From 98fac09a3897a50c7af7b28df1102a3b5770f95f Mon Sep 17 00:00:00 2001 From: David Luna Date: Fri, 19 Apr 2024 23:48:07 +0200 Subject: [PATCH 1/4] refactor(instr-mysql2): use exported strings for attributes (#2115) - Update @opentelemetry/semantic-conventions to ^1.22 - Replace SemanticAttributes.* with exported strings SEMATTRS_* - Update README with new semantic convention package version and key Refs: #2025 --- package-lock.json | 4 +- .../README.md | 16 ++++++++ .../package.json | 2 +- .../src/instrumentation.ts | 13 +++--- .../src/utils.ts | 40 +++++++++---------- .../test/mysql.test.ts | 31 +++++++------- 6 files changed, 58 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index adb9293cdf..eaf2bb882c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38231,7 +38231,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@opentelemetry/sql-common": "^0.40.0" }, "devDependencies": { @@ -46621,7 +46621,7 @@ "@opentelemetry/contrib-test-utils": "^0.38.0", "@opentelemetry/instrumentation": "^0.50.0", "@opentelemetry/sdk-trace-base": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@opentelemetry/sql-common": "^0.40.0", "@types/mocha": "7.0.2", "@types/node": "18.6.5", diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/README.md b/plugins/node/opentelemetry-instrumentation-mysql2/README.md index 04f15355ef..a0f3c73658 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/README.md +++ b/plugins/node/opentelemetry-instrumentation-mysql2/README.md @@ -49,6 +49,22 @@ You can set the following instrumentation options: | `responseHook` | `MySQL2InstrumentationExecutionResponseHook` (function) | Function for adding custom attributes from db response | | `addSqlCommenterCommentToQueries` | `boolean` | If true, adds [sqlcommenter](https://github.com/open-telemetry/opentelemetry-sqlcommenter) specification compliant comment to queries with tracing context (default false). _NOTE: A comment will not be added to queries that already contain `--` or `/* ... */` in them, even if these are not actually part of comments_ | +## 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.connection_string` | The connection string used to connect to the database. | +| `db.name` | This attribute is used to report the name of the database being accessed. | +| `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/opentelemetry-instrumentation-mysql2/package.json b/plugins/node/opentelemetry-instrumentation-mysql2/package.json index b20fb7aaf6..5d7d885d02 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql2/package.json @@ -62,7 +62,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@opentelemetry/sql-common": "^0.40.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql2#readme" diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts index ea792f8025..2d79311bcb 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts @@ -22,8 +22,9 @@ import { safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MYSQL, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, } from '@opentelemetry/semantic-conventions'; import { addSqlCommenterComment } from '@opentelemetry/sql-common'; import type * as mysqlTypes from 'mysql2'; @@ -40,7 +41,7 @@ type formatType = typeof mysqlTypes.format; export class MySQL2Instrumentation extends InstrumentationBase { static readonly COMMON_ATTRIBUTES = { - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MYSQL, + [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MYSQL, }; constructor(config?: MySQL2InstrumentationConfig) { @@ -115,11 +116,7 @@ export class MySQL2Instrumentation extends InstrumentationBase { attributes: { ...MySQL2Instrumentation.COMMON_ATTRIBUTES, ...getConnectionAttributes(this.config), - [SemanticAttributes.DB_STATEMENT]: getDbStatement( - query, - format, - values - ), + [SEMATTRS_DB_STATEMENT]: getDbStatement(query, format, values), }, }); diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts index 82333c109f..cfd9f2ef0f 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts @@ -14,8 +14,14 @@ * limitations under the License. */ -import { SpanAttributes } from '@opentelemetry/api'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { Attributes } from '@opentelemetry/api'; +import { + SEMATTRS_DB_CONNECTION_STRING, + SEMATTRS_DB_NAME, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, +} from '@opentelemetry/semantic-conventions'; /* Following types declare an expectation on mysql2 types and define a subset we @@ -42,35 +48,27 @@ interface Config { connectionConfig?: Config; } /** - * Get an SpanAttributes map from a mysql connection config object + * Get an Attributes map from a mysql connection config object * * @param config ConnectionConfig */ -export function getConnectionAttributes(config: Config): SpanAttributes { +export function getConnectionAttributes(config: Config): Attributes { const { host, port, database, user } = getConfig(config); const portNumber = parseInt(port, 10); if (!isNaN(portNumber)) { return { - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.NET_PEER_PORT]: portNumber, - [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( - host, - port, - database - ), - [SemanticAttributes.DB_NAME]: database, - [SemanticAttributes.DB_USER]: user, + [SEMATTRS_NET_PEER_NAME]: host, + [SEMATTRS_NET_PEER_PORT]: portNumber, + [SEMATTRS_DB_CONNECTION_STRING]: getJDBCString(host, port, database), + [SEMATTRS_DB_NAME]: database, + [SEMATTRS_DB_USER]: user, }; } return { - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( - host, - port, - database - ), - [SemanticAttributes.DB_NAME]: database, - [SemanticAttributes.DB_USER]: user, + [SEMATTRS_NET_PEER_NAME]: host, + [SEMATTRS_DB_CONNECTION_STRING]: getJDBCString(host, port, database), + [SEMATTRS_DB_NAME]: database, + [SEMATTRS_DB_USER]: user, }; } diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts b/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts index 4c7a4bab23..7b2bfe74ee 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/test/mysql.test.ts @@ -18,8 +18,13 @@ import * as semver from 'semver'; import { context, trace, SpanStatusCode } from '@opentelemetry/api'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MYSQL, + SEMATTRS_DB_NAME, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import * as testUtils from '@opentelemetry/contrib-test-utils'; import { @@ -177,10 +182,7 @@ describe('mysql2@2.x', () => { query.on('end', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans[0].name, 'SELECT'); - assert.strictEqual( - spans[0].attributes[SemanticAttributes.DB_STATEMENT], - sql - ); + assert.strictEqual(spans[0].attributes[SEMATTRS_DB_STATEMENT], sql); done(); }); }); @@ -198,7 +200,7 @@ describe('mysql2@2.x', () => { const spans = memoryExporter.getFinishedSpans(); assert.strictEqual(spans[0].name, 'SELECT'); assert.strictEqual( - spans[0].attributes[SemanticAttributes.DB_STATEMENT], + spans[0].attributes[SEMATTRS_DB_STATEMENT], query.sql ); done(); @@ -1215,16 +1217,13 @@ function assertSpan( values?: any, errorMessage?: string ) { + assert.strictEqual(span.attributes[SEMATTRS_DB_SYSTEM], DBSYSTEMVALUES_MYSQL); + assert.strictEqual(span.attributes[SEMATTRS_DB_NAME], database); + 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[SemanticAttributes.DB_SYSTEM], - DbSystemValues.MYSQL - ); - assert.strictEqual(span.attributes[SemanticAttributes.DB_NAME], 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[SemanticAttributes.DB_STATEMENT], + span.attributes[SEMATTRS_DB_STATEMENT], mysqlTypes.format(sql, values) ); if (errorMessage) { From a2884102f9604da9e39d3bf2547e3e5da9c15511 Mon Sep 17 00:00:00 2001 From: David Luna Date: Fri, 19 Apr 2024 23:50:07 +0200 Subject: [PATCH 2/4] refactor(instr-mysql): update semantic conventions (#2112) Refs: #2025 --- package-lock.json | 4 +- .../README.md | 17 ++++++++ .../package.json | 2 +- .../src/instrumentation.ts | 12 +++--- .../src/utils.ts | 40 +++++++++---------- .../test/index.test.ts | 24 ++++++----- 6 files changed, 57 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index eaf2bb882c..1bfd2fcf51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38198,7 +38198,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mysql": "2.15.22" }, "devDependencies": { @@ -46599,7 +46599,7 @@ "@opentelemetry/instrumentation": "^0.50.0", "@opentelemetry/sdk-metrics": "^1.8.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/mysql": "2.15.22", "@types/node": "18.6.5", diff --git a/plugins/node/opentelemetry-instrumentation-mysql/README.md b/plugins/node/opentelemetry-instrumentation-mysql/README.md index 6b86badf8e..e632521fb6 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/README.md +++ b/plugins/node/opentelemetry-instrumentation-mysql/README.md @@ -49,6 +49,23 @@ See [examples/mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/ | [`enhancedDatabaseReporting`](./src/types.ts#L24) | `boolean` | `false` | If true, an attribute containing the query's parameters will be attached the spans generated to represent the query | | +## 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.connection_string` | The connection string used to connect to the database. | +| `db.name` | This attribute is used to report the name of the database being accessed. | +| `db.operation` | The name of the operation being executed. | +| `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/opentelemetry-instrumentation-mysql/package.json b/plugins/node/opentelemetry-instrumentation-mysql/package.json index fccb9fe6ae..13d2c6d3af 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql/package.json @@ -60,7 +60,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.50.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.22.0", "@types/mysql": "2.15.22" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql#readme" diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts index 8ef20b9e2b..9ff48fd684 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts @@ -29,8 +29,9 @@ import { isWrapped, } from '@opentelemetry/instrumentation'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MYSQL, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, } from '@opentelemetry/semantic-conventions'; import type * as mysqlTypes from 'mysql'; import { AttributeNames } from './AttributeNames'; @@ -54,7 +55,7 @@ export class MySQLInstrumentation extends InstrumentationBase< typeof mysqlTypes > { static readonly COMMON_ATTRIBUTES = { - [SemanticAttributes.DB_SYSTEM]: DbSystemValues.MYSQL, + [SEMATTRS_DB_SYSTEM]: DBSYSTEMVALUES_MYSQL, }; private _connectionsUsage!: UpDownCounter; @@ -331,10 +332,7 @@ export class MySQLInstrumentation extends InstrumentationBase< }, }); - span.setAttribute( - SemanticAttributes.DB_STATEMENT, - getDbStatement(query) - ); + span.setAttribute(SEMATTRS_DB_STATEMENT, getDbStatement(query)); const instrumentationConfig: MySQLInstrumentationConfig = thisPlugin.getConfig(); diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts index 05eb1d809f..8230052d0e 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts @@ -14,8 +14,14 @@ * limitations under the License. */ -import { SpanAttributes } from '@opentelemetry/api'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { Attributes } from '@opentelemetry/api'; +import { + SEMATTRS_DB_CONNECTION_STRING, + SEMATTRS_DB_NAME, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, +} from '@opentelemetry/semantic-conventions'; import type { ConnectionConfig, PoolActualConfig, @@ -25,37 +31,29 @@ import type { import type * as mysqlTypes from 'mysql'; /** - * Get an SpanAttributes map from a mysql connection config object + * Get an Attributes map from a mysql connection config object * * @param config ConnectionConfig */ export function getConnectionAttributes( config: ConnectionConfig | PoolActualConfig -): SpanAttributes { +): Attributes { const { host, port, database, user } = getConfig(config); const portNumber = parseInt(port, 10); if (!isNaN(portNumber)) { return { - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.NET_PEER_PORT]: portNumber, - [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( - host, - port, - database - ), - [SemanticAttributes.DB_NAME]: database, - [SemanticAttributes.DB_USER]: user, + [SEMATTRS_NET_PEER_NAME]: host, + [SEMATTRS_NET_PEER_PORT]: portNumber, + [SEMATTRS_DB_CONNECTION_STRING]: getJDBCString(host, port, database), + [SEMATTRS_DB_NAME]: database, + [SEMATTRS_DB_USER]: user, }; } return { - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( - host, - port, - database - ), - [SemanticAttributes.DB_NAME]: database, - [SemanticAttributes.DB_USER]: user, + [SEMATTRS_NET_PEER_NAME]: host, + [SEMATTRS_DB_CONNECTION_STRING]: getJDBCString(host, port, database), + [SEMATTRS_DB_NAME]: database, + [SEMATTRS_DB_USER]: user, }; } diff --git a/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts b/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts index eaef649b3c..676081d47e 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/test/index.test.ts @@ -17,8 +17,13 @@ import { context, Context, trace, SpanStatusCode } from '@opentelemetry/api'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { - DbSystemValues, - SemanticAttributes, + DBSYSTEMVALUES_MYSQL, + SEMATTRS_DB_NAME, + SEMATTRS_DB_STATEMENT, + SEMATTRS_DB_SYSTEM, + SEMATTRS_DB_USER, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import * as testUtils from '@opentelemetry/contrib-test-utils'; import { @@ -868,15 +873,12 @@ function assertSpan( values?: any, errorMessage?: string ) { - assert.strictEqual( - span.attributes[SemanticAttributes.DB_SYSTEM], - DbSystemValues.MYSQL - ); - assert.strictEqual(span.attributes[SemanticAttributes.DB_NAME], 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[SemanticAttributes.DB_STATEMENT], sql); + assert.strictEqual(span.attributes[SEMATTRS_DB_SYSTEM], DBSYSTEMVALUES_MYSQL); + assert.strictEqual(span.attributes[SEMATTRS_DB_NAME], database); + 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[SEMATTRS_DB_STATEMENT], sql); if (errorMessage) { assert.strictEqual(span.status.message, errorMessage); assert.strictEqual(span.status.code, SpanStatusCode.ERROR); From 6c934c321cf2278cc48c889fb5d73a197db520e0 Mon Sep 17 00:00:00 2001 From: Jamie Danielson Date: Mon, 22 Apr 2024 02:41:49 -0400 Subject: [PATCH 3/4] ci: only publish after release is created (#2133) --- .github/workflows/release-please.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 1c58cefc06..6bf4f04da7 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -54,11 +54,15 @@ jobs: # get main again - name: Checkout Repository + # only checkout if a release has been created + if: ${{ steps.release.outputs.release_created }} uses: actions/checkout@v4 with: fetch-depth: 0 - name: Rebuild Packages + # only rebuild if a release has been created + if: ${{ steps.release.outputs.release_created }} run: | npm ci npm run compile @@ -67,6 +71,8 @@ jobs: # need to publish all unpublished versions to npm here # See: https://github.com/lerna/lerna/tree/main/commands/publish#bump-from-package - name: Publish to npm + # only publish if a release has been created + if: ${{ steps.release.outputs.release_created }} env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} run: npx lerna publish from-package --no-push --no-private --no-git-tag-version --no-verify-access --yes From a5bee9fe15f67f0e08bb6354e9bfd7876f3ff0ca Mon Sep 17 00:00:00 2001 From: David Luna Date: Tue, 23 Apr 2024 21:07:21 +0200 Subject: [PATCH 4/4] chore(instr-amqpllib): use semconv strings in test files (#2113) --- .../test/amqplib-callbacks.test.ts | 196 +++++++------ .../test/amqplib-connection.test.ts | 83 +++--- .../test/amqplib-promise.test.ts | 260 +++++++++--------- .../test/utils.test.ts | 104 +++---- 4 files changed, 319 insertions(+), 324 deletions(-) diff --git a/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts b/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts index 9f2ab1d81e..533b5d9942 100644 --- a/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts +++ b/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts @@ -25,8 +25,16 @@ registerInstrumentationTesting(new AmqplibInstrumentation()); import * as amqpCallback from 'amqplib/callback_api'; import { - MessagingDestinationKindValues, - SemanticAttributes, + MESSAGINGDESTINATIONKINDVALUES_TOPIC, + SEMATTRS_MESSAGING_DESTINATION, + SEMATTRS_MESSAGING_DESTINATION_KIND, + SEMATTRS_MESSAGING_PROTOCOL, + SEMATTRS_MESSAGING_PROTOCOL_VERSION, + SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY, + SEMATTRS_MESSAGING_SYSTEM, + SEMATTRS_MESSAGING_URL, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import { Baggage, context, propagation, SpanKind } from '@opentelemetry/api'; import { asyncConfirmSend, asyncConsume, shouldTest } from './utils'; @@ -127,67 +135,63 @@ describe('amqplib instrumentation callback model', () => { // assert publish span expect(publishSpan.kind).toEqual(SpanKind.PRODUCER); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '' + ); // according to spec: "This will be an empty string if the default exchange is used" expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used" - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - publishSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + publishSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(queueName); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_URL] - ).toEqual(censoredUrl); - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_NAME] - ).toEqual(TEST_RABBITMQ_HOST); - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_PORT] - ).toEqual(TEST_RABBITMQ_PORT); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( + censoredUrl + ); + expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( + TEST_RABBITMQ_HOST + ); + expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( + TEST_RABBITMQ_PORT + ); // assert consume span expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '' + ); // according to spec: "This will be an empty string if the default exchange is used" expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used" - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - consumeSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + consumeSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(queueName); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_URL] - ).toEqual(censoredUrl); - expect( - consumeSpan.attributes[SemanticAttributes.NET_PEER_NAME] - ).toEqual(TEST_RABBITMQ_HOST); - expect( - consumeSpan.attributes[SemanticAttributes.NET_PEER_PORT] - ).toEqual(TEST_RABBITMQ_PORT); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( + censoredUrl + ); + expect(consumeSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( + TEST_RABBITMQ_HOST + ); + expect(consumeSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( + TEST_RABBITMQ_PORT + ); // assert context propagation expect(consumeSpan.spanContext().traceId).toEqual( @@ -301,75 +305,63 @@ describe('amqplib instrumentation callback model', () => { // assert publish span expect(publishSpan.kind).toEqual(SpanKind.PRODUCER); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] + publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION] ).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used" expect( - publishSpan.attributes[ - SemanticAttributes.MESSAGING_DESTINATION_KIND - ] - ).toEqual(MessagingDestinationKindValues.TOPIC); + publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - publishSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + publishSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(queueName); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - publishSpan.attributes[ - SemanticAttributes.MESSAGING_PROTOCOL_VERSION - ] + publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_URL] - ).toEqual(censoredUrl); - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_NAME] - ).toEqual(TEST_RABBITMQ_HOST); - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_PORT] - ).toEqual(TEST_RABBITMQ_PORT); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( + censoredUrl + ); + expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( + TEST_RABBITMQ_HOST + ); + expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( + TEST_RABBITMQ_PORT + ); // assert consume span expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] + consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION] ).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used" expect( - consumeSpan.attributes[ - SemanticAttributes.MESSAGING_DESTINATION_KIND - ] - ).toEqual(MessagingDestinationKindValues.TOPIC); + consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - consumeSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + consumeSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(queueName); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - consumeSpan.attributes[ - SemanticAttributes.MESSAGING_PROTOCOL_VERSION - ] + consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_URL] - ).toEqual(censoredUrl); - expect( - consumeSpan.attributes[SemanticAttributes.NET_PEER_NAME] - ).toEqual(TEST_RABBITMQ_HOST); - expect( - consumeSpan.attributes[SemanticAttributes.NET_PEER_PORT] - ).toEqual(TEST_RABBITMQ_PORT); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( + censoredUrl + ); + expect(consumeSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( + TEST_RABBITMQ_HOST + ); + expect(consumeSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( + TEST_RABBITMQ_PORT + ); // assert context propagation expect(consumeSpan.spanContext().traceId).toEqual( diff --git a/plugins/node/instrumentation-amqplib/test/amqplib-connection.test.ts b/plugins/node/instrumentation-amqplib/test/amqplib-connection.test.ts index 7ac3e686e5..a9f6c5526d 100644 --- a/plugins/node/instrumentation-amqplib/test/amqplib-connection.test.ts +++ b/plugins/node/instrumentation-amqplib/test/amqplib-connection.test.ts @@ -32,7 +32,14 @@ import { registerInstrumentationTesting(new AmqplibInstrumentation()); import * as amqp from 'amqplib'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_MESSAGING_PROTOCOL, + SEMATTRS_MESSAGING_PROTOCOL_VERSION, + SEMATTRS_MESSAGING_SYSTEM, + SEMATTRS_MESSAGING_URL, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, +} from '@opentelemetry/semantic-conventions'; describe('amqplib instrumentation connection', () => { before(function () { @@ -60,24 +67,22 @@ describe('amqplib instrumentation connection', () => { ); const [publishSpan] = getTestSpans(); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_URL] - ).toBeUndefined(); // no url string if value supplied as object - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_NAME] - ).toEqual(TEST_RABBITMQ_HOST); - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_PORT] - ).toEqual(TEST_RABBITMQ_PORT); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toBeUndefined(); // no url string if value supplied as object + expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( + TEST_RABBITMQ_HOST + ); + expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( + TEST_RABBITMQ_PORT + ); } finally { await conn.close(); } @@ -99,9 +104,9 @@ describe('amqplib instrumentation connection', () => { Buffer.from('message created only to test connection attributes') ); const [publishSpan] = getTestSpans(); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); } finally { await conn.close(); } @@ -127,9 +132,9 @@ describe('amqplib instrumentation connection', () => { Buffer.from('message created only to test connection attributes') ); const [publishSpan] = getTestSpans(); - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_NAME] - ).toEqual(TEST_RABBITMQ_HOST); + expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( + TEST_RABBITMQ_HOST + ); } finally { await conn.close(); } @@ -149,24 +154,24 @@ describe('amqplib instrumentation connection', () => { ); const [publishSpan] = getTestSpans(); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_URL] - ).toEqual(censoredUrl); - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_NAME] - ).toEqual(TEST_RABBITMQ_HOST); - expect( - publishSpan.attributes[SemanticAttributes.NET_PEER_PORT] - ).toEqual(TEST_RABBITMQ_PORT); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( + censoredUrl + ); + expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( + TEST_RABBITMQ_HOST + ); + expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( + TEST_RABBITMQ_PORT + ); } finally { await conn.close(); } diff --git a/plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts b/plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts index e130f5e942..2205d76a5a 100644 --- a/plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts +++ b/plugins/node/instrumentation-amqplib/test/amqplib-promise.test.ts @@ -36,8 +36,16 @@ const instrumentation = registerInstrumentationTesting( import * as amqp from 'amqplib'; import { ConsumeMessage } from 'amqplib'; import { - MessagingDestinationKindValues, - SemanticAttributes, + MESSAGINGDESTINATIONKINDVALUES_TOPIC, + SEMATTRS_MESSAGING_DESTINATION, + SEMATTRS_MESSAGING_DESTINATION_KIND, + SEMATTRS_MESSAGING_PROTOCOL, + SEMATTRS_MESSAGING_PROTOCOL_VERSION, + SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY, + SEMATTRS_MESSAGING_SYSTEM, + SEMATTRS_MESSAGING_URL, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, } from '@opentelemetry/semantic-conventions'; import { Span, SpanKind, SpanStatusCode } from '@opentelemetry/api'; import { asyncConfirmPublish, asyncConfirmSend, asyncConsume } from './utils'; @@ -146,65 +154,61 @@ describe('amqplib instrumentation promise model', () => { // assert publish span expect(publishSpan.kind).toEqual(SpanKind.PRODUCER); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '' + ); // according to spec: "This will be an empty string if the default exchange is used" expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used" - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - publishSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + publishSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(queueName); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect(publishSpan.attributes[SemanticAttributes.MESSAGING_URL]).toEqual( + expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( censoredUrl ); - expect(publishSpan.attributes[SemanticAttributes.NET_PEER_NAME]).toEqual( + expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( TEST_RABBITMQ_HOST ); - expect(publishSpan.attributes[SemanticAttributes.NET_PEER_PORT]).toEqual( + expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( TEST_RABBITMQ_PORT ); // assert consume span expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '' + ); // according to spec: "This will be an empty string if the default exchange is used" expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used" - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - consumeSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + consumeSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(queueName); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect(consumeSpan.attributes[SemanticAttributes.MESSAGING_URL]).toEqual( + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( censoredUrl ); - expect(consumeSpan.attributes[SemanticAttributes.NET_PEER_NAME]).toEqual( + expect(consumeSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( TEST_RABBITMQ_HOST ); - expect(consumeSpan.attributes[SemanticAttributes.NET_PEER_PORT]).toEqual( + expect(consumeSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( TEST_RABBITMQ_PORT ); @@ -505,48 +509,44 @@ describe('amqplib instrumentation promise model', () => { // assert publish span expect(publishSpan.kind).toEqual(SpanKind.PRODUCER); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + exchangeName + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(exchangeName); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - publishSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + publishSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(routingKey); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); // assert consume span expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + exchangeName + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(exchangeName); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - consumeSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + consumeSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(routingKey); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); // assert context propagation @@ -689,65 +689,61 @@ describe('amqplib instrumentation promise model', () => { // assert publish span expect(publishSpan.kind).toEqual(SpanKind.PRODUCER); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '' + ); // according to spec: "This will be an empty string if the default exchange is used" expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used" - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - publishSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + publishSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(queueName); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect(publishSpan.attributes[SemanticAttributes.MESSAGING_URL]).toEqual( + expect(publishSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( censoredUrl ); - expect(publishSpan.attributes[SemanticAttributes.NET_PEER_NAME]).toEqual( + expect(publishSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( TEST_RABBITMQ_HOST ); - expect(publishSpan.attributes[SemanticAttributes.NET_PEER_PORT]).toEqual( + expect(publishSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( TEST_RABBITMQ_PORT ); // assert consume span expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + '' + ); // according to spec: "This will be an empty string if the default exchange is used" expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(''); // according to spec: "This will be an empty string if the default exchange is used" - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - consumeSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + consumeSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(queueName); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); - expect(consumeSpan.attributes[SemanticAttributes.MESSAGING_URL]).toEqual( + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_URL]).toEqual( censoredUrl ); - expect(consumeSpan.attributes[SemanticAttributes.NET_PEER_NAME]).toEqual( + expect(consumeSpan.attributes[SEMATTRS_NET_PEER_NAME]).toEqual( TEST_RABBITMQ_HOST ); - expect(consumeSpan.attributes[SemanticAttributes.NET_PEER_PORT]).toEqual( + expect(consumeSpan.attributes[SEMATTRS_NET_PEER_PORT]).toEqual( TEST_RABBITMQ_PORT ); @@ -1100,48 +1096,44 @@ describe('amqplib instrumentation promise model', () => { // assert publish span expect(publishSpan.kind).toEqual(SpanKind.PRODUCER); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + exchangeName + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(exchangeName); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + publishSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - publishSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + publishSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(routingKey); + expect(publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - publishSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + publishSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); // assert consume span expect(consumeSpan.kind).toEqual(SpanKind.CONSUMER); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( + 'rabbitmq' + ); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual( + exchangeName + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_SYSTEM] - ).toEqual('rabbitmq'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION] - ).toEqual(exchangeName); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] - ).toEqual(MessagingDestinationKindValues.TOPIC); + consumeSpan.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND] + ).toEqual(MESSAGINGDESTINATIONKINDVALUES_TOPIC); expect( - consumeSpan.attributes[ - SemanticAttributes.MESSAGING_RABBITMQ_ROUTING_KEY - ] + consumeSpan.attributes[SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY] ).toEqual(routingKey); + expect(consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL]).toEqual( + 'AMQP' + ); expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL] - ).toEqual('AMQP'); - expect( - consumeSpan.attributes[SemanticAttributes.MESSAGING_PROTOCOL_VERSION] + consumeSpan.attributes[SEMATTRS_MESSAGING_PROTOCOL_VERSION] ).toEqual('0.9.1'); // assert context propagation diff --git a/plugins/node/instrumentation-amqplib/test/utils.test.ts b/plugins/node/instrumentation-amqplib/test/utils.test.ts index 34e6fb7aa9..6369398969 100644 --- a/plugins/node/instrumentation-amqplib/test/utils.test.ts +++ b/plugins/node/instrumentation-amqplib/test/utils.test.ts @@ -19,7 +19,14 @@ import { getConnectionAttributesFromServer, getConnectionAttributesFromUrl, } from '../src/utils'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + SEMATTRS_MESSAGING_PROTOCOL, + SEMATTRS_MESSAGING_PROTOCOL_VERSION, + SEMATTRS_MESSAGING_SYSTEM, + SEMATTRS_MESSAGING_URL, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, +} from '@opentelemetry/semantic-conventions'; import * as amqp from 'amqplib'; import { shouldTest } from './utils'; import { rabbitMqUrl } from './config'; @@ -43,7 +50,7 @@ describe('utils', () => { it('messaging system attribute', () => { const attributes = getConnectionAttributesFromServer(conn.connection); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_SYSTEM]: 'rabbitmq', + [SEMATTRS_MESSAGING_SYSTEM]: 'rabbitmq', }); }); }); @@ -54,11 +61,11 @@ describe('utils', () => { 'amqp://user:pass@host:10000/vhost' ); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL]: 'AMQP', - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.NET_PEER_NAME]: 'host', - [SemanticAttributes.NET_PEER_PORT]: 10000, - [SemanticAttributes.MESSAGING_URL]: 'amqp://user:***@host:10000/vhost', + [SEMATTRS_MESSAGING_PROTOCOL]: 'AMQP', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_NET_PEER_NAME]: 'host', + [SEMATTRS_NET_PEER_PORT]: 10000, + [SEMATTRS_MESSAGING_URL]: 'amqp://user:***@host:10000/vhost', }); }); @@ -67,102 +74,101 @@ describe('utils', () => { 'amqp://user%61:%61pass@ho%61st:10000/v%2fhost' ); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL]: 'AMQP', - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.NET_PEER_NAME]: 'ho%61st', - [SemanticAttributes.NET_PEER_PORT]: 10000, - [SemanticAttributes.MESSAGING_URL]: - 'amqp://user%61:***@ho%61st:10000/v%2fhost', + [SEMATTRS_MESSAGING_PROTOCOL]: 'AMQP', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_NET_PEER_NAME]: 'ho%61st', + [SEMATTRS_NET_PEER_PORT]: 10000, + [SEMATTRS_MESSAGING_URL]: 'amqp://user%61:***@ho%61st:10000/v%2fhost', }); }); it('only protocol', () => { const attributes = getConnectionAttributesFromUrl('amqp://'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL]: 'AMQP', - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.NET_PEER_NAME]: 'localhost', - [SemanticAttributes.NET_PEER_PORT]: 5672, - [SemanticAttributes.MESSAGING_URL]: 'amqp://', + [SEMATTRS_MESSAGING_PROTOCOL]: 'AMQP', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_NET_PEER_NAME]: 'localhost', + [SEMATTRS_NET_PEER_PORT]: 5672, + [SEMATTRS_MESSAGING_URL]: 'amqp://', }); }); it('empty username and password', () => { const attributes = getConnectionAttributesFromUrl('amqp://:@/'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.MESSAGING_URL]: 'amqp://:***@/', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_MESSAGING_URL]: 'amqp://:***@/', }); }); it('username and no password', () => { const attributes = getConnectionAttributesFromUrl('amqp://user@'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.MESSAGING_URL]: 'amqp://user@', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_MESSAGING_URL]: 'amqp://user@', }); }); it('username and password, no host', () => { const attributes = getConnectionAttributesFromUrl('amqp://user:pass@'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.MESSAGING_URL]: 'amqp://user:***@', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_MESSAGING_URL]: 'amqp://user:***@', }); }); it('host only', () => { const attributes = getConnectionAttributesFromUrl('amqp://host'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL]: 'AMQP', - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.NET_PEER_NAME]: 'host', - [SemanticAttributes.NET_PEER_PORT]: 5672, - [SemanticAttributes.MESSAGING_URL]: 'amqp://host', + [SEMATTRS_MESSAGING_PROTOCOL]: 'AMQP', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_NET_PEER_NAME]: 'host', + [SEMATTRS_NET_PEER_PORT]: 5672, + [SEMATTRS_MESSAGING_URL]: 'amqp://host', }); }); it('vhost only', () => { const attributes = getConnectionAttributesFromUrl('amqp:///vhost'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL]: 'AMQP', - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.NET_PEER_NAME]: 'localhost', - [SemanticAttributes.NET_PEER_PORT]: 5672, - [SemanticAttributes.MESSAGING_URL]: 'amqp:///vhost', + [SEMATTRS_MESSAGING_PROTOCOL]: 'AMQP', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_NET_PEER_NAME]: 'localhost', + [SEMATTRS_NET_PEER_PORT]: 5672, + [SEMATTRS_MESSAGING_URL]: 'amqp:///vhost', }); }); it('host only, trailing slash', () => { const attributes = getConnectionAttributesFromUrl('amqp://host/'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL]: 'AMQP', - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.NET_PEER_NAME]: 'host', - [SemanticAttributes.NET_PEER_PORT]: 5672, - [SemanticAttributes.MESSAGING_URL]: 'amqp://host/', + [SEMATTRS_MESSAGING_PROTOCOL]: 'AMQP', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_NET_PEER_NAME]: 'host', + [SEMATTRS_NET_PEER_PORT]: 5672, + [SEMATTRS_MESSAGING_URL]: 'amqp://host/', }); }); it('vhost encoded', () => { const attributes = getConnectionAttributesFromUrl('amqp://host/%2f'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL]: 'AMQP', - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.NET_PEER_NAME]: 'host', - [SemanticAttributes.NET_PEER_PORT]: 5672, - [SemanticAttributes.MESSAGING_URL]: 'amqp://host/%2f', + [SEMATTRS_MESSAGING_PROTOCOL]: 'AMQP', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_NET_PEER_NAME]: 'host', + [SEMATTRS_NET_PEER_PORT]: 5672, + [SEMATTRS_MESSAGING_URL]: 'amqp://host/%2f', }); }); it('IPv6 host', () => { const attributes = getConnectionAttributesFromUrl('amqp://[::1]'); expect(attributes).toStrictEqual({ - [SemanticAttributes.MESSAGING_PROTOCOL]: 'AMQP', - [SemanticAttributes.MESSAGING_PROTOCOL_VERSION]: '0.9.1', - [SemanticAttributes.NET_PEER_NAME]: '[::1]', - [SemanticAttributes.NET_PEER_PORT]: 5672, - [SemanticAttributes.MESSAGING_URL]: 'amqp://[::1]', + [SEMATTRS_MESSAGING_PROTOCOL]: 'AMQP', + [SEMATTRS_MESSAGING_PROTOCOL_VERSION]: '0.9.1', + [SEMATTRS_NET_PEER_NAME]: '[::1]', + [SEMATTRS_NET_PEER_PORT]: 5672, + [SEMATTRS_MESSAGING_URL]: 'amqp://[::1]', }); }); });