Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tracing_method using self argument #11042

Merged
merged 3 commits into from
Jan 7, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions datadog_checks_base/datadog_checks/base/utils/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
import functools
import inspect
import os

from ..config import is_affirmative
Expand Down Expand Up @@ -55,21 +56,38 @@ def traced_wrapper(self, *args, **kwargs):


def tracing_method(f, tracer):
@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):
return f(self, *args, **kwargs)
signature = inspect.signature(f)
if signature.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):
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):
return f(*args, **kwargs)

return wrapper

Expand Down