@@ -49,6 +49,7 @@ var DefaultTraceExtractor = getHeadersFromEventHeaders
49
49
// the root TraceContext and then adds that TraceContext to the context object.
50
50
func contextWithRootTraceContext (ctx context.Context , ev json.RawMessage , mergeXrayTraces bool , extractor ContextExtractor ) (context.Context , error ) {
51
51
datadogTraceContext , gotDatadogTraceContext := getTraceContext (ctx , extractor (ctx , ev ))
52
+ fmt .Printf ("[DEBUG LAMBDA] Got trace context: %+v, ok=%v\n " , datadogTraceContext , gotDatadogTraceContext )
52
53
53
54
xrayTraceContext , errGettingXrayContext := convertXrayTraceContextFromLambdaContext (ctx )
54
55
if errGettingXrayContext != nil {
@@ -135,6 +136,7 @@ func getTraceContext(ctx context.Context, headers map[string]string) (TraceConte
135
136
if traceID == "" {
136
137
if val , ok := ctx .Value (extension .DdTraceId ).(string ); ok {
137
138
traceID = val
139
+ fmt .Printf ("[DEBUG LAMBDA] Got traceID from context: %s\n " , val )
138
140
}
139
141
}
140
142
if traceID == "" {
@@ -145,12 +147,19 @@ func getTraceContext(ctx context.Context, headers map[string]string) (TraceConte
145
147
if parentID == "" {
146
148
if val , ok := ctx .Value (extension .DdParentId ).(string ); ok {
147
149
parentID = val
150
+ fmt .Printf ("[DEBUG LAMBDA] Got parentID from context: %s\n " , val )
148
151
}
149
152
}
153
+ if parentID == "" {
154
+ return tc , false
155
+ }
156
+
150
157
samplingPriority := headers [samplingPriorityHeader ]
158
+ fmt .Printf ("[DEBUG LAMBDA] Initial sampling priority from headers: %s\n " , samplingPriority )
151
159
if samplingPriority == "" {
152
160
if val , ok := ctx .Value (extension .DdSamplingPriority ).(string ); ok {
153
161
samplingPriority = val
162
+ fmt .Printf ("[DEBUG LAMBDA] Got sampling priority from context: %s\n " , val )
154
163
}
155
164
}
156
165
// Remove this default to let tracer sampling rules take effect
@@ -161,6 +170,9 @@ func getTraceContext(ctx context.Context, headers map[string]string) (TraceConte
161
170
// Only set sampling priority if it was explicitly provided
162
171
if samplingPriority != "" {
163
172
tc [samplingPriorityHeader ] = samplingPriority
173
+ fmt .Printf ("[DEBUG LAMBDA] Setting sampling priority in trace context: %s\n " , samplingPriority )
174
+ } else {
175
+ fmt .Printf ("[DEBUG LAMBDA] No sampling priority set in trace context\n " )
164
176
}
165
177
tc [traceIDHeader ] = traceID
166
178
tc [parentIDHeader ] = parentID
@@ -269,6 +281,7 @@ func convertXRayEntityIDToDatadogParentID(entityID string) (string, error) {
269
281
270
282
// Converts an X-Ray sampling decision into its Datadog counterpart.
271
283
func convertXRaySamplingDecision (decision header.SamplingDecision ) string {
284
+ fmt .Printf ("[DEBUG LAMBDA] Converting X-Ray sampling decision: %v\n " , decision )
272
285
if decision == header .Sampled {
273
286
return userKeep
274
287
}
0 commit comments