From 56392f4097dd2632de3275782f4ff49c91c552b7 Mon Sep 17 00:00:00 2001 From: David Luna Date: Mon, 29 Apr 2024 07:36:22 +0200 Subject: [PATCH 1/7] refactor(instr-socket.io): use exported strings for attributes (#2147) * refactor(instr-socket.io): use exported strings for attributes * chore(instr-socket.io): fix lint issues * fix(instr-socket.io): fix missing entries in package-lock.json * fix(instr-socket.io): fix bad entry in package.json --- package-lock.json | 4 +- .../node/instrumentation-socket.io/README.md | 13 +++ .../instrumentation-socket.io/package.json | 2 +- .../src/socket.io.ts | 27 +++--- .../test/socket.io.test.ts | 82 +++++++++---------- 5 files changed, 69 insertions(+), 59 deletions(-) diff --git a/package-lock.json b/package-lock.json index b30e3664a6..4663055e9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37112,7 +37112,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -46987,7 +46987,7 @@ "@opentelemetry/contrib-test-utils": "^0.39.0", "@opentelemetry/instrumentation": "^0.51.0", "@opentelemetry/sdk-trace-base": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "8.2.3", "@types/node": "18.6.5", "expect": "27.4.2", diff --git a/plugins/node/instrumentation-socket.io/README.md b/plugins/node/instrumentation-socket.io/README.md index ca242046f9..28370b58f2 100644 --- a/plugins/node/instrumentation-socket.io/README.md +++ b/plugins/node/instrumentation-socket.io/README.md @@ -59,6 +59,19 @@ Few breaking changes were made during porting to the contrib repo: The instrumentation's config `filterHttpTransport` option was removed to decouple this instrumentation from the http instrumentation. if you do not want to trace the socket.io http requests, add the default socket.io route (`/socket.io/`) to the `HttpInstrumentationConfig.ignoreIncomingPaths` array +## Semantic Conventions + +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) + +Attributes collected: + +| Attribute | Short Description | +| ---------------------------- | ------------------------------------------------------------------------------------------------ | +| `messaging.destination` | The message destination name. This might be equal to the span name but is required nevertheless. | +| `messaging.destination_kind` | The kind of message destination. | +| `messaging.operation` | A string identifying the kind of message consumption. | +| `messaging.system` | A string identifying the messaging system. | + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/plugins/node/instrumentation-socket.io/package.json b/plugins/node/instrumentation-socket.io/package.json index 45557a81e4..7ec6a4e6b2 100644 --- a/plugins/node/instrumentation-socket.io/package.json +++ b/plugins/node/instrumentation-socket.io/package.json @@ -59,7 +59,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-socket.io#readme" } diff --git a/plugins/node/instrumentation-socket.io/src/socket.io.ts b/plugins/node/instrumentation-socket.io/src/socket.io.ts index 51c3d1d962..5ed289c65b 100644 --- a/plugins/node/instrumentation-socket.io/src/socket.io.ts +++ b/plugins/node/instrumentation-socket.io/src/socket.io.ts @@ -28,9 +28,12 @@ import { safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; import { - SemanticAttributes, - MessagingOperationValues, - MessagingDestinationKindValues, + SEMATTRS_MESSAGING_DESTINATION, + SEMATTRS_MESSAGING_DESTINATION_KIND, + SEMATTRS_MESSAGING_OPERATION, + SEMATTRS_MESSAGING_SYSTEM, + MESSAGINGOPERATIONVALUES_RECEIVE, + MESSAGINGDESTINATIONKINDVALUES_TOPIC, } from '@opentelemetry/semantic-conventions'; import { SocketIoInstrumentationConfig } from './types'; import { SocketIoInstrumentationAttributes } from './AttributeNames'; @@ -302,14 +305,14 @@ export class SocketIoInstrumentation extends InstrumentationBase { ? eventName : `${namespace} ${eventName}`; const span: Span = self.tracer.startSpan( - `${destination} ${MessagingOperationValues.RECEIVE}`, + `${destination} ${MESSAGINGOPERATIONVALUES_RECEIVE}`, { kind: SpanKind.CONSUMER, attributes: { - [SemanticAttributes.MESSAGING_SYSTEM]: 'socket.io', - [SemanticAttributes.MESSAGING_DESTINATION]: namespace, - [SemanticAttributes.MESSAGING_OPERATION]: - MessagingOperationValues.RECEIVE, + [SEMATTRS_MESSAGING_SYSTEM]: 'socket.io', + [SEMATTRS_MESSAGING_DESTINATION]: namespace, + [SEMATTRS_MESSAGING_OPERATION]: + MESSAGINGOPERATIONVALUES_RECEIVE, [SocketIoInstrumentationAttributes.SOCKET_IO_EVENT_NAME]: eventName, }, @@ -379,9 +382,9 @@ export class SocketIoInstrumentation extends InstrumentationBase { const messagingSystem = 'socket.io'; const eventName = ev; const attributes: any = { - [SemanticAttributes.MESSAGING_SYSTEM]: messagingSystem, - [SemanticAttributes.MESSAGING_DESTINATION_KIND]: - MessagingDestinationKindValues.TOPIC, + [SEMATTRS_MESSAGING_SYSTEM]: messagingSystem, + [SEMATTRS_MESSAGING_DESTINATION_KIND]: + MESSAGINGDESTINATIONKINDVALUES_TOPIC, [SocketIoInstrumentationAttributes.SOCKET_IO_EVENT_NAME]: eventName, }; @@ -394,7 +397,7 @@ export class SocketIoInstrumentation extends InstrumentationBase { if (namespace) { attributes[SocketIoInstrumentationAttributes.SOCKET_IO_NAMESPACE] = namespace; - attributes[SemanticAttributes.MESSAGING_DESTINATION] = namespace; + attributes[SEMATTRS_MESSAGING_DESTINATION] = namespace; } const spanRooms = rooms.length ? `[${rooms.join()}]` : ''; const span = self.tracer.startSpan(`${namespace}${spanRooms} send`, { diff --git a/plugins/node/instrumentation-socket.io/test/socket.io.test.ts b/plugins/node/instrumentation-socket.io/test/socket.io.test.ts index 1b47fd5d73..0b733a438c 100644 --- a/plugins/node/instrumentation-socket.io/test/socket.io.test.ts +++ b/plugins/node/instrumentation-socket.io/test/socket.io.test.ts @@ -14,8 +14,10 @@ * limitations under the License. */ import { - MessagingDestinationKindValues, - SemanticAttributes, + MESSAGINGDESTINATIONKINDVALUES_TOPIC, + SEMATTRS_MESSAGING_DESTINATION, + SEMATTRS_MESSAGING_DESTINATION_KIND, + SEMATTRS_MESSAGING_SYSTEM, } from '@opentelemetry/semantic-conventions'; import { SocketIoInstrumentation, @@ -56,12 +58,10 @@ describe('SocketIoInstrumentation', () => { io.emit('test'); expectSpan('/ send', span => { expect(span.kind).toEqual(SpanKind.PRODUCER); - expect(span.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toEqual( - 'socket.io' + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('socket.io'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual( + MESSAGINGDESTINATIONKINDVALUES_TOPIC ); - expect( - span.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); }); }); @@ -89,7 +89,7 @@ describe('SocketIoInstrumentation', () => { // only for v2: connect do not throw, but are just ignored return expectSpan('/ send', span => { expect(span.kind).toEqual(SpanKind.PRODUCER); - expect(span.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toEqual( + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( 'socket.io' ); }); @@ -107,12 +107,10 @@ describe('SocketIoInstrumentation', () => { io.send('test'); expectSpan('/ send', span => { expect(span.kind).toEqual(SpanKind.PRODUCER); - expect(span.attributes[SemanticAttributes.MESSAGING_SYSTEM]).toEqual( - 'socket.io' + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('socket.io'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual( + MESSAGINGDESTINATIONKINDVALUES_TOPIC ); - expect( - span.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); }); }); @@ -173,9 +171,9 @@ describe('SocketIoInstrumentation', () => { span => { try { expect(span.kind).toEqual(SpanKind.CONSUMER); - expect( - span.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('socket.io'); + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'socket.io' + ); expect(span.attributes['payload']).toEqual( JSON.stringify([data]) ); @@ -213,9 +211,9 @@ describe('SocketIoInstrumentation', () => { setTimeout(() => { expectSpan('connection receive', span => { expect(span.kind).toEqual(SpanKind.CONSUMER); - expect( - span.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('socket.io'); + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'socket.io' + ); done(); }); }); @@ -244,9 +242,9 @@ describe('SocketIoInstrumentation', () => { span => { try { expect(span.kind).toEqual(SpanKind.CONSUMER); - expect( - span.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('socket.io'); + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'socket.io' + ); done(); } catch (e) { done(e); @@ -294,9 +292,7 @@ describe('SocketIoInstrumentation', () => { const sio = createServerInstance(); sio.to(roomName).emit('broadcast', '1234'); expectSpan('/[room] send', span => { - expect( - span.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual('/'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual('/'); expect( span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_ROOMS] ).toEqual([roomName]); @@ -307,9 +303,7 @@ describe('SocketIoInstrumentation', () => { const sio = createServerInstance(); sio.to('room1').to('room2').emit('broadcast', '1234'); expectSpan('/[room1,room2] send', span => { - expect( - span.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual('/'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual('/'); expect( span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_ROOMS] ).toEqual(['room1', 'room2']); @@ -323,9 +317,9 @@ describe('SocketIoInstrumentation', () => { const namespace = io.of('/testing'); namespace.emit('namespace'); expectSpan('/testing send', span => { - expect( - span.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual('/testing'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '/testing' + ); expect( span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_NAMESPACE] ).toEqual('/testing'); @@ -338,9 +332,9 @@ describe('SocketIoInstrumentation', () => { const namespace = io.of('/testing'); namespace.to(roomName).emit('broadcast', '1234'); expectSpan('/testing[room] send', span => { - expect( - span.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual('/testing'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '/testing' + ); expect( span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_ROOMS] ).toEqual([roomName]); @@ -355,9 +349,9 @@ describe('SocketIoInstrumentation', () => { const namespace = io.of('/testing'); namespace.to('room1').to('room2').emit('broadcast', '1234'); expectSpan('/testing[room1,room2] send', span => { - expect( - span.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual('/testing'); + expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '/testing' + ); expect( span.attributes[SocketIoInstrumentationAttributes.SOCKET_IO_NAMESPACE] ).toEqual('/testing'); @@ -389,11 +383,11 @@ describe('SocketIoInstrumentation', () => { span => { try { expect(span.kind).toEqual(SpanKind.CONSUMER); + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'socket.io' + ); expect( - span.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('socket.io'); - expect( - span.attributes[SemanticAttributes.MESSAGING_DESTINATION] + span.attributes[SEMATTRS_MESSAGING_DESTINATION] ).toEqual('/testing'); done(); } catch (e) { @@ -431,9 +425,9 @@ describe('SocketIoInstrumentation', () => { span => { try { expect(span.kind).toEqual(SpanKind.PRODUCER); - expect( - span.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('socket.io'); + expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'socket.io' + ); done(); } catch (e) { done(e); From b40926e9686598a991ed1ca0c4fdf034ae07bec6 Mon Sep 17 00:00:00 2001 From: David Luna Date: Mon, 29 Apr 2024 07:55:19 +0200 Subject: [PATCH 2/7] refactor(instr-tedious): use exported strings for attributes (#2144) Co-authored-by: Amir Blum --- package-lock.json | 4 +- .../node/instrumentation-tedious/README.md | 16 ++++++++ .../node/instrumentation-tedious/package.json | 2 +- .../src/instrumentation.ts | 24 ++++++----- .../test/instrumentation.test.ts | 40 ++++++++----------- 5 files changed, 51 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4663055e9d..3ec369f264 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37361,7 +37361,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/tedious": "^4.0.10" }, "devDependencies": { @@ -47180,7 +47180,7 @@ "@opentelemetry/contrib-test-utils": "^0.39.0", "@opentelemetry/instrumentation": "^0.51.0", "@opentelemetry/sdk-trace-base": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "7.0.2", "@types/node": "18.6.5", "@types/tedious": "^4.0.10", diff --git a/plugins/node/instrumentation-tedious/README.md b/plugins/node/instrumentation-tedious/README.md index ee8a9ee535..48863d1a3c 100644 --- a/plugins/node/instrumentation-tedious/README.md +++ b/plugins/node/instrumentation-tedious/README.md @@ -40,6 +40,22 @@ registerInstrumentations({ }) ``` +## Semantic Conventions + +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) + +Attributes collected: + +| Attribute | Short Description | +| ----------------------- | ------------------------------------------------------------------------------ | +| `db.name` | This attribute is used to report the name of the database being accessed. | +| `db.sql.table` | The name of the primary table that the operation is acting upon. | +| `db.statement` | The database statement being executed. | +| `db.system` | An identifier for the database management system (DBMS) product being used. | +| `db.user` | Username for accessing the database. | +| `net.peer.name` | Remote hostname or similar. | +| `net.peer.port` | Remote port number. | + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/plugins/node/instrumentation-tedious/package.json b/plugins/node/instrumentation-tedious/package.json index c123a3a90b..8d2948bf55 100644 --- a/plugins/node/instrumentation-tedious/package.json +++ b/plugins/node/instrumentation-tedious/package.json @@ -63,7 +63,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/tedious": "^4.0.10" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-tedious#readme" diff --git a/plugins/node/instrumentation-tedious/src/instrumentation.ts b/plugins/node/instrumentation-tedious/src/instrumentation.ts index d9c23eeb86..24935a32c3 100644 --- a/plugins/node/instrumentation-tedious/src/instrumentation.ts +++ b/plugins/node/instrumentation-tedious/src/instrumentation.ts @@ -22,8 +22,14 @@ import { isWrapped, } from '@opentelemetry/instrumentation'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MSSQL, + SEMATTRS_DB_NAME, + SEMATTRS_DB_SQL_TABLE, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import type * as tedious from 'tedious'; import { TediousInstrumentationConfig } from './types'; @@ -155,16 +161,16 @@ export class TediousInstrumentation extends InstrumentationBase { { kind: api.SpanKind.CLIENT, attributes: { - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MSSQL, - [SemanticAttributes.DB_NAME]: databaseName, - [SemanticAttributes.NET_PEER_PORT]: this.config?.options?.port, - [SemanticAttributes.NET_PEER_NAME]: this.config?.server, + [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MSSQL, + [SEMATTRS_DB_NAME]: databaseName, + [SEMATTRS_NET_PEER_PORT]: this.config?.options?.port, + [SEMATTRS_NET_PEER_NAME]: this.config?.server, // >=4 uses `authentication` object, older versions just userName and password pair - [SemanticAttributes.DB_USER]: + [SEMATTRS_DB_USER]: this.config?.userName ?? this.config?.authentication?.options?.userName, - [SemanticAttributes.DB_STATEMENT]: sql, - [SemanticAttributes.DB_SQL_TABLE]: request.table, + [SEMATTRS_DB_STATEMENT]: sql, + [SEMATTRS_DB_SQL_TABLE]: request.table, }, } ); diff --git a/plugins/node/instrumentation-tedious/test/instrumentation.test.ts b/plugins/node/instrumentation-tedious/test/instrumentation.test.ts index 9313281838..5a531e2815 100644 --- a/plugins/node/instrumentation-tedious/test/instrumentation.test.ts +++ b/plugins/node/instrumentation-tedious/test/instrumentation.test.ts @@ -17,8 +17,14 @@ import { context, trace, SpanStatusCode, SpanKind } from '@opentelemetry/api'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MSSQL, + SEMATTRS_DB_NAME, + SEMATTRS_DB_SQL_TABLE, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import * as util from 'util'; import * as testUtils from '@opentelemetry/contrib-test-utils'; @@ -335,17 +341,14 @@ function assertSpan(span: ReadableSpan, expected: any) { assert(span); assert.strictEqual(span.name, expected.name); assert.strictEqual(span.kind, SpanKind.CLIENT); + assert.strictEqual(span.attributes[SEMATTRS_DB_SYSTEM], DBSYSTEMVALUES_MSSQL); assert.strictEqual( - span.attributes[SemanticAttributes.DB_SYSTEM], - DbSystemValues.MSSQL - ); - assert.strictEqual( - span.attributes[SemanticAttributes.DB_NAME], + span.attributes[SEMATTRS_DB_NAME], expected.database ?? database ); - assert.strictEqual(span.attributes[SemanticAttributes.NET_PEER_PORT], port); - assert.strictEqual(span.attributes[SemanticAttributes.NET_PEER_NAME], host); - assert.strictEqual(span.attributes[SemanticAttributes.DB_USER], user); + assert.strictEqual(span.attributes[SEMATTRS_NET_PEER_PORT], port); + assert.strictEqual(span.attributes[SEMATTRS_NET_PEER_NAME], host); + assert.strictEqual(span.attributes[SEMATTRS_DB_USER], user); assert.strictEqual( span.attributes['tedious.procedure_count'], expected.procCount ?? 1, @@ -362,27 +365,18 @@ function assertSpan(span: ReadableSpan, expected: any) { expected.parentSpan.spanContext().spanId ); } - assert.strictEqual( - span.attributes[SemanticAttributes.DB_SQL_TABLE], - expected.table - ); + assert.strictEqual(span.attributes[SEMATTRS_DB_SQL_TABLE], expected.table); if (expected.sql) { if (expected.sql instanceof RegExp) { assertMatch( - span.attributes[SemanticAttributes.DB_STATEMENT] as string | undefined, + span.attributes[SEMATTRS_DB_STATEMENT] as string | undefined, expected.sql ); } else { - assert.strictEqual( - span.attributes[SemanticAttributes.DB_STATEMENT], - expected.sql - ); + assert.strictEqual(span.attributes[SEMATTRS_DB_STATEMENT], expected.sql); } } else { - assert.strictEqual( - span.attributes[SemanticAttributes.DB_STATEMENT], - undefined - ); + assert.strictEqual(span.attributes[SEMATTRS_DB_STATEMENT], undefined); } if (expected.error) { assert( From 2d07c1858bad8461dd7bd411e56f6305664ca331 Mon Sep 17 00:00:00 2001 From: David Luna Date: Mon, 29 Apr 2024 08:12:46 +0200 Subject: [PATCH 3/7] fix(instr-knex): set correct SpanKind for traces (#2157) Co-authored-by: Amir Blum --- .../opentelemetry-instrumentation-knex/src/instrumentation.ts | 1 + .../node/opentelemetry-instrumentation-knex/test/index.test.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts index ce45403efc..40577aa886 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts @@ -160,6 +160,7 @@ export class KnexInstrumentation extends InstrumentationBase { const span = instrumentation.tracer.startSpan( utils.getName(name, operation, table), { + kind: api.SpanKind.CLIENT, attributes, }, parent diff --git a/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts index 1f660cf273..9072465c47 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/test/index.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { context, trace } from '@opentelemetry/api'; +import { SpanKind, context, trace } from '@opentelemetry/api'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { @@ -471,6 +471,7 @@ const assertSpans = (actualSpans: any[], expectedSpans: any[]) => { try { assert.notStrictEqual(span, undefined); assert.notStrictEqual(expected, undefined); + assert.strictEqual(span.kind, SpanKind.CLIENT); assertMatch(span.name, new RegExp(expected.op)); assertMatch(span.name, new RegExp(':memory:')); assert.strictEqual(span.attributes['db.system'], 'sqlite'); From 49d77cede61188f71f75459eb1ff9c84e4cc3abf Mon Sep 17 00:00:00 2001 From: David Luna Date: Mon, 29 Apr 2024 09:23:58 +0200 Subject: [PATCH 4/7] refactor(instr-cucumber): use exported strings for attributes (#2143) Co-authored-by: Amir Blum --- package-lock.json | 4 ++-- .../node/instrumentation-cucumber/README.md | 13 +++++++++++++ .../instrumentation-cucumber/package.json | 2 +- .../src/instrumentation.ts | 15 ++++++++++----- .../test/cucumber.test.ts | 19 ++++++++++++------- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3ec369f264..dd02d74395 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36873,7 +36873,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { "@cucumber/cucumber": "^9.0.0", @@ -45940,7 +45940,7 @@ "@opentelemetry/instrumentation": "^0.51.0", "@opentelemetry/sdk-trace-base": "^1.3.1", "@opentelemetry/sdk-trace-node": "^1.3.1", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mocha": "7.0.2", "@types/semver": "7.5.3", "@types/shimmer": "1.0.3", diff --git a/plugins/node/instrumentation-cucumber/README.md b/plugins/node/instrumentation-cucumber/README.md index c3fd434353..acc5466c36 100644 --- a/plugins/node/instrumentation-cucumber/README.md +++ b/plugins/node/instrumentation-cucumber/README.md @@ -43,6 +43,19 @@ Cucumber instrumentation has currently no options. | Options | Type | Description | | ------- | ---- | ----------- | +## Semantic Conventions + +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) + +Attributes collected: + +| Attribute | Short Description | +| ---------------- | -------------------------------------------------------------------------------- | +| `code.filepath` | The source code file name that identifies the code unit as uniquely as possible. | +| `code.function` | The method or function name, or equivalent. | +| `code.lineno` | The line number in `code.filepath` best representing the operation. | +| `code.namespace` | The "namespace" within which `code.function` is defined. | + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/plugins/node/instrumentation-cucumber/package.json b/plugins/node/instrumentation-cucumber/package.json index 76c0e259aa..ee4b117fd0 100644 --- a/plugins/node/instrumentation-cucumber/package.json +++ b/plugins/node/instrumentation-cucumber/package.json @@ -63,7 +63,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.22.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-cucumber#readme" } diff --git a/plugins/node/instrumentation-cucumber/src/instrumentation.ts b/plugins/node/instrumentation-cucumber/src/instrumentation.ts index 29e466cb69..255b2a297c 100644 --- a/plugins/node/instrumentation-cucumber/src/instrumentation.ts +++ b/plugins/node/instrumentation-cucumber/src/instrumentation.ts @@ -21,7 +21,12 @@ import { InstrumentationNodeModuleFile, isWrapped, } from '@opentelemetry/instrumentation'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_CODE_FILEPATH, + SEMATTRS_CODE_FUNCTION, + SEMATTRS_CODE_LINENO, + SEMATTRS_CODE_NAMESPACE, +} from '@opentelemetry/semantic-conventions'; import type * as cucumber from '@cucumber/cucumber'; import type * as messages from '@cucumber/messages'; @@ -174,10 +179,10 @@ export class CucumberInstrumentation extends InstrumentationBase { { kind: SpanKind.CLIENT, attributes: { - [SemanticAttributes.CODE_FILEPATH]: gherkinDocument.uri, - [SemanticAttributes.CODE_LINENO]: scenario.location.line, - [SemanticAttributes.CODE_FUNCTION]: scenario.name, - [SemanticAttributes.CODE_NAMESPACE]: feature.name, + [SEMATTRS_CODE_FILEPATH]: gherkinDocument.uri, + [SEMATTRS_CODE_LINENO]: scenario.location.line, + [SEMATTRS_CODE_FUNCTION]: scenario.name, + [SEMATTRS_CODE_NAMESPACE]: feature.name, [AttributeNames.FEATURE_TAGS]: CucumberInstrumentation.mapTags( feature.tags ), diff --git a/plugins/node/instrumentation-cucumber/test/cucumber.test.ts b/plugins/node/instrumentation-cucumber/test/cucumber.test.ts index 87679cb7bd..deffbef31d 100644 --- a/plugins/node/instrumentation-cucumber/test/cucumber.test.ts +++ b/plugins/node/instrumentation-cucumber/test/cucumber.test.ts @@ -21,9 +21,14 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/sdk-trace-base'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_CODE_FILEPATH, + SEMATTRS_CODE_FUNCTION, + SEMATTRS_CODE_LINENO, + SEMATTRS_CODE_NAMESPACE, + SEMRESATTRS_SERVICE_NAME, +} from '@opentelemetry/semantic-conventions'; import { Resource } from '@opentelemetry/resources'; -import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import * as path from 'path'; import * as assert from 'assert'; @@ -50,7 +55,7 @@ import { PassThrough } from 'stream'; describe('CucumberInstrumentation', () => { const provider = new NodeTracerProvider({ resource: new Resource({ - [SemanticResourceAttributes.SERVICE_NAME]: 'CucumberInstrumentation', + [SEMRESATTRS_SERVICE_NAME]: 'CucumberInstrumentation', }), }); const memoryExporter = new InMemorySpanExporter(); @@ -165,10 +170,10 @@ describe('CucumberInstrumentation', () => { assert(parent, 'Expected a parent span'); assert.deepEqual(parent.attributes, { - [SemanticAttributes.CODE_FILEPATH]: 'test/current.feature', - [SemanticAttributes.CODE_LINENO]: 7, - [SemanticAttributes.CODE_FUNCTION]: 'Button pushing', - [SemanticAttributes.CODE_NAMESPACE]: 'Basic', + [SEMATTRS_CODE_FILEPATH]: 'test/current.feature', + [SEMATTRS_CODE_LINENO]: 7, + [SEMATTRS_CODE_FUNCTION]: 'Button pushing', + [SEMATTRS_CODE_NAMESPACE]: 'Basic', [AttributeNames.FEATURE_DESCRIPTION]: ' A very basic feature file with a single scenario', [AttributeNames.FEATURE_LANGUAGE]: 'en', From 86d143aef90f8381a4eb51e1fca70d8114d2e4b9 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Mon, 29 Apr 2024 09:44:31 +0200 Subject: [PATCH 5/7] chore(deps): update dependency @fastify/express to v3 (#2117) --- package-lock.json | 16 ++++++++-------- .../package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index dd02d74395..89f33d1864 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5122,9 +5122,9 @@ "dev": true }, "node_modules/@fastify/express": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@fastify/express/-/express-2.3.0.tgz", - "integrity": "sha512-jvvjlPPCfJsSHfF6tQDyARJ3+c3xXiqcxVZu6bi3xMWCWB3fl07vrjFDeaqnwqKhLZ9+m6cog5dw7gIMKEsTnQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@fastify/express/-/express-3.0.0.tgz", + "integrity": "sha512-Ug6aulXCUiHgMyrHVYQqnQbGdsAV0aTad6nZxbOr6w3QjKn1mdQS3Kyzvc+I0xMjZ9yIyMUWHSooHgZ0l7nOng==", "dev": true, "dependencies": { "express": "^4.17.1", @@ -37691,7 +37691,7 @@ "@opentelemetry/semantic-conventions": "^1.22.0" }, "devDependencies": { - "@fastify/express": "^2.0.2", + "@fastify/express": "^3.0.0", "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/contrib-test-utils": "^0.39.0", @@ -43079,9 +43079,9 @@ "dev": true }, "@fastify/express": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@fastify/express/-/express-2.3.0.tgz", - "integrity": "sha512-jvvjlPPCfJsSHfF6tQDyARJ3+c3xXiqcxVZu6bi3xMWCWB3fl07vrjFDeaqnwqKhLZ9+m6cog5dw7gIMKEsTnQ==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@fastify/express/-/express-3.0.0.tgz", + "integrity": "sha512-Ug6aulXCUiHgMyrHVYQqnQbGdsAV0aTad6nZxbOr6w3QjKn1mdQS3Kyzvc+I0xMjZ9yIyMUWHSooHgZ0l7nOng==", "dev": true, "requires": { "express": "^4.17.1", @@ -46084,7 +46084,7 @@ "@opentelemetry/instrumentation-fastify": { "version": "file:plugins/node/opentelemetry-instrumentation-fastify", "requires": { - "@fastify/express": "^2.0.2", + "@fastify/express": "^3.0.0", "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/contrib-test-utils": "^0.39.0", diff --git a/plugins/node/opentelemetry-instrumentation-fastify/package.json b/plugins/node/opentelemetry-instrumentation-fastify/package.json index 4a55548d68..fe7cf44d17 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/package.json +++ b/plugins/node/opentelemetry-instrumentation-fastify/package.json @@ -43,7 +43,7 @@ "@opentelemetry/api": "^1.3.0" }, "devDependencies": { - "@fastify/express": "^2.0.2", + "@fastify/express": "^3.0.0", "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", "@opentelemetry/contrib-test-utils": "^0.39.0", From af2f3f1e5a2608900fcea721f08b2e541a17927c Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Mon, 29 Apr 2024 04:08:11 -0400 Subject: [PATCH 6/7] feat(auto-instrumentation-node): add azure detector (#2101) The Azure detectors were not being added to the list of possible detectors. All other cloud providers were possible values, so this commit adds the missing detectors for Azure. Signed-off-by: maryliag Co-authored-by: Amir Blum --- metapackages/auto-instrumentations-node/README.md | 1 + metapackages/auto-instrumentations-node/package.json | 1 + metapackages/auto-instrumentations-node/src/utils.ts | 12 +++++++++++- .../auto-instrumentations-node/test/utils.test.ts | 4 ++-- package-lock.json | 2 ++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/metapackages/auto-instrumentations-node/README.md b/metapackages/auto-instrumentations-node/README.md index dccf55a266..ba31c44d9a 100644 --- a/metapackages/auto-instrumentations-node/README.md +++ b/metapackages/auto-instrumentations-node/README.md @@ -65,6 +65,7 @@ By default, all SDK resource detectors are used, but you can use the environment - `container` - `alibaba` - `aws` +- `azure` - `gcp` - `all` - enable all resource detectors - `none` - disable resource detection diff --git a/metapackages/auto-instrumentations-node/package.json b/metapackages/auto-instrumentations-node/package.json index 47ee58c6b3..7704e11d66 100644 --- a/metapackages/auto-instrumentations-node/package.json +++ b/metapackages/auto-instrumentations-node/package.json @@ -89,6 +89,7 @@ "@opentelemetry/instrumentation-winston": "^0.37.0", "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.9", "@opentelemetry/resource-detector-aws": "^1.4.2", + "@opentelemetry/resource-detector-azure": "^0.2.6", "@opentelemetry/resource-detector-container": "^0.3.9", "@opentelemetry/resource-detector-gcp": "^0.29.9", "@opentelemetry/resources": "^1.12.0", diff --git a/metapackages/auto-instrumentations-node/src/utils.ts b/metapackages/auto-instrumentations-node/src/utils.ts index 67cfa900c8..de7d0c7026 100644 --- a/metapackages/auto-instrumentations-node/src/utils.ts +++ b/metapackages/auto-instrumentations-node/src/utils.ts @@ -73,6 +73,11 @@ import { osDetectorSync, processDetectorSync, } from '@opentelemetry/resources'; +import { + azureAppServiceDetector, + azureFunctionsDetector, + azureVmDetector, +} from '@opentelemetry/resource-detector-azure'; const RESOURCE_DETECTOR_CONTAINER = 'container'; const RESOURCE_DETECTOR_ENVIRONMENT = 'env'; @@ -81,6 +86,7 @@ const RESOURCE_DETECTOR_OS = 'os'; const RESOURCE_DETECTOR_PROCESS = 'process'; const RESOURCE_DETECTOR_ALIBABA = 'alibaba'; const RESOURCE_DETECTOR_AWS = 'aws'; +const RESOURCE_DETECTOR_AZURE = 'azure'; const RESOURCE_DETECTOR_GCP = 'gcp'; const InstrumentationMap = { @@ -196,7 +202,7 @@ function getEnabledInstrumentationsFromEnv() { export function getResourceDetectorsFromEnv(): Array { const resourceDetectors = new Map< string, - Detector | DetectorSync | Detector[] + Detector | DetectorSync | Detector[] | DetectorSync[] >([ [RESOURCE_DETECTOR_CONTAINER, containerDetector], [RESOURCE_DETECTOR_ENVIRONMENT, envDetectorSync], @@ -215,6 +221,10 @@ export function getResourceDetectorsFromEnv(): Array { awsLambdaDetector, ], ], + [ + RESOURCE_DETECTOR_AZURE, + [azureAppServiceDetector, azureFunctionsDetector, azureVmDetector], + ], ]); const resourceDetectorsFromEnv = diff --git a/metapackages/auto-instrumentations-node/test/utils.test.ts b/metapackages/auto-instrumentations-node/test/utils.test.ts index 3a04c01569..29fae3cef2 100644 --- a/metapackages/auto-instrumentations-node/test/utils.test.ts +++ b/metapackages/auto-instrumentations-node/test/utils.test.ts @@ -114,13 +114,13 @@ describe('utils', () => { describe('getResourceDetectorsFromEnv', () => { it('should return all resource detectors by default', () => { - assert.equal(getResourceDetectorsFromEnv().length, 12); + assert.equal(getResourceDetectorsFromEnv().length, 15); }); it('should return all resource detectors when OTEL_NODE_RESOURCE_DETECTORS contains "all"', () => { process.env.OTEL_NODE_RESOURCE_DETECTORS = 'all'; - assert.equal(getResourceDetectorsFromEnv().length, 12); + assert.equal(getResourceDetectorsFromEnv().length, 15); delete process.env.OTEL_NODE_RESOURCE_DETECTORS; }); diff --git a/package-lock.json b/package-lock.json index 89f33d1864..ec53fe1355 100644 --- a/package-lock.json +++ b/package-lock.json @@ -324,6 +324,7 @@ "@opentelemetry/instrumentation-winston": "^0.37.0", "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.9", "@opentelemetry/resource-detector-aws": "^1.4.2", + "@opentelemetry/resource-detector-azure": "^0.2.6", "@opentelemetry/resource-detector-container": "^0.3.9", "@opentelemetry/resource-detector-gcp": "^0.29.9", "@opentelemetry/resources": "^1.12.0", @@ -45514,6 +45515,7 @@ "@opentelemetry/instrumentation-winston": "^0.37.0", "@opentelemetry/resource-detector-alibaba-cloud": "^0.28.9", "@opentelemetry/resource-detector-aws": "^1.4.2", + "@opentelemetry/resource-detector-azure": "^0.2.6", "@opentelemetry/resource-detector-container": "^0.3.9", "@opentelemetry/resource-detector-gcp": "^0.29.9", "@opentelemetry/resources": "^1.12.0", From 3ad9fdfe1e18e597f31bb546d9b00824a7d1ffe9 Mon Sep 17 00:00:00 2001 From: Zirak Date: Mon, 29 Apr 2024 08:20:51 +0000 Subject: [PATCH 7/7] fix(instrumentation-redis): Take host and port used for connection (#2072) * fix(instrumentation-redis): Take host and port used for connection The Redis client allows specifying connection options in several ways, with sensible defaults. The following all translate into `127.0.0.1:6379`: ```js createClient('redis://127.0.0.1:6379'); createClient({ host: '127.0.0.1', port: NaN }); createClient({}) createClient() ``` Redis somewhat normalises these separate options into its `options` member, and stores the properties it uses to connect to the server in `connection_options`. Examples of the difference between the two in the examples preceding (slightly redacted for ease of reading): ```js createClient('redis://127.0.0.1:6379'); // options = { port: '6379', host: '127.0.0.1' } // connection_options = { port: 6379, host: '127.0.0.1', family: 4 } createClient({ host: '127.0.0.1', port: NaN }); // options = { host: '127.0.0.1', port: NaN } // connection_options = { port: 6379, host: '127.0.0.1', family: 4 } createClient() // options = { host: undefined } // connection_options = { port: 6379, host: '127.0.0.1', family: 4 } ``` The instrumentation before this commit looks at the `options` property, which contains caller-supplied values before they're fully normalised and smoothed over by Redis. This means that for these weird cases, the instrumentation would populate `NET_PEER_NAME` and `NET_PEER_PORT` with erroneous values. This commit has the instrumentation the values the Redis client uses to connect to the server, mirroring actual use. * test(instrumentation-redis): Explicitly expect for a numeric port --------- Co-authored-by: Amir Blum --- .../src/internal-types.ts | 6 +++--- .../node/opentelemetry-instrumentation-redis/src/utils.ts | 6 +++--- .../opentelemetry-instrumentation-redis/test/redis.test.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-redis/src/internal-types.ts b/plugins/node/opentelemetry-instrumentation-redis/src/internal-types.ts index 99e2efe829..545a1927e4 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/src/internal-types.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/src/internal-types.ts @@ -14,9 +14,9 @@ * limitations under the License. */ export interface RedisPluginClientTypes { - options?: { - host: string; - port: string; + connection_options?: { + port?: string; + host?: string; }; address?: string; diff --git a/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts b/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts index fed4f769f9..d863089f30 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/src/utils.ts @@ -111,10 +111,10 @@ export const getTracedInternalSendCommand = ( ); // Set attributes for not explicitly typed RedisPluginClientTypes - if (this.options) { + if (this.connection_options) { span.setAttributes({ - [SEMATTRS_NET_PEER_NAME]: this.options.host, - [SEMATTRS_NET_PEER_PORT]: this.options.port, + [SEMATTRS_NET_PEER_NAME]: this.connection_options.host, + [SEMATTRS_NET_PEER_PORT]: this.connection_options.port, }); } if (this.address) { diff --git a/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts b/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts index 63ab337e86..13113a2f3d 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-redis/test/redis.test.ts @@ -51,7 +51,7 @@ const memoryExporter = new InMemorySpanExporter(); const CONFIG = { host: process.env.OPENTELEMETRY_REDIS_HOST || 'localhost', - port: process.env.OPENTELEMETRY_REDIS_PORT || '63790', + port: Number(process.env.OPENTELEMETRY_REDIS_PORT || 63790), }; const URL = `redis://${CONFIG.host}:${CONFIG.port}`;