Skip to content

Commit 30c1c65

Browse files
trentmmaryliag
andauthored
chore(instrumentation-socket.io): update semconv usage to ATTR_ exports (#3055)
Co-authored-by: Marylia Gutierrez <[email protected]>
1 parent d68bdde commit 30c1c65

File tree

7 files changed

+144
-61
lines changed

7 files changed

+144
-61
lines changed

package-lock.json

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/instrumentation-socket.io/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
"typescript": "5.0.4"
6161
},
6262
"dependencies": {
63-
"@opentelemetry/instrumentation": "^0.205.0",
64-
"@opentelemetry/semantic-conventions": "^1.27.0"
63+
"@opentelemetry/instrumentation": "^0.205.0"
6564
},
6665
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/instrumentation-socket.io#readme"
6766
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
* 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.
43+
*
44+
* @deprecated Use MESSAGING_OPERATION_TYPE_VALUE_RECEIVE in [incubating entry-point]({@link https://github.com/open-telemetry/opentelemetry-js/blob/main/semantic-conventions/README.md#unstable-semconv}).
45+
*/
46+
export const MESSAGING_OPERATION_VALUE_RECEIVE = 'receive' as const;
47+
48+
/**
49+
* The kind of message destination.
50+
*
51+
* @deprecated Removed in semconv v1.20.0.
52+
*/
53+
export const MESSAGING_DESTINATION_KIND_VALUE_TOPIC = 'topic' as const;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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;

packages/instrumentation-socket.io/src/socket.io.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ import {
2727
isWrapped,
2828
safeExecuteInTheMiddle,
2929
} from '@opentelemetry/instrumentation';
30+
import { ATTR_MESSAGING_OPERATION, ATTR_MESSAGING_SYSTEM } from './semconv';
3031
import {
31-
SEMATTRS_MESSAGING_DESTINATION,
32-
SEMATTRS_MESSAGING_DESTINATION_KIND,
33-
SEMATTRS_MESSAGING_OPERATION,
34-
SEMATTRS_MESSAGING_SYSTEM,
35-
MESSAGINGOPERATIONVALUES_RECEIVE,
36-
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
37-
} from '@opentelemetry/semantic-conventions';
32+
ATTR_MESSAGING_DESTINATION,
33+
ATTR_MESSAGING_DESTINATION_KIND,
34+
MESSAGING_OPERATION_VALUE_RECEIVE,
35+
MESSAGING_DESTINATION_KIND_VALUE_TOPIC,
36+
} from './semconv-obsolete';
3837
import { SocketIoInstrumentationConfig } from './types';
3938
import { SocketIoInstrumentationAttributes } from './AttributeNames';
4039
/** @knipignore */
@@ -295,14 +294,13 @@ export class SocketIoInstrumentation extends InstrumentationBase<SocketIoInstrum
295294
const eventName = ev;
296295
const namespace = this.name || this.adapter?.nsp?.name;
297296
const span: Span = self.tracer.startSpan(
298-
`${MESSAGINGOPERATIONVALUES_RECEIVE} ${namespace}`,
297+
`${MESSAGING_OPERATION_VALUE_RECEIVE} ${namespace}`,
299298
{
300299
kind: SpanKind.CONSUMER,
301300
attributes: {
302-
[SEMATTRS_MESSAGING_SYSTEM]: 'socket.io',
303-
[SEMATTRS_MESSAGING_DESTINATION]: namespace,
304-
[SEMATTRS_MESSAGING_OPERATION]:
305-
MESSAGINGOPERATIONVALUES_RECEIVE,
301+
[ATTR_MESSAGING_SYSTEM]: 'socket.io',
302+
[ATTR_MESSAGING_DESTINATION]: namespace,
303+
[ATTR_MESSAGING_OPERATION]: MESSAGING_OPERATION_VALUE_RECEIVE,
306304
[SocketIoInstrumentationAttributes.SOCKET_IO_EVENT_NAME]:
307305
eventName,
308306
},
@@ -372,9 +370,9 @@ export class SocketIoInstrumentation extends InstrumentationBase<SocketIoInstrum
372370
const messagingSystem = 'socket.io';
373371
const eventName = ev;
374372
const attributes: any = {
375-
[SEMATTRS_MESSAGING_SYSTEM]: messagingSystem,
376-
[SEMATTRS_MESSAGING_DESTINATION_KIND]:
377-
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
373+
[ATTR_MESSAGING_SYSTEM]: messagingSystem,
374+
[ATTR_MESSAGING_DESTINATION_KIND]:
375+
MESSAGING_DESTINATION_KIND_VALUE_TOPIC,
378376
[SocketIoInstrumentationAttributes.SOCKET_IO_EVENT_NAME]: eventName,
379377
};
380378

@@ -387,7 +385,7 @@ export class SocketIoInstrumentation extends InstrumentationBase<SocketIoInstrum
387385
if (namespace) {
388386
attributes[SocketIoInstrumentationAttributes.SOCKET_IO_NAMESPACE] =
389387
namespace;
390-
attributes[SEMATTRS_MESSAGING_DESTINATION] = namespace;
388+
attributes[ATTR_MESSAGING_DESTINATION] = namespace;
391389
}
392390
const span = self.tracer.startSpan(`send ${namespace}`, {
393391
kind: SpanKind.PRODUCER,

packages/instrumentation-socket.io/test/socket.io.test.ts

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { ATTR_MESSAGING_SYSTEM } from '../src/semconv';
1617
import {
17-
MESSAGINGDESTINATIONKINDVALUES_TOPIC,
18-
SEMATTRS_MESSAGING_DESTINATION,
19-
SEMATTRS_MESSAGING_DESTINATION_KIND,
20-
SEMATTRS_MESSAGING_SYSTEM,
21-
} from '@opentelemetry/semantic-conventions';
18+
MESSAGING_DESTINATION_KIND_VALUE_TOPIC,
19+
ATTR_MESSAGING_DESTINATION,
20+
ATTR_MESSAGING_DESTINATION_KIND,
21+
} from '../src/semconv-obsolete';
2222
import {
2323
SocketIoInstrumentation,
2424
SocketIoInstrumentationAttributes,
@@ -59,9 +59,9 @@ describe('SocketIoInstrumentation', () => {
5959
io.emit('test');
6060
expectSpan('send /', span => {
6161
expect(span.kind).toEqual(SpanKind.PRODUCER);
62-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('socket.io');
63-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual(
64-
MESSAGINGDESTINATIONKINDVALUES_TOPIC
62+
expect(span.attributes[ATTR_MESSAGING_SYSTEM]).toEqual('socket.io');
63+
expect(span.attributes[ATTR_MESSAGING_DESTINATION_KIND]).toEqual(
64+
MESSAGING_DESTINATION_KIND_VALUE_TOPIC
6565
);
6666
});
6767
});
@@ -90,9 +90,7 @@ describe('SocketIoInstrumentation', () => {
9090
// only for v2: connect do not throw, but are just ignored
9191
return expectSpan('send /', span => {
9292
expect(span.kind).toEqual(SpanKind.PRODUCER);
93-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
94-
'socket.io'
95-
);
93+
expect(span.attributes[ATTR_MESSAGING_SYSTEM]).toEqual('socket.io');
9694
});
9795
}
9896
expectSpan('send /', span => {
@@ -108,9 +106,9 @@ describe('SocketIoInstrumentation', () => {
108106
io.send('test');
109107
expectSpan('send /', span => {
110108
expect(span.kind).toEqual(SpanKind.PRODUCER);
111-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('socket.io');
112-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual(
113-
MESSAGINGDESTINATIONKINDVALUES_TOPIC
109+
expect(span.attributes[ATTR_MESSAGING_SYSTEM]).toEqual('socket.io');
110+
expect(span.attributes[ATTR_MESSAGING_DESTINATION_KIND]).toEqual(
111+
MESSAGING_DESTINATION_KIND_VALUE_TOPIC
114112
);
115113
});
116114
});
@@ -173,13 +171,13 @@ describe('SocketIoInstrumentation', () => {
173171
spans => {
174172
try {
175173
expect(spans[0].kind).toEqual(SpanKind.CONSUMER);
176-
expect(
177-
spans[0].attributes[SEMATTRS_MESSAGING_SYSTEM]
178-
).toEqual('socket.io');
174+
expect(spans[0].attributes[ATTR_MESSAGING_SYSTEM]).toEqual(
175+
'socket.io'
176+
);
179177
expect(spans[1].kind).toEqual(SpanKind.CONSUMER);
180-
expect(
181-
spans[1].attributes[SEMATTRS_MESSAGING_SYSTEM]
182-
).toEqual('socket.io');
178+
expect(spans[1].attributes[ATTR_MESSAGING_SYSTEM]).toEqual(
179+
'socket.io'
180+
);
183181
expect(spans[1].attributes['payload']).toEqual(
184182
JSON.stringify([data])
185183
);
@@ -215,7 +213,7 @@ describe('SocketIoInstrumentation', () => {
215213
setTimeout(() => {
216214
expectSpan('receive /', span => {
217215
expect(span.kind).toEqual(SpanKind.CONSUMER);
218-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
216+
expect(span.attributes[ATTR_MESSAGING_SYSTEM]).toEqual(
219217
'socket.io'
220218
);
221219
client.close();
@@ -248,7 +246,7 @@ describe('SocketIoInstrumentation', () => {
248246
span => {
249247
try {
250248
expect(span.kind).toEqual(SpanKind.CONSUMER);
251-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
249+
expect(span.attributes[ATTR_MESSAGING_SYSTEM]).toEqual(
252250
'socket.io'
253251
);
254252
done();
@@ -298,7 +296,7 @@ describe('SocketIoInstrumentation', () => {
298296
const sio = createServerInstance();
299297
sio.to(roomName).emit('broadcast', '1234');
300298
expectSpan('send /', span => {
301-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual('/');
299+
expect(span.attributes[ATTR_MESSAGING_DESTINATION]).toEqual('/');
302300
expect(
303301
span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_ROOMS]
304302
).toEqual([roomName]);
@@ -309,7 +307,7 @@ describe('SocketIoInstrumentation', () => {
309307
const sio = createServerInstance();
310308
sio.to('room1').to('room2').emit('broadcast', '1234');
311309
expectSpan('send /', span => {
312-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual('/');
310+
expect(span.attributes[ATTR_MESSAGING_DESTINATION]).toEqual('/');
313311
expect(
314312
span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_ROOMS]
315313
).toEqual(['room1', 'room2']);
@@ -323,9 +321,7 @@ describe('SocketIoInstrumentation', () => {
323321
const namespace = io.of('/testing');
324322
namespace.emit('namespace');
325323
expectSpan('send /testing', span => {
326-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
327-
'/testing'
328-
);
324+
expect(span.attributes[ATTR_MESSAGING_DESTINATION]).toEqual('/testing');
329325
expect(
330326
span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_NAMESPACE]
331327
).toEqual('/testing');
@@ -338,9 +334,7 @@ describe('SocketIoInstrumentation', () => {
338334
const namespace = io.of('/testing');
339335
namespace.to(roomName).emit('broadcast', '1234');
340336
expectSpan('send /testing', span => {
341-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
342-
'/testing'
343-
);
337+
expect(span.attributes[ATTR_MESSAGING_DESTINATION]).toEqual('/testing');
344338
expect(
345339
span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_ROOMS]
346340
).toEqual([roomName]);
@@ -355,9 +349,7 @@ describe('SocketIoInstrumentation', () => {
355349
const namespace = io.of('/testing');
356350
namespace.to('room1').to('room2').emit('broadcast', '1234');
357351
expectSpan('send /testing', span => {
358-
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
359-
'/testing'
360-
);
352+
expect(span.attributes[ATTR_MESSAGING_DESTINATION]).toEqual('/testing');
361353
expect(
362354
span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_NAMESPACE]
363355
).toEqual('/testing');
@@ -389,12 +381,12 @@ describe('SocketIoInstrumentation', () => {
389381
span => {
390382
try {
391383
expect(span.kind).toEqual(SpanKind.CONSUMER);
392-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
384+
expect(span.attributes[ATTR_MESSAGING_SYSTEM]).toEqual(
393385
'socket.io'
394386
);
395-
expect(
396-
span.attributes[SEMATTRS_MESSAGING_DESTINATION]
397-
).toEqual('/testing');
387+
expect(span.attributes[ATTR_MESSAGING_DESTINATION]).toEqual(
388+
'/testing'
389+
);
398390
done();
399391
} catch (e) {
400392
done(e);
@@ -431,7 +423,7 @@ describe('SocketIoInstrumentation', () => {
431423
span => {
432424
try {
433425
expect(span.kind).toEqual(SpanKind.PRODUCER);
434-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
426+
expect(span.attributes[ATTR_MESSAGING_SYSTEM]).toEqual(
435427
'socket.io'
436428
);
437429
done();

packages/instrumentation-socket.io/test/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { strict as assert } from 'assert';
1717
import * as http from 'http';
1818
import { AddressInfo } from 'net';
1919

20-
import { SEMATTRS_MESSAGING_SYSTEM } from '@opentelemetry/semantic-conventions';
20+
import { ATTR_MESSAGING_SYSTEM } from '../src/semconv';
2121
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
2222
import { getTestSpans } from '@opentelemetry/contrib-test-utils';
2323

@@ -57,7 +57,7 @@ export const createServerInstance = (server?: http.Server) => {
5757

5858
export const getSocketIoSpans = (): ReadableSpan[] =>
5959
getTestSpans().filter(
60-
s => s.attributes[SEMATTRS_MESSAGING_SYSTEM] === 'socket.io'
60+
s => s.attributes[ATTR_MESSAGING_SYSTEM] === 'socket.io'
6161
) as ReadableSpan[];
6262

6363
export const expectSpan = (

0 commit comments

Comments
 (0)