-
Notifications
You must be signed in to change notification settings - Fork 619
feat(aws-sdk)!: SQS receive: use span links instead of processing spans #2345
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
Merged
Merged
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
3447c0e
sqs: use links instead of process spans
seemk c9bf62a
add tests
seemk 0021486
update readme
seemk 6dfe182
Merge branch 'main' into sqs-batch-receive
seemk b339cc3
Merge branch 'main' into sqs-batch-receive
seemk f4d95b0
Merge branch 'main' into sqs-batch-receive
seemk 9581ae6
Merge branch 'main' into sqs-batch-receive
seemk 10ee8c1
Merge branch 'main' into sqs-batch-receive
seemk 940b6cf
Merge branch 'main' into sqs-batch-receive
seemk 0a24be7
Merge branch 'main' into sqs-batch-receive
seemk e9eeabd
Merge branch 'main' into sqs-batch-receive
seemk b77188d
Merge branch 'main' into sqs-batch-receive
seemk 4822b0b
Merge branch 'main' into sqs-batch-receive
seemk 5fb4345
Merge branch 'main' into sqs-batch-receive
seemk 25ea56d
Merge branch 'main' into sqs-batch-receive
seemk 35adc39
Merge branch 'main' into sqs-batch-receive
seemk c68d15e
Merge branch 'main' into sqs-batch-receive
seemk a9c8df6
Merge branch 'main' into sqs-batch-receive
seemk 6d30fa6
Merge branch 'main' into sqs-batch-receive
seemk ca771f5
Merge branch 'main' into sqs-batch-receive
seemk b562d80
Merge branch 'main' into sqs-batch-receive
seemk a5be283
Merge branch 'main' into sqs-batch-receive
seemk f237133
Merge branch 'main' into sqs-batch-receive
seemk 62bf036
Merge branch 'main' into sqs-batch-receive
seemk 953b3c5
Merge branch 'main' into sqs-batch-receive
seemk 680f7d2
Merge branch 'main' into sqs-batch-receive
seemk 6b7cb26
Merge branch 'main' into sqs-batch-receive
seemk 0db74dd
Merge branch 'main' into sqs-batch-receive
seemk 454fbf2
Merge branch 'main' into sqs-batch-receive
seemk f1cfbee
Merge branch 'main' into sqs-batch-receive
seemk fc5ba3c
Merge branch 'main' into sqs-batch-receive
seemk 8028d85
update semconv values
seemk 4ce0bfb
add tests for v3
seemk fd7a219
update sqs docs
seemk c9bcc5a
Merge branch 'main' into sqs-batch-receive
seemk c70fb0e
remove unused dependency
seemk cefd08a
Merge branch 'main' into sqs-batch-receive
seemk 33df93b
Merge branch 'main' into sqs-batch-receive
seemk 19e5cdd
remove obsolete test file and exports
seemk 65d17d4
Merge branch 'main' into sqs-batch-receive
seemk ba514c4
mark semconv values as const
seemk ce50e2a
Merge branch 'main' into sqs-batch-receive
seemk 94561e4
remove unused dep
seemk 2ae3ff2
ci
seemk 4308ee1
Merge branch 'main' into sqs-batch-receive
trentm 5d50710
regenerate src/semconv.ts with scripts/gen-semconv-ts.js tool
trentm d18c87e
fix missed conflict in earlier merge
trentm 943ef18
Merge branch 'main' into sqs-batch-receive
trentm 05104ff
regenerate src/semconv.ts again (re-ordering and comments)
trentm 8c2c582
Merge branch 'main' into sqs-batch-receive
pichlermarc 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,68 +1,19 @@ | ||
| # SQS | ||
|
|
||
| SQS is amazon's managed message queue. Thus, it should follow the [OpenTelemetry specification for Messaging systems](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md). | ||
| SQS is Amazon's managed message queue. Thus, it should follow the [OpenTelemetry specification for Messaging systems](https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/). | ||
|
|
||
| ## Specific trace semantic | ||
|
|
||
| The following methods are automatically enhanced: | ||
|
|
||
| ### sendMessage / sendMessageBatch | ||
|
|
||
| - [Messaging Attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#messaging-attributes) are added by this instrumentation according to the spec. | ||
| - [Messaging Attributes](https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#messaging-attributes) are added by this instrumentation according to the spec. | ||
| - OpenTelemetry trace context is injected as SQS MessageAttributes, so the service receiving the message can link cascading spans to the trace which created the message. | ||
|
|
||
| ### receiveMessage | ||
|
|
||
| - [Messaging Attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#messaging-attributes) are added by this instrumentation according to the spec. | ||
| - Additional "processing spans" are created for each message received by the application. | ||
| If an application invoked `receiveMessage`, and received a 10 messages batch, a single `messaging.operation` = `receive` span will be created for the `receiveMessage` operation, and 10 `messaging.operation` = `process` spans will be created, one for each message. | ||
| Those processing spans are created by the library. This behavior is partially implemented, [See discussion below](#processing-spans). | ||
| - Sets the inter process context correctly, so that additional spans created through the process will be linked to parent spans correctly. | ||
| This behavior is partially implemented, [See discussion below](#processing-spans). | ||
| - [Messaging Attributes](https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#messaging-attributes) are added by this instrumentation according to the spec. | ||
| - Sets the inter process context correctly, so that additional spans created through the process will be linked to parent spans correctly. | ||
| When multiple messages are received, the instrumentation will attach spank links to the receiving span containing the trace context and message ID of each message. | ||
| - Extract trace context from SQS MessageAttributes, and set span's `parent` and `links` correctly according to the spec. | ||
|
|
||
| #### Processing Spans | ||
|
|
||
| See GH issue [here](https://github.com/open-telemetry/opentelemetry-js-contrib/issues/707) | ||
|
|
||
| According to OpenTelemetry specification (and to reasonable expectation for trace structure), user of this library would expect to see one span for the operation of receiving messages batch from SQS, and then, **for each message**, a span with it's own sub-tree for the processing of this specific message. | ||
|
|
||
| For example, if a `receiveMessages` returned 2 messages: | ||
|
|
||
| - `msg1` resulting in storing something to a DB. | ||
| - `msg2` resulting in calling an external HTTP endpoint. | ||
|
|
||
| This will result in a creating a DB span that would be the child of `msg1` process span, and an HTTP span that would be the child of `msg2` process span (in opposed to mixing all those operations under the single `receive` span, or start a new trace for each of them). | ||
|
|
||
| Unfortunately, this is not so easy to implement in JS: | ||
|
|
||
| 1. The SDK is calling a single callback for the messages batch, and it's not straightforward to understand when each individual message processing starts and ends (and set the context correctly for cascading spans). | ||
| 2. If async/await is used, context can be lost when returning data from async functions, for example: | ||
|
|
||
| ```js | ||
| async function asyncRecv() { | ||
| const data = await sqs.receiveMessage(recvParams).promise(); | ||
| // context of receiveMessage is set here | ||
| return data; | ||
| } | ||
|
|
||
| async function poll() { | ||
| const result = await asyncRecv(); | ||
| // context is lost when asyncRecv returns. following spans are created with root context. | ||
| await Promise.all( | ||
| result.Messages.map((message) => this.processMessage(message)) | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| Current implementation partially solves this issue by patching the `map` \ `forEach` \ `Filter` functions on the `Messages` array of `receiveMessage` result. This handles issues like the one above, but will not handle situations where the processing is done in other patterns (multiple map\forEach calls, index access to the array, other array operations, etc). This is currently an open issue in the instrumentation. | ||
|
|
||
| User can add custom attributes to the `process` span, by setting a function to `sqsProcessHook` in instrumentation config. For example: | ||
|
|
||
| ```js | ||
| awsInstrumentationConfig = { | ||
| sqsProcessHook: (span, message) => { | ||
| span.setAttribute("sqs.receipt_handle", message.params?.ReceiptHandle); | ||
| }, | ||
| }; | ||
| ``` |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
nit: There are enum value exports from the unstable semantic-conventions exports that could be used for 'receive' here (and
aws_sqsabove):However, this is very minor and could be done in a follow-up PR.