Skip to content

Commit 0f9bbd4

Browse files
jchrostek-ddclaude
andcommitted
Fix duplicate aws.lambda spans when extension is present
When the extension is present, use the placeholder resource name "dd-tracer-serverless-span" for the Python tracer's aws.lambda span. This allows the extension to: 1. Recognize the span as a tracer placeholder 2. Merge the span's metadata into the extension's invocation span 3. Filter out the placeholder span (not sent to backend) This prevents duplicate aws.lambda spans being sent - only the extension's span (with merged Python metadata) will be sent. Without the extension, the span uses the function name as before. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6ab7bcf commit 0f9bbd4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

datadog_lambda/tracing.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from ddtrace.trace import Context, Span, tracer
3636

3737
from datadog_lambda.config import config
38+
from datadog_lambda.extension import should_use_extension
3839
from datadog_lambda import __version__ as datadog_lambda_version
3940
from datadog_lambda.trigger import (
4041
_EventSource,
@@ -1493,10 +1494,18 @@ def create_function_execution_span(
14931494
else:
14941495
service_name = function_name if function_name else "aws.lambda"
14951496

1497+
# When the extension is present, use a placeholder resource name so the
1498+
# extension recognizes this span and merges its metadata into the extension's
1499+
# invocation span. The extension will set the correct resource (function name)
1500+
# on its span, and this placeholder span will be filtered out.
1501+
# Without the extension, use the function name directly.
1502+
span_resource = (
1503+
"dd-tracer-serverless-span" if should_use_extension else function_name
1504+
)
14961505
span = tracer.trace(
14971506
"aws.lambda",
14981507
service=service_name,
1499-
resource=function_name,
1508+
resource=span_resource,
15001509
span_type="serverless",
15011510
)
15021511
if span:

0 commit comments

Comments
 (0)