Skip to content

Commit

Permalink
Adds ability to Trace "check" function with DD APM (#2079)
Browse files Browse the repository at this point in the history
* Initial pass at trace decorator
  • Loading branch information
nmuesch committed Nov 1, 2018
1 parent c5e4682 commit 9f17679
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ boto==2.46.1
cffi==1.11.5
cryptography==2.3
cx_oracle==6.0.1
ddtrace==0.13.0
dnspython==1.12.0
enum34==1.1.6
flup==1.0.3.dev-20110405; python_version < '3.0'
Expand Down
9 changes: 9 additions & 0 deletions datadog_checks_base/datadog_checks/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

try:
import datadog_agent
if datadog_agent.get_config('integration_tracing'):
from ddtrace import patch
patch(requests=True)
except ImportError:
# Tracing Integrations is only available with Agent 6
pass
34 changes: 34 additions & 0 deletions datadog_checks_base/datadog_checks/utils/tracing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)

from ..config import is_affirmative
from ddtrace import tracer

import wrapt

try:
import datadog_agent
except ImportError:
# Integration Tracing is only available with Agent 6
datadog_agent = None


_tracing_config = set()

def add_trace_check(check_object):
_tracing_config.add(check_object)

@wrapt.decorator
def traced(wrapped, instance, args, kwargs):
if datadog_agent is None:
return wrapped(*args, **kwargs)

trace_check = instance in _tracing_config
integration_tracing = is_affirmative(datadog_agent.get_config('integration_tracing'))

if integration_tracing and trace_check:
with tracer.trace('integration.check', service='integrations-tracing', resource=instance.name):
return wrapped(*args, **kwargs)

return wrapped(*args, **kwargs)
5 changes: 3 additions & 2 deletions datadog_checks_base/requirements.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ddtrace==0.13.0
prometheus-client==0.3.0
requests==2.19.1
protobuf==3.5.1
requests==2.19.1
simplejson==3.6.5
six==1.11.0
uptime==3.0.1
uuid==1.30
six==1.11.0
8 changes: 8 additions & 0 deletions datadog_checks_base/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ chardet==3.0.4 \
--hash=sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae \
--hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \
# via requests
ddtrace==0.12.1 \
--hash=sha256:f77a7367c43e3d58cb106519a61b3a137d774835f37f768979726a47e18ba11c
idna==2.7 \
--hash=sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e \
--hash=sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16 \
# via requests
msgpack-python==0.5.6 \
--hash=sha256:378cc8a6d3545b532dfd149da715abae4fda2a3adb6d74e525d0d5e51f46909b \
# via ddtrace
prometheus-client==0.3.0 \
--hash=sha256:69494dc1ac967c0f626c8193e439755c2b95dd4ed22ef31c277601778a50c7ff
protobuf==3.5.1 \
Expand All @@ -42,3 +47,6 @@ urllib3==1.23 \
# via requests
uuid==1.30 \
--hash=sha256:1f87cc004ac5120466f36c5beae48b4c48cc411968eed0eaecd3da82aa96193f
wrapt==1.10.11 \
--hash=sha256:d4d560d479f2c21e1b5443bbd15fe7ec4b37fe7e53d335d3b9b0a7b1226fe3c6 \
# via ddtrace
1 change: 0 additions & 1 deletion datadog_checks_tests_helper/requirements.in
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

2 changes: 1 addition & 1 deletion openstack/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ platform = linux|darwin|win32

[testenv:openstack]
deps =
../datadog_checks_base
-e../datadog_checks_base
-r../datadog_checks_base/requirements.in
-rrequirements-dev.txt
commands =
Expand Down

0 comments on commit 9f17679

Please sign in to comment.