-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: OB-35469 add subscription request parent span as child of disco… #334
Merged
+54
−5
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,6 @@ func New(ctx context.Context, cfg *Config) (*Lambda, error) { | |
return nil, fmt.Errorf("failed to register functions: %w", err) | ||
} | ||
|
||
l.Entrypoint = tracing.NewLambdaHandler(mux, tracerProvider) | ||
l.Entrypoint = tracing.WrapHandlerSQSContext(tracing.NewLambdaHandler(mux, tracerProvider)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new wrapper that only applies in the subscriber case since in forwarder we're not injecting the context into the sqs messages/trying to read it back out. |
||
return l, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tracing | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/go-logr/logr" | ||
) | ||
|
||
type SQSWithContextHandler struct { | ||
handler lambda.Handler | ||
} | ||
|
||
// Compile time check our Handler implements lambda.Handler. | ||
var _ lambda.Handler = SQSWithContextHandler{} | ||
|
||
// Invoke checks if the incoming payload is from a SQS event and, if so, | ||
// extracts the context from the SQS message and injects it into the context. | ||
// This means that the spans created with this context will appear as children | ||
// of a span in the discover request that created the SQS event | ||
func (h SQSWithContextHandler) Invoke(ctx context.Context, payload []byte) ([]byte, error) { | ||
logger := logr.FromContextOrDiscard(ctx) | ||
logger.V(3).Info("Getting context from message attributes") | ||
var event events.SQSEvent | ||
dec := json.NewDecoder(bytes.NewReader(payload)) | ||
dec.DisallowUnknownFields() | ||
if err := dec.Decode(&event); err == nil { | ||
for _, record := range event.Records { | ||
ctx = NewSQSCarrier().Extract(ctx, record.MessageAttributes) | ||
break | ||
} | ||
} | ||
|
||
response, err := h.handler.Invoke(ctx, payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return response, nil | ||
} | ||
|
||
// WrapHandlerSQSContext Provides a Handler which wraps an existing Handler while | ||
// injecting the SQS context into the context if the payload is a SQS event. | ||
func WrapHandlerSQSContext(handler lambda.Handler) lambda.Handler { | ||
return SQSWithContextHandler{handler: handler} | ||
} |
2 changes: 1 addition & 1 deletion
2
pkg/handler/subscriber/sqspropagator.go → pkg/tracing/sqspropagator.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package subscriber | ||
package tracing | ||
|
||
import ( | ||
"context" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is suspicious. If you remove this, what functionality is
InstrumentedHandler
providing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point. This effectively just becomes a wrapper around
HandleRequest
that does nothing. There might be some more refactoring that is possible if I do remove this. The idea with this modification is to change the place where the context is being inserted from. I removed adding the context in here because I am adding it in in a different place, as a wrapper to the invocation. This allows the parent span of the subscription request to get the context from the SQS event (the context of the previous request). I'll add more description in the commit message.