Skip to content

Commit d546c4d

Browse files
authored
chore(instrumentation-amqplib): update semconv usage to ATTR_ exports (#3066)
1 parent fe3dc37 commit d546c4d

File tree

10 files changed

+571
-514
lines changed

10 files changed

+571
-514
lines changed

packages/instrumentation-amqplib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ By default, the tests that connect to RabbitMQ are skipped. To make sure these t
8989

9090
## Semantic Conventions
9191

92-
This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
92+
This package emits telemetry using Semantic Convention [version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
9393

9494
Attributes collected:
9595

packages/instrumentation-amqplib/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
},
5353
"dependencies": {
5454
"@opentelemetry/core": "^2.0.0",
55-
"@opentelemetry/instrumentation": "^0.205.0",
56-
"@opentelemetry/semantic-conventions": "^1.27.0"
55+
"@opentelemetry/instrumentation": "^0.205.0"
5756
},
5857
"devDependencies": {
5958
"@opentelemetry/api": "^1.3.0",

packages/instrumentation-amqplib/src/amqplib.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ import {
3737
isWrapped,
3838
safeExecuteInTheMiddle,
3939
} from '@opentelemetry/instrumentation';
40+
import { ATTR_MESSAGING_OPERATION } from './semconv';
4041
import {
41-
SEMATTRS_MESSAGING_DESTINATION,
42-
SEMATTRS_MESSAGING_DESTINATION_KIND,
43-
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
44-
SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY,
45-
SEMATTRS_MESSAGING_OPERATION,
46-
MESSAGINGOPERATIONVALUES_PROCESS,
47-
SEMATTRS_MESSAGING_MESSAGE_ID,
48-
SEMATTRS_MESSAGING_CONVERSATION_ID,
49-
} from '@opentelemetry/semantic-conventions';
42+
ATTR_MESSAGING_DESTINATION,
43+
ATTR_MESSAGING_DESTINATION_KIND,
44+
ATTR_MESSAGING_RABBITMQ_ROUTING_KEY,
45+
MESSAGING_DESTINATION_KIND_VALUE_TOPIC,
46+
MESSAGING_OPERATION_VALUE_PROCESS,
47+
OLD_ATTR_MESSAGING_MESSAGE_ID,
48+
ATTR_MESSAGING_CONVERSATION_ID,
49+
} from '../src/semconv-obsolete';
5050
import type {
5151
Connection,
5252
ConsumeMessage,
@@ -432,14 +432,13 @@ export class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumen
432432
kind: SpanKind.CONSUMER,
433433
attributes: {
434434
...channel?.connection?.[CONNECTION_ATTRIBUTES],
435-
[SEMATTRS_MESSAGING_DESTINATION]: exchange,
436-
[SEMATTRS_MESSAGING_DESTINATION_KIND]:
437-
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
438-
[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: msg.fields?.routingKey,
439-
[SEMATTRS_MESSAGING_OPERATION]: MESSAGINGOPERATIONVALUES_PROCESS,
440-
[SEMATTRS_MESSAGING_MESSAGE_ID]: msg?.properties.messageId,
441-
[SEMATTRS_MESSAGING_CONVERSATION_ID]:
442-
msg?.properties.correlationId,
435+
[ATTR_MESSAGING_DESTINATION]: exchange,
436+
[ATTR_MESSAGING_DESTINATION_KIND]:
437+
MESSAGING_DESTINATION_KIND_VALUE_TOPIC,
438+
[ATTR_MESSAGING_RABBITMQ_ROUTING_KEY]: msg.fields?.routingKey,
439+
[ATTR_MESSAGING_OPERATION]: MESSAGING_OPERATION_VALUE_PROCESS,
440+
[OLD_ATTR_MESSAGING_MESSAGE_ID]: msg?.properties.messageId,
441+
[ATTR_MESSAGING_CONVERSATION_ID]: msg?.properties.correlationId,
443442
},
444443
links,
445444
},
@@ -655,12 +654,13 @@ export class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumen
655654
kind: SpanKind.PRODUCER,
656655
attributes: {
657656
...channel.connection[CONNECTION_ATTRIBUTES],
658-
[SEMATTRS_MESSAGING_DESTINATION]: exchange,
659-
[SEMATTRS_MESSAGING_DESTINATION_KIND]:
660-
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
661-
[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey,
662-
[SEMATTRS_MESSAGING_MESSAGE_ID]: options?.messageId,
663-
[SEMATTRS_MESSAGING_CONVERSATION_ID]: options?.correlationId,
657+
[ATTR_MESSAGING_DESTINATION]: exchange,
658+
[ATTR_MESSAGING_DESTINATION_KIND]:
659+
MESSAGING_DESTINATION_KIND_VALUE_TOPIC,
660+
661+
[ATTR_MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey,
662+
[OLD_ATTR_MESSAGING_MESSAGE_ID]: options?.messageId,
663+
[ATTR_MESSAGING_CONVERSATION_ID]: options?.correlationId,
664664
},
665665
});
666666
const modifiedOptions = options ?? {};
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
/*
18+
* This file contains constants for values that where replaced/removed from
19+
* Semantic Conventions long enough ago that they do not have `ATTR_*`
20+
* constants in the `@opentelemetry/semantic-conventions` package. Eventually
21+
* it is expected that this instrumention will be updated to emit telemetry
22+
* using modern Semantic Conventions, dropping the need for the constants in
23+
* this file.
24+
*/
25+
26+
/**
27+
* The message destination name. This might be equal to the span name but is required nevertheless.
28+
*
29+
* @deprecated Use ATTR_MESSAGING_DESTINATION_NAME in [incubating entry-point]({@link https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv}).
30+
*/
31+
export const ATTR_MESSAGING_DESTINATION = 'messaging.destination' as const;
32+
33+
/**
34+
* The kind of message destination.
35+
*
36+
* @deprecated Removed in semconv v1.20.0.
37+
*/
38+
export const ATTR_MESSAGING_DESTINATION_KIND =
39+
'messaging.destination_kind' as const;
40+
41+
/**
42+
* RabbitMQ message routing key.
43+
*
44+
* @deprecated Use ATTR_MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY in [incubating entry-point]({@link https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv}).
45+
*/
46+
export const ATTR_MESSAGING_RABBITMQ_ROUTING_KEY =
47+
'messaging.rabbitmq.routing_key' as const;
48+
49+
/**
50+
* A string identifying the kind of message consumption as defined in the [Operation names](#operation-names) section above. If the operation is &#34;send&#34;, this attribute MUST NOT be set, since the operation can be inferred from the span kind in that case.
51+
*
52+
* @deprecated Use MESSAGING_OPERATION_TYPE_VALUE_PROCESS in [incubating entry-point]({@link https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv}).
53+
*/
54+
export const MESSAGING_OPERATION_VALUE_PROCESS = 'process' as const;
55+
56+
/**
57+
* The name of the transport protocol.
58+
*
59+
* @deprecated Use ATTR_NETWORK_PROTOCOL_NAME.
60+
*/
61+
export const ATTR_MESSAGING_PROTOCOL = 'messaging.protocol' as const;
62+
63+
/**
64+
* The version of the transport protocol.
65+
*
66+
* @deprecated Use ATTR_NETWORK_PROTOCOL_VERSION.
67+
*/
68+
export const ATTR_MESSAGING_PROTOCOL_VERSION =
69+
'messaging.protocol_version' as const;
70+
71+
/**
72+
* Connection string.
73+
*
74+
* @deprecated Removed in semconv v1.17.0.
75+
*/
76+
export const ATTR_MESSAGING_URL = 'messaging.url' as const;
77+
78+
/**
79+
* The kind of message destination.
80+
*
81+
* @deprecated Removed in semconv v1.20.0.
82+
*/
83+
export const MESSAGING_DESTINATION_KIND_VALUE_TOPIC = 'topic' as const;
84+
85+
/**
86+
* A value used by the messaging system as an identifier for the message, represented as a string.
87+
*
88+
* @deprecated Use ATTR_MESSAGING_MESSAGE_ID in [incubating entry-point]({@link https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv}).
89+
*
90+
* Note: changing to `ATTR_MESSAGING_MESSAGE_ID` means a change in value from `messaging.message_id` to `messaging.message.id`.
91+
*/
92+
export const OLD_ATTR_MESSAGING_MESSAGE_ID = 'messaging.message_id' as const;
93+
94+
/**
95+
* The [conversation ID](#conversations) identifying the conversation to which the message belongs, represented as a string. Sometimes called &#34;Correlation ID&#34;.
96+
*
97+
* @deprecated Use ATTR_MESSAGING_MESSAGE_CONVERSATION_ID in [incubating entry-point]({@link https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv}).
98+
*/
99+
export const ATTR_MESSAGING_CONVERSATION_ID =
100+
'messaging.conversation_id' as const;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
/*
18+
* This file contains a copy of unstable semantic convention definitions
19+
* used by this package.
20+
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
21+
*/
22+
23+
/**
24+
* Deprecated, use `messaging.operation.type` instead.
25+
*
26+
* @example publish
27+
* @example create
28+
* @example process
29+
*
30+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
31+
*
32+
* @deprecated Replaced by `messaging.operation.type`.
33+
*/
34+
export const ATTR_MESSAGING_OPERATION = 'messaging.operation' as const;
35+
36+
/**
37+
* The messaging system as identified by the client instrumentation.
38+
*
39+
* @note The actual messaging system may differ from the one known by the client. For example, when using Kafka client libraries to communicate with Azure Event Hubs, the `messaging.system` is set to `kafka` based on the instrumentation's best knowledge.
40+
*
41+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
42+
*/
43+
export const ATTR_MESSAGING_SYSTEM = 'messaging.system' as const;
44+
45+
/**
46+
* Deprecated, use `server.address` on client spans and `client.address` on server spans.
47+
*
48+
* @example example.com
49+
*
50+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
51+
*
52+
* @deprecated Replaced by `server.address` on client spans and `client.address` on server spans.
53+
*/
54+
export const ATTR_NET_PEER_NAME = 'net.peer.name' as const;
55+
56+
/**
57+
* Deprecated, use `server.port` on client spans and `client.port` on server spans.
58+
*
59+
* @example 8080
60+
*
61+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
62+
*
63+
* @deprecated Replaced by `server.port` on client spans and `client.port` on server spans.
64+
*/
65+
export const ATTR_NET_PEER_PORT = 'net.peer.port' as const;

packages/instrumentation-amqplib/src/utils.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ import {
2323
AttributeValue,
2424
} from '@opentelemetry/api';
2525
import {
26-
SEMATTRS_MESSAGING_PROTOCOL,
27-
SEMATTRS_MESSAGING_PROTOCOL_VERSION,
28-
SEMATTRS_MESSAGING_SYSTEM,
29-
SEMATTRS_MESSAGING_URL,
30-
SEMATTRS_NET_PEER_NAME,
31-
SEMATTRS_NET_PEER_PORT,
32-
} from '@opentelemetry/semantic-conventions';
26+
ATTR_MESSAGING_SYSTEM,
27+
ATTR_NET_PEER_NAME,
28+
ATTR_NET_PEER_PORT,
29+
} from './semconv';
30+
import {
31+
ATTR_MESSAGING_PROTOCOL,
32+
ATTR_MESSAGING_PROTOCOL_VERSION,
33+
ATTR_MESSAGING_URL,
34+
} from '../src/semconv-obsolete';
3335
import type * as amqp from 'amqplib';
3436

3537
export const MESSAGE_STORED_SPAN: unique symbol = Symbol(
@@ -128,7 +130,7 @@ export const getConnectionAttributesFromServer = (
128130
const product = conn.serverProperties.product?.toLowerCase?.();
129131
if (product) {
130132
return {
131-
[SEMATTRS_MESSAGING_SYSTEM]: product,
133+
[ATTR_MESSAGING_SYSTEM]: product,
132134
};
133135
} else {
134136
return {};
@@ -139,7 +141,7 @@ export const getConnectionAttributesFromUrl = (
139141
url: string | amqp.Options.Connect
140142
): Attributes => {
141143
const attributes: Attributes = {
142-
[SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', // this is the only protocol supported by the instrumented library
144+
[ATTR_MESSAGING_PROTOCOL_VERSION]: '0.9.1', // this is the only protocol supported by the instrumented library
143145
};
144146

145147
url = url || 'amqp://localhost';
@@ -150,7 +152,7 @@ export const getConnectionAttributesFromUrl = (
150152
Object.assign(attributes, {
151153
...extractConnectionAttributeOrLog(
152154
url,
153-
SEMATTRS_MESSAGING_PROTOCOL,
155+
ATTR_MESSAGING_PROTOCOL,
154156
protocol,
155157
'protocol'
156158
),
@@ -160,32 +162,27 @@ export const getConnectionAttributesFromUrl = (
160162
Object.assign(attributes, {
161163
...extractConnectionAttributeOrLog(
162164
url,
163-
SEMATTRS_NET_PEER_NAME,
165+
ATTR_NET_PEER_NAME,
164166
hostname,
165167
'hostname'
166168
),
167169
});
168170

169171
const port = getPort(connectOptions.port, protocol);
170172
Object.assign(attributes, {
171-
...extractConnectionAttributeOrLog(
172-
url,
173-
SEMATTRS_NET_PEER_PORT,
174-
port,
175-
'port'
176-
),
173+
...extractConnectionAttributeOrLog(url, ATTR_NET_PEER_PORT, port, 'port'),
177174
});
178175
} else {
179176
const censoredUrl = censorPassword(url);
180-
attributes[SEMATTRS_MESSAGING_URL] = censoredUrl;
177+
attributes[ATTR_MESSAGING_URL] = censoredUrl;
181178
try {
182179
const urlParts = new URL(censoredUrl);
183180

184181
const protocol = getProtocol(urlParts.protocol);
185182
Object.assign(attributes, {
186183
...extractConnectionAttributeOrLog(
187184
censoredUrl,
188-
SEMATTRS_MESSAGING_PROTOCOL,
185+
ATTR_MESSAGING_PROTOCOL,
189186
protocol,
190187
'protocol'
191188
),
@@ -195,7 +192,7 @@ export const getConnectionAttributesFromUrl = (
195192
Object.assign(attributes, {
196193
...extractConnectionAttributeOrLog(
197194
censoredUrl,
198-
SEMATTRS_NET_PEER_NAME,
195+
ATTR_NET_PEER_NAME,
199196
hostname,
200197
'hostname'
201198
),
@@ -208,7 +205,7 @@ export const getConnectionAttributesFromUrl = (
208205
Object.assign(attributes, {
209206
...extractConnectionAttributeOrLog(
210207
censoredUrl,
211-
SEMATTRS_NET_PEER_PORT,
208+
ATTR_NET_PEER_PORT,
212209
port,
213210
'port'
214211
),

0 commit comments

Comments
 (0)