Skip to content

fix: call patch_all before importing handler code. #598

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
6 changes: 4 additions & 2 deletions datadog_lambda/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
extract_http_status_code_tag,
)

# Patch third-party libraries for tracing, must be done before importing any
# handler code.
patch_all()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are planning to deprecate ddtrace.patch_all(...) and instead encourage folks to use import ddtrace.auto (which executes a similar set of operations as ddtrace-run).

I don't think we can make this change in this PR due to the overhead of loading all ddtrace products and entrypoints but it's something we should investigate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Munir. It's definitely something on our radar. Last I benchmarked the difference between patch_all and ddtrace.auto, it was significant.


profiling_env_var = os.environ.get("DD_PROFILING_ENABLED", "false").lower() == "true"
if profiling_env_var:
from ddtrace.profiling import profiler
Expand Down Expand Up @@ -223,8 +227,6 @@ def __init__(self, func):
os.environ[DD_REQUESTS_SERVICE_NAME] = os.environ.get(
DD_SERVICE, "aws.lambda"
)
# Patch third-party libraries for tracing
patch_all()

# Enable LLM Observability
if llmobs_env_var:
Expand Down
Loading