Skip to content

Commit

Permalink
update integration tracing naming scheme
Browse files Browse the repository at this point in the history
Follow-up to #13576, update the integrations tracing naming scheme to ensure all integrations appear under a single service, matching the name of the service used for profiling. This enables bettter linking between APM & profiling data.

Since all integrations are now reporting under a single service, we now include the integration name in the resource names to be able to differentiate between the integrations.
  • Loading branch information
djova committed Dec 27, 2022
1 parent ea51537 commit 31cb130
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
10 changes: 7 additions & 3 deletions datadog_checks_base/datadog_checks/base/utils/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@

def _traced_dbm_async_job_method(f):
# traces DBMAsyncJob.run_job only if tracing is enabled
if os.getenv('DDEV_TRACE_ENABLED', 'false') == 'true':
if os.getenv('DDEV_TRACE_ENABLED', 'false') == 'true' or is_affirmative(datadog_agent.get_config('integration_tracing')):
try:
from ddtrace import tracer

@functools.wraps(f)
def wrapper(self, *args, **kwargs):
with tracer.trace(
# match the same primary operation name that comes from the regular integration tracing
"run",
service="{}-integration".format(self._check.name),
resource="{}.run_job".format(type(self).__name__),
service="datadog-agent-integrations",
resource="{}.{}.run_job".format(
self._check.name,
type(self).__name__
),
):
self.run_job()

Expand Down
44 changes: 22 additions & 22 deletions datadog_checks_base/datadog_checks/base/utils/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

EXCLUDED_MODULES = ['threading']

INTEGRATION_TRACING_SERVICE_NAME = "datadog-agent-integrations"


def traced(fn):
"""
Expand Down Expand Up @@ -57,39 +59,37 @@ def traced_wrapper(self, *args, **kwargs):
return traced_wrapper


def _get_integration_tracing_resource_name(function_name, self, *args, **kwargs):
integration_name = None
if self and hasattr(self, "name"):
integration_name = self.name
elif function_name == "__init__":
# copy the logic that the AgentCheck init method uses to determine the check name
integration_name = kwargs.get('name', '')
if len(args) > 0:
integration_name = args[0]

if not integration_name:
integration_name = "UNKNOWN_INTEGRATION"

return integration_name + "." + function_name


def tracing_method(f, tracer):
if (PY2 and 'self' in inspect.getargspec(f).args) or (PY3 and inspect.signature(f).parameters.get('self')):

@functools.wraps(f)
def wrapper(self, *args, **kwargs):
service_name = None
if hasattr(self, "name"):
service_name = "{}-integration".format(self.name)
elif f.__name__ == "__init__":
# copy the logic that the AgentCheck init method uses to determine the check name
name = kwargs.get('name', '')
if len(args) > 0:
name = args[0]
if name:
service_name = "{}-integration".format(name)

with tracer.trace(f.__name__, resource=f.__name__, service=service_name):
resource = _get_integration_tracing_resource_name(f.__name__, self, *args, **kwargs)
with tracer.trace(f.__name__, resource=resource, service=INTEGRATION_TRACING_SERVICE_NAME):
return f(self, *args, **kwargs)

else:

@functools.wraps(f)
def wrapper(*args, **kwargs):
service_name = None
if f.__name__ == "__init__":
# copy the logic that the AgentCheck init method uses to determine the check name
name = kwargs.get('name', '')
if len(args) > 0:
name = args[0]
if name:
service_name = "{}-integration".format(name)

with tracer.trace(f.__name__, resource=f.__name__, service=service_name):
resource = _get_integration_tracing_resource_name(f.__name__, None, *args, **kwargs)
with tracer.trace(f.__name__, resource=resource, service=INTEGRATION_TRACING_SERVICE_NAME):
return f(*args, **kwargs)

return wrapper
Expand Down

0 comments on commit 31cb130

Please sign in to comment.