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

feat(aws-sdk): SQS receive: use span links instead of processing spans #2345

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3447c0e
sqs: use links instead of process spans
seemk Jul 17, 2024
c9bf62a
add tests
seemk Jul 18, 2024
0021486
update readme
seemk Jul 18, 2024
6dfe182
Merge branch 'main' into sqs-batch-receive
seemk Jul 23, 2024
b339cc3
Merge branch 'main' into sqs-batch-receive
seemk Jul 23, 2024
f4d95b0
Merge branch 'main' into sqs-batch-receive
seemk Jul 31, 2024
9581ae6
Merge branch 'main' into sqs-batch-receive
seemk Aug 7, 2024
10ee8c1
Merge branch 'main' into sqs-batch-receive
seemk Aug 14, 2024
940b6cf
Merge branch 'main' into sqs-batch-receive
seemk Aug 20, 2024
0a24be7
Merge branch 'main' into sqs-batch-receive
seemk Aug 22, 2024
e9eeabd
Merge branch 'main' into sqs-batch-receive
seemk Aug 22, 2024
b77188d
Merge branch 'main' into sqs-batch-receive
seemk Aug 27, 2024
4822b0b
Merge branch 'main' into sqs-batch-receive
seemk Aug 27, 2024
5fb4345
Merge branch 'main' into sqs-batch-receive
seemk Sep 10, 2024
25ea56d
Merge branch 'main' into sqs-batch-receive
seemk Sep 11, 2024
35adc39
Merge branch 'main' into sqs-batch-receive
seemk Sep 14, 2024
c68d15e
Merge branch 'main' into sqs-batch-receive
seemk Sep 25, 2024
a9c8df6
Merge branch 'main' into sqs-batch-receive
seemk Oct 2, 2024
6d30fa6
Merge branch 'main' into sqs-batch-receive
seemk Oct 15, 2024
ca771f5
Merge branch 'main' into sqs-batch-receive
seemk Oct 17, 2024
b562d80
Merge branch 'main' into sqs-batch-receive
seemk Oct 30, 2024
a5be283
Merge branch 'main' into sqs-batch-receive
seemk Nov 6, 2024
f237133
Merge branch 'main' into sqs-batch-receive
seemk Nov 7, 2024
62bf036
Merge branch 'main' into sqs-batch-receive
seemk Nov 20, 2024
953b3c5
Merge branch 'main' into sqs-batch-receive
seemk Nov 25, 2024
680f7d2
Merge branch 'main' into sqs-batch-receive
seemk Nov 25, 2024
6b7cb26
Merge branch 'main' into sqs-batch-receive
seemk Nov 26, 2024
0db74dd
Merge branch 'main' into sqs-batch-receive
seemk Nov 27, 2024
454fbf2
Merge branch 'main' into sqs-batch-receive
seemk Dec 2, 2024
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ aws-sdk instrumentation has few options available to choose from. You can set th
| ----------------------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `preRequestHook` | `AwsSdkRequestCustomAttributeFunction` | Hook called before request send, which allow to add custom attributes to span. |
| `responseHook` | `AwsSdkResponseCustomAttributeFunction` | Hook for adding custom attributes when response is received from aws. |
| `sqsProcessHook` | `AwsSdkSqsProcessCustomAttributeFunction` | Hook called after starting sqs `process` span (for each sqs received message), which allow to add custom attributes to it. |
| `suppressInternalInstrumentation` | `boolean` | Most aws operation use http requests under the hood. Set this to `true` to hide all underlying http spans. |
| `sqsExtractContextPropagationFromPayload` | `boolean` | Will parse and extract context propagation headers from SQS Payload, false by default. [When should it be used?](./doc/sns.md#integration-with-sqs) |
| `dynamoDBStatementSerializer` | `AwsSdkDynamoDBStatementSerializer` | AWS SDK instrumentation will serialize DynamoDB commands to the `db.statement` attribute using the specified function. Defaults to using a serializer that returns `undefined`. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -33,7 +31,6 @@ import {
} from '../types';
import {
MESSAGINGDESTINATIONKINDVALUES_QUEUE,
MESSAGINGOPERATIONVALUES_PROCESS,
MESSAGINGOPERATIONVALUES_RECEIVE,
SEMATTRS_MESSAGING_DESTINATION,
SEMATTRS_MESSAGING_DESTINATION_KIND,
Expand Down Expand Up @@ -134,7 +131,7 @@ export class SqsServiceExtension implements ServiceExtension {
responseHook = (
response: NormalizedResponse,
span: Span,
tracer: Tracer,
_tracer: Tracer,
config: AwsSdkInstrumentationConfig
) => {
switch (response.request.commandName) {
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
Expand Down
11 changes: 0 additions & 11 deletions plugins/node/opentelemetry-instrumentation-aws-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
import { Span } from '@opentelemetry/api';
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { SQS } from './aws-sdk.types';

export type CommandInput = Record<string, any>;

Expand Down Expand Up @@ -57,13 +56,6 @@ export interface AwsSdkResponseCustomAttributeFunction {
(span: Span, responseInfo: AwsSdkResponseHookInformation): void;
}

export interface AwsSdkSqsProcessHookInformation {
message: SQS.Message;
}
export interface AwsSdkSqsProcessCustomAttributeFunction {
(span: Span, sqsProcessInfo: AwsSdkSqsProcessHookInformation): void;
}

export type AwsSdkDynamoDBStatementSerializer = (
operation: string,
commandInput: CommandInput
Expand All @@ -76,9 +68,6 @@ export interface AwsSdkInstrumentationConfig extends InstrumentationConfig {
/** hook for adding custom attributes when response is received from aws */
responseHook?: AwsSdkResponseCustomAttributeFunction;

/** hook for adding custom attribute when an sqs process span is started */
sqsProcessHook?: AwsSdkSqsProcessCustomAttributeFunction;

/** custom serializer function for the db.statement attribute in DynamoDB spans */
dynamoDBStatementSerializer?: AwsSdkDynamoDBStatementSerializer;

Expand Down
Loading