1717from datadog_lambda .tracing import (
1818 extract_dd_trace_context ,
1919 inject_correlation_ids ,
20- get_dd_trace_context ,
2120 dd_tracing_enabled ,
2221 set_correlation_ids ,
22+ create_function_execution_span ,
2323)
24- from datadog_lambda .constants import TraceContextSource
25- from ddtrace import tracer
26- from ddtrace .propagation .http import HTTPPropagator
27-
2824
2925logger = logging .getLogger (__name__ )
3026
@@ -91,7 +87,6 @@ def __init__(self, func):
9187 )
9288 self .handler_name = os .environ .get ("_HANDLER" , "handler" )
9389 self .function_name = os .environ .get ("AWS_LAMBDA_FUNCTION_NAME" , "function" )
94- self .propagator = HTTPPropagator ()
9590
9691 # Inject trace correlation ids to logs
9792 if self .logs_injection :
@@ -126,7 +121,15 @@ def _before(self, event, context):
126121
127122 self .span = None
128123 if dd_tracing_enabled :
129- self .span = self ._create_dd_trace_py_span (context , dd_context )
124+
125+ self .span = create_function_execution_span (
126+ context ,
127+ self .function_name ,
128+ self .handler_name ,
129+ is_cold_start (),
130+ dd_context ,
131+ self .merge_xray_traces ,
132+ )
130133 else :
131134 set_correlation_ids ()
132135
@@ -144,33 +147,5 @@ def _after(self, event, context):
144147 except Exception :
145148 traceback .print_exc ()
146149
147- def _create_dd_trace_py_span (self , context , trace_context ):
148- span_context = None
149- if (
150- trace_context ["source" ] == TraceContextSource .EVENT
151- or self .merge_xray_traces
152- ):
153- headers = get_dd_trace_context ()
154- span_context = self .propagator .extract (headers )
155-
156- tags = {}
157- if context :
158- tags = {
159- "cold_start" : is_cold_start (),
160- "function_arn" : context .invoked_function_arn ,
161- "request_id" : context .aws_request_id ,
162- "resource_names" : context .function_name ,
163- }
164- args = {
165- "service" : self .function_name ,
166- "resource" : self .handler_name ,
167- "span_type" : "serverless" ,
168- "child_of" : span_context ,
169- }
170- span = tracer .start_span ("aws.lambda" , ** args )
171- if span :
172- span .set_tags (tags )
173- return span
174-
175150
176151datadog_lambda_wrapper = _LambdaDecorator
0 commit comments