Skip to content

Commit 8028d85

Browse files
committed
update semconv values
1 parent fc5ba3c commit 8028d85

File tree

5 files changed

+65
-61
lines changed

5 files changed

+65
-61
lines changed

plugins/node/opentelemetry-instrumentation-aws-sdk/doc/sqs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ The following methods are automatically enhanced:
1414
### receiveMessage
1515

1616
- [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.
17-
- Additional "processing spans" are created for each message received by the application.
18-
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.
17+
- Additional "processing spans" are created for each message received by the application.
18+
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.
1919
Those processing spans are created by the library. This behavior is partially implemented, [See discussion below](#processing-spans).
20-
- Sets the inter process context correctly, so that additional spans created through the process will be linked to parent spans correctly.
20+
- Sets the inter process context correctly, so that additional spans created through the process will be linked to parent spans correctly.
2121
This behavior is partially implemented, [See discussion below](#processing-spans).
2222
- Extract trace context from SQS MessageAttributes, and set span's `parent` and `links` correctly according to the spec.
2323

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export const ATTR_MESSAGING_BATCH_MESSAGE_COUNT =
18+
'messaging.batch.message_count';
19+
export const ATTR_MESSAGING_DESTINATION_NAME = 'messaging.destination.name';
20+
export const ATTR_MESSAGING_MESSAGE_ID = 'messaging.message.id';
21+
export const ATTR_MESSAGING_OPERATION_TYPE = 'messaging.operation.type';

plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/sqs.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ import {
3030
NormalizedResponse,
3131
} from '../types';
3232
import {
33-
MESSAGINGDESTINATIONKINDVALUES_QUEUE,
34-
MESSAGINGOPERATIONVALUES_RECEIVE,
35-
SEMATTRS_MESSAGING_DESTINATION,
36-
SEMATTRS_MESSAGING_DESTINATION_KIND,
37-
SEMATTRS_MESSAGING_MESSAGE_ID,
38-
SEMATTRS_MESSAGING_OPERATION,
33+
ATTR_URL_FULL,
3934
SEMATTRS_MESSAGING_SYSTEM,
40-
SEMATTRS_MESSAGING_URL,
4135
} from '@opentelemetry/semantic-conventions';
36+
import {
37+
ATTR_MESSAGING_BATCH_MESSAGE_COUNT,
38+
ATTR_MESSAGING_DESTINATION_NAME,
39+
ATTR_MESSAGING_MESSAGE_ID,
40+
ATTR_MESSAGING_OPERATION_TYPE,
41+
} from '../semconv';
4242
import {
4343
contextGetter,
4444
extractPropagationContext,
@@ -57,11 +57,9 @@ export class SqsServiceExtension implements ServiceExtension {
5757
let spanName: string | undefined;
5858

5959
const spanAttributes: Attributes = {
60-
[SEMATTRS_MESSAGING_SYSTEM]: 'aws.sqs',
61-
[SEMATTRS_MESSAGING_DESTINATION_KIND]:
62-
MESSAGINGDESTINATIONKINDVALUES_QUEUE,
63-
[SEMATTRS_MESSAGING_DESTINATION]: queueName,
64-
[SEMATTRS_MESSAGING_URL]: queueUrl,
60+
[SEMATTRS_MESSAGING_SYSTEM]: 'aws_sqs',
61+
[ATTR_MESSAGING_DESTINATION_NAME]: queueName,
62+
[ATTR_URL_FULL]: queueUrl,
6563
};
6664

6765
let isIncoming = false;
@@ -72,8 +70,7 @@ export class SqsServiceExtension implements ServiceExtension {
7270
isIncoming = true;
7371
spanKind = SpanKind.CONSUMER;
7472
spanName = `${queueName} receive`;
75-
spanAttributes[SEMATTRS_MESSAGING_OPERATION] =
76-
MESSAGINGOPERATIONVALUES_RECEIVE;
73+
spanAttributes[ATTR_MESSAGING_OPERATION_TYPE] = 'receive';
7774

7875
request.commandInput.MessageAttributeNames =
7976
addPropagationFieldsToAttributeNames(
@@ -138,10 +135,7 @@ export class SqsServiceExtension implements ServiceExtension {
138135
) => {
139136
switch (response.request.commandName) {
140137
case 'SendMessage':
141-
span.setAttribute(
142-
SEMATTRS_MESSAGING_MESSAGE_ID,
143-
response?.data?.MessageId
144-
);
138+
span.setAttribute(ATTR_MESSAGING_MESSAGE_ID, response?.data?.MessageId);
145139
break;
146140

147141
case 'SendMessageBatch':
@@ -151,7 +145,7 @@ export class SqsServiceExtension implements ServiceExtension {
151145
case 'ReceiveMessage': {
152146
const messages: SQS.Message[] = response?.data?.Messages || [];
153147

154-
span.setAttribute('messaging.batch.message_count', messages.length);
148+
span.setAttribute(ATTR_MESSAGING_BATCH_MESSAGE_COUNT, messages.length);
155149

156150
for (const message of messages) {
157151
const propagatedContext = propagation.extract(
@@ -169,7 +163,7 @@ export class SqsServiceExtension implements ServiceExtension {
169163
span.addLink({
170164
context: spanContext,
171165
attributes: {
172-
[SEMATTRS_MESSAGING_MESSAGE_ID]: message.MessageId,
166+
[ATTR_MESSAGING_MESSAGE_ID]: message.MessageId,
173167
},
174168
});
175169
}

plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,21 @@ import 'mocha';
4242
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
4343
import { context, SpanStatusCode, trace, Span } from '@opentelemetry/api';
4444
import {
45-
MESSAGINGDESTINATIONKINDVALUES_QUEUE,
45+
ATTR_URL_FULL,
4646
MESSAGINGOPERATIONVALUES_RECEIVE,
4747
SEMATTRS_HTTP_STATUS_CODE,
4848
SEMATTRS_MESSAGING_DESTINATION,
49-
SEMATTRS_MESSAGING_DESTINATION_KIND,
50-
SEMATTRS_MESSAGING_MESSAGE_ID,
5149
SEMATTRS_MESSAGING_OPERATION,
5250
SEMATTRS_MESSAGING_SYSTEM,
5351
SEMATTRS_MESSAGING_URL,
5452
SEMATTRS_RPC_METHOD,
5553
SEMATTRS_RPC_SERVICE,
5654
SEMATTRS_RPC_SYSTEM,
5755
} from '@opentelemetry/semantic-conventions';
56+
import {
57+
ATTR_MESSAGING_DESTINATION_NAME,
58+
ATTR_MESSAGING_MESSAGE_ID,
59+
} from '../src/semconv';
5860
import { AttributeNames } from '../src/enums';
5961
import { expect } from 'expect';
6062
import * as fs from 'fs';
@@ -323,17 +325,12 @@ describe('instrumentation-aws-sdk-v3', () => {
323325
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
324326

325327
// custom messaging attributes
326-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws.sqs');
327-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual(
328-
MESSAGINGDESTINATIONKINDVALUES_QUEUE
329-
);
330-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
328+
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws_sqs');
329+
expect(span.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toEqual(
331330
'otel-demo-aws-sdk'
332331
);
333-
expect(span.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
334-
params.QueueUrl
335-
);
336-
expect(span.attributes[SEMATTRS_MESSAGING_MESSAGE_ID]).toEqual(
332+
expect(span.attributes[ATTR_URL_FULL]).toEqual(params.QueueUrl);
333+
expect(span.attributes[ATTR_MESSAGING_MESSAGE_ID]).toEqual(
337334
response.MessageId
338335
);
339336
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
@@ -383,16 +380,11 @@ describe('instrumentation-aws-sdk-v3', () => {
383380
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
384381

385382
// messaging semantic attributes
386-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws.sqs');
387-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual(
388-
MESSAGINGDESTINATIONKINDVALUES_QUEUE
389-
);
390-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
383+
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws_sqs');
384+
expect(span.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toEqual(
391385
'otel-demo-aws-sdk'
392386
);
393-
expect(span.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
394-
params.QueueUrl
395-
);
387+
expect(span.attributes[ATTR_URL_FULL]).toEqual(params.QueueUrl);
396388
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
397389
});
398390

plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ import { AWSError } from 'aws-sdk';
2626
import type { SQS } from 'aws-sdk';
2727

2828
import {
29-
MESSAGINGDESTINATIONKINDVALUES_QUEUE,
29+
ATTR_URL_FULL,
3030
SEMATTRS_HTTP_STATUS_CODE,
31-
SEMATTRS_MESSAGING_DESTINATION,
32-
SEMATTRS_MESSAGING_DESTINATION_KIND,
33-
SEMATTRS_MESSAGING_MESSAGE_ID,
3431
SEMATTRS_MESSAGING_SYSTEM,
35-
SEMATTRS_MESSAGING_URL,
3632
SEMATTRS_RPC_METHOD,
3733
SEMATTRS_RPC_SERVICE,
3834
SEMATTRS_RPC_SYSTEM,
3935
} from '@opentelemetry/semantic-conventions';
36+
import {
37+
ATTR_MESSAGING_DESTINATION_NAME,
38+
ATTR_MESSAGING_MESSAGE_ID,
39+
} from '../src/semconv';
4040
import { SpanKind, trace } from '@opentelemetry/api';
4141
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
4242
import { mockV2AwsSend } from './testing-utils';
@@ -186,15 +186,12 @@ describe('SQS', () => {
186186
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
187187

188188
// custom messaging attributes
189-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws.sqs');
190-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual(
191-
MESSAGINGDESTINATIONKINDVALUES_QUEUE
192-
);
193-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
189+
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws_sqs');
190+
expect(span.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toEqual(
194191
QueueName
195192
);
196-
expect(span.attributes[SEMATTRS_MESSAGING_URL]).toEqual(params.QueueUrl);
197-
expect(span.attributes[SEMATTRS_MESSAGING_MESSAGE_ID]).toEqual(
193+
expect(span.attributes[ATTR_URL_FULL]).toEqual(params.QueueUrl);
194+
expect(span.attributes[ATTR_MESSAGING_MESSAGE_ID]).toEqual(
198195
response.MessageId
199196
);
200197
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
@@ -348,16 +345,16 @@ describe('SQS', () => {
348345
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
349346
);
350347
expect(links[0].context.spanId).toStrictEqual('aaaaaaaaaaaaaaaa');
351-
expect(
352-
links[0].attributes?.[SEMATTRS_MESSAGING_MESSAGE_ID]
353-
).toStrictEqual('1');
348+
expect(links[0].attributes?.[ATTR_MESSAGING_MESSAGE_ID]).toStrictEqual(
349+
'1'
350+
);
354351
expect(links[1].context.traceId).toStrictEqual(
355352
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
356353
);
357354
expect(links[1].context.spanId).toStrictEqual('bbbbbbbbbbbbbbbb');
358-
expect(
359-
links[1].attributes?.[SEMATTRS_MESSAGING_MESSAGE_ID]
360-
).toStrictEqual('2');
355+
expect(links[1].attributes?.[ATTR_MESSAGING_MESSAGE_ID]).toStrictEqual(
356+
'2'
357+
);
361358
});
362359

363360
it('adds message count to the receive span', async () => {

0 commit comments

Comments
 (0)