Skip to content
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

[Serverless] Reset both inferred spans on each invocation. #30881

Merged
merged 1 commit into from
Nov 8, 2024
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
1 change: 1 addition & 0 deletions pkg/serverless/invocationlifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ func (lp *LifecycleProcessor) newRequest(lambdaPayloadString []byte, startTime t
SpanID: inferredspan.GenerateSpanId(),
},
}
lp.requestHandler.inferredSpans[1] = nil
lp.requestHandler.triggerTags = make(map[string]string)
lp.requestHandler.triggerMetrics = make(map[string]float64)
}
Expand Down
52 changes: 52 additions & 0 deletions pkg/serverless/invocationlifecycle/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,58 @@ func TestTriggerTypesLifecycleEventForSNSSQSNoDdContext(t *testing.T) {
assert.Equal(t, snsSpan.SpanID, sqsSpan.ParentID)
}

func TestTriggerTypesLifecycleEventForSNSSQSThenApiGateway(t *testing.T) {
// SNS-SQS creates two inferred spans. Ensure that then invoking the
// function with an event that should have just one inferred span (API
// Gateway) creates just one inferred span.
var tracePayload *api.Payload
testProcessor := &LifecycleProcessor{
DetectLambdaLibrary: func() bool { return false },
ProcessTrace: func(payload *api.Payload) { tracePayload = payload },
InferredSpansEnabled: true,
}

// SNS-SQS invocation
startInvocationTime := time.Now()
endInvocationTime := startInvocationTime.Add(time.Second)

startDetails := &InvocationStartDetails{
InvokeEventRawPayload: getEventFromFile("snssqs.json"),
InvokedFunctionARN: "arn:aws:lambda:us-east-1:123456789012:function:my-function",
StartTime: startInvocationTime,
}
endDetails := &InvocationEndDetails{
RequestID: "test-request-id",
EndTime: endInvocationTime,
}

testProcessor.OnInvokeStart(startDetails)
testProcessor.OnInvokeEnd(endDetails)

spans := tracePayload.TracerPayload.Chunks[0].Spans
assert.Equal(t, 3, len(spans))

// API Gateway invocation
startInvocationTime = endInvocationTime
endInvocationTime = startInvocationTime.Add(time.Second)

startDetails = &InvocationStartDetails{
InvokeEventRawPayload: getEventFromFile("api-gateway.json"),
InvokedFunctionARN: "arn:aws:lambda:us-east-1:123456789012:function:my-function",
StartTime: startInvocationTime,
}
endDetails = &InvocationEndDetails{
RequestID: "test-request-id",
EndTime: endInvocationTime,
}

testProcessor.OnInvokeStart(startDetails)
testProcessor.OnInvokeEnd(endDetails)

spans = tracePayload.TracerPayload.Chunks[0].Spans
assert.Equal(t, 2, len(spans))
}

func TestTriggerTypesLifecycleEventForSQSNoDdContext(t *testing.T) {

startInvocationTime := time.Now()
Expand Down
Loading