-
Notifications
You must be signed in to change notification settings - Fork 544
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
feat(aws-sdk): SQS receive: use span links instead of processing spans #2345
base: main
Are you sure you want to change the base?
Changes from all commits
3447c0e
c9bf62a
0021486
6dfe182
b339cc3
f4d95b0
9581ae6
10ee8c1
940b6cf
0a24be7
e9eeabd
b77188d
4822b0b
5fb4345
25ea56d
35adc39
c68d15e
a9c8df6
6d30fa6
ca771f5
b562d80
a5be283
f237133
62bf036
953b3c5
680f7d2
6b7cb26
0db74dd
454fbf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,9 @@ import { | |
Span, | ||
propagation, | ||
trace, | ||
context, | ||
ROOT_CONTEXT, | ||
Attributes, | ||
} from '@opentelemetry/api'; | ||
import { pubsubPropagation } from '@opentelemetry/propagation-utils'; | ||
import { RequestMetadata, ServiceExtension } from './ServiceExtension'; | ||
import type { SQS } from 'aws-sdk'; | ||
import { | ||
|
@@ -33,7 +31,6 @@ import { | |
} from '../types'; | ||
import { | ||
MESSAGINGDESTINATIONKINDVALUES_QUEUE, | ||
MESSAGINGOPERATIONVALUES_PROCESS, | ||
MESSAGINGOPERATIONVALUES_RECEIVE, | ||
SEMATTRS_MESSAGING_DESTINATION, | ||
SEMATTRS_MESSAGING_DESTINATION_KIND, | ||
|
@@ -134,7 +131,7 @@ export class SqsServiceExtension implements ServiceExtension { | |
responseHook = ( | ||
response: NormalizedResponse, | ||
span: Span, | ||
tracer: Tracer, | ||
_tracer: Tracer, | ||
config: AwsSdkInstrumentationConfig | ||
) => { | ||
switch (response.request.commandName) { | ||
|
@@ -150,45 +147,30 @@ export class SqsServiceExtension implements ServiceExtension { | |
break; | ||
|
||
case 'ReceiveMessage': { | ||
const messages: SQS.Message[] = response?.data?.Messages; | ||
if (messages) { | ||
const queueUrl = this.extractQueueUrl(response.request.commandInput); | ||
const queueName = this.extractQueueNameFromUrl(queueUrl); | ||
|
||
pubsubPropagation.patchMessagesArrayToStartProcessSpans<SQS.Message>({ | ||
messages, | ||
parentContext: trace.setSpan(context.active(), span), | ||
tracer, | ||
messageToSpanDetails: (message: SQS.Message) => ({ | ||
name: queueName ?? 'unknown', | ||
parentContext: propagation.extract( | ||
ROOT_CONTEXT, | ||
extractPropagationContext( | ||
message, | ||
config.sqsExtractContextPropagationFromPayload | ||
), | ||
contextGetter | ||
), | ||
const messages: SQS.Message[] = response?.data?.Messages || []; | ||
|
||
span.setAttribute('messaging.batch.message_count', messages.length); | ||
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. You can now can use 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. I have seen some discussion that argues to stay with hardcoded attributes until they are stable, so maybe we can keep this as-is. |
||
|
||
for (const message of messages) { | ||
const propagatedContext = propagation.extract( | ||
ROOT_CONTEXT, | ||
extractPropagationContext( | ||
message, | ||
config.sqsExtractContextPropagationFromPayload | ||
), | ||
contextGetter | ||
); | ||
|
||
const spanContext = trace.getSpanContext(propagatedContext); | ||
|
||
if (spanContext) { | ||
span.addLink({ | ||
context: spanContext, | ||
attributes: { | ||
[SEMATTRS_MESSAGING_SYSTEM]: 'aws.sqs', | ||
[SEMATTRS_MESSAGING_DESTINATION]: queueName, | ||
[SEMATTRS_MESSAGING_DESTINATION_KIND]: | ||
MESSAGINGDESTINATIONKINDVALUES_QUEUE, | ||
[SEMATTRS_MESSAGING_MESSAGE_ID]: message.MessageId, | ||
[SEMATTRS_MESSAGING_URL]: queueUrl, | ||
[SEMATTRS_MESSAGING_OPERATION]: | ||
MESSAGINGOPERATIONVALUES_PROCESS, | ||
}, | ||
}), | ||
processHook: (span: Span, message: SQS.Message) => | ||
config.sqsProcessHook?.(span, { message }), | ||
}); | ||
|
||
pubsubPropagation.patchArrayForProcessSpans( | ||
messages, | ||
tracer, | ||
context.active() | ||
); | ||
}); | ||
} | ||
} | ||
break; | ||
} | ||
|
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.
Can you update this doc with your changes and to remove mention of
processing spans
https://github.com/open-telemetry/opentelemetry-js-contrib/blob/instrumentation-aw[…]0/plugins/node/opentelemetry-instrumentation-aws-sdk/doc/sqs.md