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

Commit 694b1c2

Browse files
author
Amir Blum
authored
chore: upgrade to otel v0.19.0 (#100)
1 parent c95b034 commit 694b1c2

File tree

38 files changed

+414
-369
lines changed

38 files changed

+414
-369
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The instrumentations in this repo are:
2929
- strictly complies with [open telemetry semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions)
3030
- up to date with latest SDK version
3131

32-
**Compatible with [SDK v0.18.0](https://github.com/open-telemetry/opentelemetry-js/releases/tag/v0.18.0)**
32+
**Compatible with [SDK v0.19.0](https://github.com/open-telemetry/opentelemetry-js/releases/tag/v0.19.0)**
3333
## Instrumentations
3434
| Instrumentation Package | Instrumented Lib | NPM |
3535
| --- | --- | --- |
@@ -46,7 +46,8 @@ The instrumentations in this repo are:
4646
### Instrumentations in this repo are using opentelemetry [Instrumentation API](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation).
4747
For documentation using with the old [plugin](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-core/src/trace/Plugin.ts) api, please go [here](https://github.com/aspecto-io/opentelemetry-ext-js/tree/4393fff108c477d05ecd02dd7d9552ea1d482853).
4848

49-
**Tested and verified against otel v0.18.0**
49+
**Tested and verified against otel v0.19.0**
50+
- Versions **0.4.x** of the instrumentations are compatible with otel version v0.19.0
5051
- Versions **0.3.x** of the instrumentations are compatible with otel version v0.18.0
5152
- Versions **0.2.x** of the instrumentations are compatible with otel version v0.17.0
5253
- Versions **0.1.x** of the instrumentations are compatible with otel version v0.16.0

packages/instrumentation-amqplib/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@
3636
"url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues"
3737
},
3838
"dependencies": {
39-
"@opentelemetry/api": "^0.18.0",
40-
"@opentelemetry/instrumentation": "^0.18.0",
41-
"@opentelemetry/semantic-conventions": "^0.18.0"
39+
"@opentelemetry/api": "^1.0.0-rc.0",
40+
"@opentelemetry/instrumentation": "^0.19.0",
41+
"@opentelemetry/semantic-conventions": "^0.19.0"
4242
},
4343
"devDependencies": {
44-
"@opentelemetry/api": "^0.18.0",
45-
"@opentelemetry/core": "^0.18.0",
46-
"@opentelemetry/node": "^0.18.0",
47-
"@opentelemetry/tracing": "^0.18.0",
44+
"@opentelemetry/core": "^0.19.0",
45+
"@opentelemetry/node": "^0.19.0",
46+
"@opentelemetry/tracing": "^0.19.0",
4847
"@types/amqplib": "^0.5.17",
4948
"@types/lodash": "^4.14.168",
5049
"@types/mocha": "^8.2.0",

packages/instrumentation-amqplib/src/amqplib.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import {
77
isWrapped,
88
safeExecuteInTheMiddle,
99
} from '@opentelemetry/instrumentation';
10-
import { MessagingAttribute, MessagingOperationName } from '@opentelemetry/semantic-conventions';
10+
import {
11+
SemanticAttributes,
12+
MessagingOperationValues,
13+
MessagingDestinationKindValues,
14+
} from '@opentelemetry/semantic-conventions';
1115
import type amqp from 'amqplib';
1216
import { AmqplibInstrumentationConfig, DEFAULT_CONFIG, EndOperation } from './types';
1317
import {
@@ -239,10 +243,10 @@ export class AmqplibInstrumentation extends InstrumentationBase<typeof amqp> {
239243
kind: SpanKind.CONSUMER,
240244
attributes: {
241245
...channel?.connection?.[CONNECTION_ATTRIBUTES],
242-
[MessagingAttribute.MESSAGING_DESTINATION]: exchange,
243-
[MessagingAttribute.MESSAGING_DESTINATION_KIND]: 'topic',
244-
[MessagingAttribute.MESSAGING_RABBITMQ_ROUTING_KEY]: msg?.fields?.routingKey,
245-
[MessagingAttribute.MESSAGING_OPERATION]: MessagingOperationName.PROCESS,
246+
[SemanticAttributes.MESSAGING_DESTINATION]: exchange,
247+
[SemanticAttributes.MESSAGING_DESTINATION_KIND]: MessagingDestinationKindValues.TOPIC,
248+
['messaging.rabbitmq.routing_key']: msg?.fields?.routingKey,
249+
[SemanticAttributes.MESSAGING_OPERATION]: MessagingOperationValues.PROCESS,
246250
},
247251
},
248252
parentContext
@@ -306,9 +310,9 @@ export class AmqplibInstrumentation extends InstrumentationBase<typeof amqp> {
306310
kind: SpanKind.PRODUCER,
307311
attributes: {
308312
...this.connection[CONNECTION_ATTRIBUTES],
309-
[MessagingAttribute.MESSAGING_DESTINATION]: exchange,
310-
[MessagingAttribute.MESSAGING_DESTINATION_KIND]: 'topic',
311-
[MessagingAttribute.MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey,
313+
[SemanticAttributes.MESSAGING_DESTINATION]: exchange,
314+
[SemanticAttributes.MESSAGING_DESTINATION_KIND]: MessagingDestinationKindValues.TOPIC,
315+
['messaging.rabbitmq.routing_key']: routingKey,
312316
},
313317
});
314318

packages/instrumentation-amqplib/src/utils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { diag, SpanAttributes, SpanAttributeValue } from '@opentelemetry/api';
2-
import { GeneralAttribute, MessagingAttribute } from '@opentelemetry/semantic-conventions';
2+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
33
import type amqp from 'amqplib';
44

55
export const MESSAGE_STORED_SPAN: unique symbol = Symbol('opentelemetry.amqplib.message.stored-span');
@@ -52,12 +52,12 @@ export const getConnectionAttributesFromUrl = (
5252
conn: amqp.Connection
5353
): SpanAttributes => {
5454
const attributes: SpanAttributes = {
55-
[MessagingAttribute.MESSAGING_PROTOCOL_VERSION]: '0.9.1', // this is the only protocol supported by the instrumented library
55+
[SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', // this is the only protocol supported by the instrumented library
5656
};
5757

5858
const product = conn?.['serverProperties']?.product?.toLowerCase?.();
5959
if (product) {
60-
attributes[MessagingAttribute.MESSAGING_SYSTEM] = product;
60+
attributes[SemanticAttributes.MESSAGING_SYSTEM] = product;
6161
}
6262

6363
url = url || 'amqp://localhost';
@@ -66,38 +66,38 @@ export const getConnectionAttributesFromUrl = (
6666

6767
const protocol = getProtocol(connectOptions.protocol);
6868
Object.assign(attributes, {
69-
...extractConnectionAttributeOrLog(url, MessagingAttribute.MESSAGING_PROTOCOL, protocol, 'protocol'),
69+
...extractConnectionAttributeOrLog(url, SemanticAttributes.MESSAGING_PROTOCOL, protocol, 'protocol'),
7070
});
7171

7272
const hostname = getHostname(connectOptions?.hostname);
7373
Object.assign(attributes, {
74-
...extractConnectionAttributeOrLog(url, GeneralAttribute.NET_PEER_NAME, hostname, 'hostname'),
74+
...extractConnectionAttributeOrLog(url, SemanticAttributes.NET_PEER_NAME, hostname, 'hostname'),
7575
});
7676

7777
const port = getPort(connectOptions.port, protocol);
7878
Object.assign(attributes, {
79-
...extractConnectionAttributeOrLog(url, GeneralAttribute.NET_PEER_PORT, port, 'port'),
79+
...extractConnectionAttributeOrLog(url, SemanticAttributes.NET_PEER_PORT, port, 'port'),
8080
});
8181

82-
attributes[GeneralAttribute.NET_PEER_PORT] = getPort(url.port, protocol);
82+
attributes[SemanticAttributes.NET_PEER_PORT] = getPort(url.port, protocol);
8383
} else {
84-
attributes[MessagingAttribute.MESSAGING_URL] = url;
84+
attributes[SemanticAttributes.MESSAGING_URL] = url;
8585
try {
8686
const urlParts = new URL(url);
8787

8888
const protocol = getProtocol(urlParts.protocol);
8989
Object.assign(attributes, {
90-
...extractConnectionAttributeOrLog(url, MessagingAttribute.MESSAGING_PROTOCOL, protocol, 'protocol'),
90+
...extractConnectionAttributeOrLog(url, SemanticAttributes.MESSAGING_PROTOCOL, protocol, 'protocol'),
9191
});
9292

9393
const hostname = getHostname(urlParts.hostname);
9494
Object.assign(attributes, {
95-
...extractConnectionAttributeOrLog(url, GeneralAttribute.NET_PEER_NAME, hostname, 'hostname'),
95+
...extractConnectionAttributeOrLog(url, SemanticAttributes.NET_PEER_NAME, hostname, 'hostname'),
9696
});
9797

9898
const port = getPort(parseInt(urlParts.port), protocol);
9999
Object.assign(attributes, {
100-
...extractConnectionAttributeOrLog(url, GeneralAttribute.NET_PEER_PORT, port, 'port'),
100+
...extractConnectionAttributeOrLog(url, SemanticAttributes.NET_PEER_PORT, port, 'port'),
101101
});
102102
} catch (err) {
103103
diag.error('amqplib instrumentation: error while extracting connection details from connection url', {

packages/instrumentation-amqplib/test/amqplib-callbacks.spec.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { AmqplibInstrumentation } from '../src';
88
const instrumentation = new AmqplibInstrumentation();
99
instrumentation.enable();
1010
import amqpCallback from 'amqplib/callback_api';
11-
import { GeneralAttribute, MessagingAttribute } from '@opentelemetry/semantic-conventions';
12-
import { propagation, Span, SpanKind, SpanStatusCode } from '@opentelemetry/api';
11+
import { MessagingDestinationKindValues, SemanticAttributes } from '@opentelemetry/semantic-conventions';
12+
import { propagation, SpanKind } from '@opentelemetry/api';
1313
import { asyncConsume } from './utils';
1414

1515
const msgPayload = 'payload from test';
@@ -73,27 +73,31 @@ describe('amqplib instrumentation callback model', function () {
7373

7474
// assert publish span
7575
expect(publishSpan.kind).toEqual(SpanKind.PRODUCER);
76-
expect(publishSpan.attributes[MessagingAttribute.MESSAGING_SYSTEM]).toEqual('rabbitmq');
77-
expect(publishSpan.attributes[MessagingAttribute.MESSAGING_DESTINATION]).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used"
78-
expect(publishSpan.attributes[MessagingAttribute.MESSAGING_DESTINATION_KIND]).toEqual('topic');
79-
expect(publishSpan.attributes[MessagingAttribute.MESSAGING_RABBITMQ_ROUTING_KEY]).toEqual(queueName);
80-
expect(publishSpan.attributes[MessagingAttribute.MESSAGING_PROTOCOL]).toEqual('AMQP');
81-
expect(publishSpan.attributes[MessagingAttribute.MESSAGING_PROTOCOL_VERSION]).toEqual('0.9.1');
82-
expect(publishSpan.attributes[MessagingAttribute.MESSAGING_URL]).toEqual(url);
83-
expect(publishSpan.attributes[GeneralAttribute.NET_PEER_NAME]).toEqual('localhost');
84-
expect(publishSpan.attributes[GeneralAttribute.NET_PEER_PORT]).toEqual(22221);
76+
expect(publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toEqual('rabbitmq');
77+
expect(publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used"
78+
expect(publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND]).toEqual(
79+
MessagingDestinationKindValues.TOPIC
80+
);
81+
expect(publishSpan.attributes['messaging.rabbitmq.routing_key']).toEqual(queueName);
82+
expect(publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]).toEqual('AMQP');
83+
expect(publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION]).toEqual('0.9.1');
84+
expect(publishSpan.attributes[SemanticAttributes.MESSAGING_URL]).toEqual(url);
85+
expect(publishSpan.attributes[SemanticAttributes.NET_PEER_NAME]).toEqual('localhost');
86+
expect(publishSpan.attributes[SemanticAttributes.NET_PEER_PORT]).toEqual(22221);
8587

8688
// assert consume span
8789
expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER);
88-
expect(consumeSpan.attributes[MessagingAttribute.MESSAGING_SYSTEM]).toEqual('rabbitmq');
89-
expect(consumeSpan.attributes[MessagingAttribute.MESSAGING_DESTINATION]).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used"
90-
expect(consumeSpan.attributes[MessagingAttribute.MESSAGING_DESTINATION_KIND]).toEqual('topic');
91-
expect(consumeSpan.attributes[MessagingAttribute.MESSAGING_RABBITMQ_ROUTING_KEY]).toEqual(queueName);
92-
expect(consumeSpan.attributes[MessagingAttribute.MESSAGING_PROTOCOL]).toEqual('AMQP');
93-
expect(consumeSpan.attributes[MessagingAttribute.MESSAGING_PROTOCOL_VERSION]).toEqual('0.9.1');
94-
expect(consumeSpan.attributes[MessagingAttribute.MESSAGING_URL]).toEqual(url);
95-
expect(consumeSpan.attributes[GeneralAttribute.NET_PEER_NAME]).toEqual('localhost');
96-
expect(consumeSpan.attributes[GeneralAttribute.NET_PEER_PORT]).toEqual(22221);
90+
expect(consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toEqual('rabbitmq');
91+
expect(consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION]).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used"
92+
expect(consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND]).toEqual(
93+
MessagingDestinationKindValues.TOPIC
94+
);
95+
expect(consumeSpan.attributes['messaging.rabbitmq.routing_key']).toEqual(queueName);
96+
expect(consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL]).toEqual('AMQP');
97+
expect(consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION]).toEqual('0.9.1');
98+
expect(consumeSpan.attributes[SemanticAttributes.MESSAGING_URL]).toEqual(url);
99+
expect(consumeSpan.attributes[SemanticAttributes.NET_PEER_NAME]).toEqual('localhost');
100+
expect(consumeSpan.attributes[SemanticAttributes.NET_PEER_PORT]).toEqual(22221);
97101

98102
// assert context propagation
99103
expect(consumeSpan.spanContext.traceId).toEqual(publishSpan.spanContext.traceId);

0 commit comments

Comments
 (0)