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 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions datadog_lambda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@


initialize_logging(__name__)


from datadog_lambda.patch import patch_all # noqa: E402

# Patch third-party libraries for tracing, must be done before importing any
# handler code.
patch_all()
3 changes: 0 additions & 3 deletions datadog_lambda/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Headers,
)
from datadog_lambda.module_name import modify_module_name
from datadog_lambda.patch import patch_all
from datadog_lambda.span_pointers import calculate_span_pointers
from datadog_lambda.tag_object import tag_object
from datadog_lambda.tracing import (
Expand Down Expand Up @@ -142,8 +141,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 config.llmobs_enabled:
Expand Down
90 changes: 54 additions & 36 deletions tests/integration/snapshots/logs/async-metrics_python310.log
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Integration test changes are all related to the fact that we're now properly patching the requests package before importing it, which wasn't happening previously.

"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -133,7 +133,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -145,7 +146,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -160,7 +161,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down Expand Up @@ -326,7 +328,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -340,7 +342,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -352,7 +355,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -367,7 +370,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down Expand Up @@ -485,7 +489,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -499,7 +503,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -511,7 +516,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -526,7 +531,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down Expand Up @@ -660,7 +666,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -674,7 +680,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -686,7 +693,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -701,7 +708,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down Expand Up @@ -826,7 +834,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -840,7 +848,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -852,7 +861,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -867,7 +876,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down Expand Up @@ -1001,7 +1011,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -1015,7 +1025,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -1027,7 +1038,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -1042,7 +1053,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down Expand Up @@ -1165,7 +1177,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -1179,7 +1191,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -1191,7 +1204,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -1206,7 +1219,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down Expand Up @@ -1328,7 +1342,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -1342,7 +1356,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -1354,7 +1369,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -1369,7 +1384,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down Expand Up @@ -1499,7 +1515,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -1513,7 +1529,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://datadoghq.com/",
"out.host": "datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1,
Expand All @@ -1525,7 +1542,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "integration-tests-python",
"service": "requests",
"resource": "GET /",
"name": "requests.request",
"error": 0,
Expand All @@ -1540,7 +1557,8 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate","A
"http.url": "https://www.datadoghq.com/",
"out.host": "www.datadoghq.com",
"http.status_code": "200",
"http.useragent": "python-requests/X.X.X"
"http.useragent": "python-requests/X.X.X",
"_dd.base_service": "integration-tests-python"
},
"metrics": {
"_dd.measured": 1
Expand Down
Loading
Loading