Skip to content

feat: add peer.service #337

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

Merged
Merged
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
11 changes: 8 additions & 3 deletions datadog_lambda/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
dd_capture_lambda_payload_enabled = (
os.environ.get("DD_CAPTURE_LAMBDA_PAYLOAD", "false").lower() == "true"
)
service_env_var = os.environ.get("DD_SERVICE", "DefaultServiceName")
env_env_var = os.environ.get("DD_ENV", None)

DD_FLUSH_TO_LOG = "DD_FLUSH_TO_LOG"
DD_LOGS_INJECTION = "DD_LOGS_INJECTION"
Expand All @@ -70,6 +68,9 @@
DD_COLD_START_TRACE_SKIP_LIB = "DD_COLD_START_TRACE_SKIP_LIB"
DD_REQUESTS_SERVICE_NAME = "DD_REQUESTS_SERVICE_NAME"
DD_SERVICE = "DD_SERVICE"
DD_ENV = "DD_ENV"

env_env_var = os.environ.get(DD_ENV, None)

"""
Usage:
Expand Down Expand Up @@ -132,6 +133,7 @@ def __init__(self, func):
os.environ.get(DD_MERGE_XRAY_TRACES, "false").lower() == "true"
)
self.function_name = os.environ.get(AWS_LAMBDA_FUNCTION_NAME, "function")
self.service = os.environ.get(DD_SERVICE, None)
self.extractor_env = os.environ.get(DD_TRACE_EXTRACTOR, None)
self.trace_extractor = None
self.span = None
Expand Down Expand Up @@ -172,7 +174,7 @@ def __init__(self, func):
logger.debug(f"Malformatted for env {DD_COLD_START_TRACE_SKIP_LIB}")
self.response = None
if profiling_env_var:
self.prof = profiler.Profiler(env=env_env_var, service=service_env_var)
self.prof = profiler.Profiler(env=env_env_var, service=self.service)
if self.extractor_env:
extractor_parts = self.extractor_env.rsplit(".", 1)
if len(extractor_parts) == 2:
Expand Down Expand Up @@ -315,6 +317,9 @@ def _after(self, event, context):
if status_code:
self.inferred_span.set_tag("http.status_code", status_code)

if self.service:
self.inferred_span.set_tag("peer.service", self.service)
Copy link
Contributor

Choose a reason for hiding this comment

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

nice


if InferredSpanInfo.is_async(self.inferred_span) and self.span:
self.inferred_span.finish(finish_time=self.span.start)
else:
Expand Down
1 change: 1 addition & 0 deletions tests/integration/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ provider:
DD_API_KEY: ${env:DD_API_KEY}
DD_TRACE_MANAGED_SERVICES: true
DD_COLD_START_TRACING: false
DD_SERVICE: ${self:service}
timeout: 15
deploymentBucket:
name: integration-tests-serververless-deployment-bucket
Expand Down
72 changes: 45 additions & 27 deletions tests/integration/snapshots/logs/async-metrics_python310.log
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"_inferred_span.synchronicity": "sync",
"_inferred_span.tag_source": "self",
"http.status_code": "200",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -114,7 +115,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -130,15 +131,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down Expand Up @@ -228,6 +230,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"size_bytes": "26",
"_inferred_span.synchronicity": "async",
"_inferred_span.tag_source": "self",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -272,7 +275,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -288,15 +291,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down Expand Up @@ -380,6 +384,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"detail_type": "testdetail",
"_inferred_span.synchronicity": "async",
"_inferred_span.tag_source": "self",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -423,7 +428,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -439,15 +444,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down Expand Up @@ -541,6 +547,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"_inferred_span.synchronicity": "sync",
"_inferred_span.tag_source": "self",
"http.status_code": "200",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -589,7 +596,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -605,15 +612,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down Expand Up @@ -703,6 +711,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"partition_key": "XXXX",
"_inferred_span.synchronicity": "async",
"_inferred_span.tag_source": "self",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -747,7 +756,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -763,15 +772,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down Expand Up @@ -858,6 +868,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"object_etag": "XXXX",
"_inferred_span.synchronicity": "async",
"_inferred_span.tag_source": "self",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -902,7 +913,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -918,15 +929,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down Expand Up @@ -1014,6 +1026,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"subject": "TestInvoke",
"_inferred_span.synchronicity": "async",
"_inferred_span.tag_source": "self",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -1058,7 +1071,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -1074,15 +1087,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down Expand Up @@ -1169,6 +1183,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"sender_id": "AIDAIENQZJOLO23YVJ4VO",
"_inferred_span.synchronicity": "async",
"_inferred_span.tag_source": "self",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -1213,7 +1228,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -1229,15 +1244,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down Expand Up @@ -1330,6 +1346,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"_inferred_span.synchronicity": "sync",
"_inferred_span.tag_source": "self",
"http.status_code": "200",
"peer.service": "integration-tests-python",
"_dd.p.dm": "-0",
"language": "python"
},
Expand Down Expand Up @@ -1376,7 +1393,7 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand All @@ -1392,15 +1409,16 @@ HTTP GET https://www.datadoghq.com/ Headers: ["Accept-Encoding:gzip, deflate", "
"http.useragent": "python-requests/X.X.X"
},
"metrics": {
"_dd.measured": 1
"_dd.measured": 1,
"_dd.top_level": 1
},
"type": "http"
},
{
"trace_id": "XXXX",
"parent_id": "XXXX",
"span_id": "XXXX",
"service": "aws.lambda",
"service": "integration-tests-python",
"resource": "requests.request",
"name": "requests.request",
"error": 0,
Expand Down
Loading