Skip to content

Commit b0be0c8

Browse files
committed
test changes
1 parent f46397b commit b0be0c8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

internal/trace/context.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var DefaultTraceExtractor = getHeadersFromEventHeaders
4949
// the root TraceContext and then adds that TraceContext to the context object.
5050
func contextWithRootTraceContext(ctx context.Context, ev json.RawMessage, mergeXrayTraces bool, extractor ContextExtractor) (context.Context, error) {
5151
datadogTraceContext, gotDatadogTraceContext := getTraceContext(ctx, extractor(ctx, ev))
52+
fmt.Printf("[DEBUG LAMBDA] Got trace context: %+v, ok=%v\n", datadogTraceContext, gotDatadogTraceContext)
5253

5354
xrayTraceContext, errGettingXrayContext := convertXrayTraceContextFromLambdaContext(ctx)
5455
if errGettingXrayContext != nil {
@@ -135,6 +136,7 @@ func getTraceContext(ctx context.Context, headers map[string]string) (TraceConte
135136
if traceID == "" {
136137
if val, ok := ctx.Value(extension.DdTraceId).(string); ok {
137138
traceID = val
139+
fmt.Printf("[DEBUG LAMBDA] Got traceID from context: %s\n", val)
138140
}
139141
}
140142
if traceID == "" {
@@ -145,12 +147,19 @@ func getTraceContext(ctx context.Context, headers map[string]string) (TraceConte
145147
if parentID == "" {
146148
if val, ok := ctx.Value(extension.DdParentId).(string); ok {
147149
parentID = val
150+
fmt.Printf("[DEBUG LAMBDA] Got parentID from context: %s\n", val)
148151
}
149152
}
153+
if parentID == "" {
154+
return tc, false
155+
}
156+
150157
samplingPriority := headers[samplingPriorityHeader]
158+
fmt.Printf("[DEBUG LAMBDA] Initial sampling priority from headers: %s\n", samplingPriority)
151159
if samplingPriority == "" {
152160
if val, ok := ctx.Value(extension.DdSamplingPriority).(string); ok {
153161
samplingPriority = val
162+
fmt.Printf("[DEBUG LAMBDA] Got sampling priority from context: %s\n", val)
154163
}
155164
}
156165
// Remove this default to let tracer sampling rules take effect
@@ -161,6 +170,9 @@ func getTraceContext(ctx context.Context, headers map[string]string) (TraceConte
161170
// Only set sampling priority if it was explicitly provided
162171
if samplingPriority != "" {
163172
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")
164176
}
165177
tc[traceIDHeader] = traceID
166178
tc[parentIDHeader] = parentID
@@ -269,6 +281,7 @@ func convertXRayEntityIDToDatadogParentID(entityID string) (string, error) {
269281

270282
// Converts an X-Ray sampling decision into its Datadog counterpart.
271283
func convertXRaySamplingDecision(decision header.SamplingDecision) string {
284+
fmt.Printf("[DEBUG LAMBDA] Converting X-Ray sampling decision: %v\n", decision)
272285
if decision == header.Sampled {
273286
return userKeep
274287
}

0 commit comments

Comments
 (0)