Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit f1c3dc9

Browse files
author
Amir Blum
committed
feat(plugin-aws-sdk): add span name to request hook
1 parent fca954f commit f1c3dc9

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/plugin-aws-sdk/src/aws-sdk.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ class AwsPlugin extends BasePlugin<typeof AWS> {
7272
private _startAwsSpan(
7373
request: AWS.Request<any, any>,
7474
additionalAttributes?: Attributes,
75-
spanKind?: SpanKind
75+
spanKind?: SpanKind,
76+
spanName?: string
7677
): Span {
7778
const operation = (request as any).operation;
7879
const service = (request as any).service;
80+
const name = spanName ?? this._getSpanName(request);
7981

80-
const newSpan = this._tracer.startSpan(this._getSpanName(request), {
82+
const newSpan = this._tracer.startSpan(name, {
8183
kind: spanKind,
8284
attributes: {
8385
[AttributeNames.COMPONENT]: this.moduleName,
@@ -150,7 +152,8 @@ class AwsPlugin extends BasePlugin<typeof AWS> {
150152
const span = thisPlugin._startAwsSpan(
151153
awsRequest,
152154
requestMetadata.spanAttributes,
153-
requestMetadata.spanKind
155+
requestMetadata.spanKind,
156+
requestMetadata.spanName
154157
);
155158
thisPlugin._callPreRequestHooks(span, awsRequest);
156159
thisPlugin._registerCompletedEvent(span, awsRequest);
@@ -183,7 +186,8 @@ class AwsPlugin extends BasePlugin<typeof AWS> {
183186
const span = thisPlugin._startAwsSpan(
184187
awsRequest,
185188
requestMetadata.spanAttributes,
186-
requestMetadata.spanKind
189+
requestMetadata.spanKind,
190+
requestMetadata.spanName
187191
);
188192
thisPlugin._callPreRequestHooks(span, awsRequest);
189193
thisPlugin._registerCompletedEvent(span, awsRequest);

packages/plugin-aws-sdk/src/services/ServiceExtension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface RequestMetadata {
77
isIncoming: boolean;
88
spanAttributes?: Attributes;
99
spanKind?: SpanKind;
10+
spanName?: string;
1011
}
1112

1213
export interface ServiceExtension {

packages/plugin-aws-sdk/src/services/sqs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class SqsServiceExtension implements ServiceExtension {
3131
const queueUrl = this.extractQueueUrl(request);
3232
const queueName = this.extractQueueNameFromUrl(queueUrl);
3333
let spanKind: SpanKind = SpanKind.CLIENT;
34+
let spanName: string;
3435

3536
const spanAttributes = {
3637
[SqsAttributeNames.MESSAGING_SYSTEM]: "aws.sqs",
@@ -46,19 +47,22 @@ export class SqsServiceExtension implements ServiceExtension {
4647
case "receiveMessage":
4748
isIncoming = true;
4849
spanKind = SpanKind.CONSUMER;
50+
spanName = queueName;
4951
spanAttributes[SqsAttributeNames.MESSAGING_OPERATION] = "receive";
5052
break;
5153

5254
case "sendMessage":
5355
case "sendMessageBatch":
5456
spanKind = SpanKind.PRODUCER;
57+
spanName = queueName;
5558
break;
5659
}
5760

5861
return {
5962
isIncoming,
6063
spanAttributes,
6164
spanKind,
65+
spanName,
6266
};
6367
}
6468

0 commit comments

Comments
 (0)