From f6f9e4c3f806b7b122ff4182e50403dfb641131f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Mon, 20 Jan 2025 12:31:24 +0100 Subject: [PATCH 1/9] feat(instrumentation-knex): Use newer semantic conventions --- .../README.md | 42 +++++++++- .../package.json | 4 +- .../src/env.ts | 48 +++++++++++ .../src/instrumentation.ts | 84 +++++++++++++++---- .../src/internal-types.ts | 23 +++++ .../src/semconv.ts | 30 +++++++ .../src/utils.ts | 10 +-- 7 files changed, 218 insertions(+), 23 deletions(-) create mode 100644 plugins/node/opentelemetry-instrumentation-knex/src/env.ts create mode 100644 plugins/node/opentelemetry-instrumentation-knex/src/internal-types.ts create mode 100644 plugins/node/opentelemetry-instrumentation-knex/src/semconv.ts diff --git a/plugins/node/opentelemetry-instrumentation-knex/README.md b/plugins/node/opentelemetry-instrumentation-knex/README.md index 596fdcc619..a30f4c83a1 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/README.md +++ b/plugins/node/opentelemetry-instrumentation-knex/README.md @@ -54,7 +54,28 @@ 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) +This package uses `@opentelemetry/semantic-conventions` version `1.27+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) + +This package is capable of emitting both Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) and [Version 1.32.0](https://github.com/open-telemetry/semantic-conventions/blob/v1.32.0/docs/database/database-metrics.md) +It is controlled using the environment variable `OTEL_SEMCONV_STABILITY_OPT_IN`, which is a comma separated list of values. +The values `database` and `database/dup` control this instrumentation. +See details for the behavior of each of these values below. +If neither `database` or `database/dup` is included in `OTEL_SEMCONV_STABILITY_OPT_IN`, the old experimental semantic conventions will be used by default. + +### Upgrading Semantic Conventions + +When upgrading to the new semantic conventions, it is recommended to do so in the following order: + +1. Upgrade `@opentelemetry/instrumentation-knex` to the latest version +2. Set `OTEL_SEMCONV_STABILITY_OPT_IN=database/dup` to emit both old and new semantic conventions +3. Modify alerts, dashboards, metrics, and other processes to expect the new semantic conventions +4. Set `OTEL_SEMCONV_STABILITY_OPT_IN=database` to emit only the new semantic conventions + +This will cause both the old and new semantic conventions to be emitted during the transition period. + +### ### Legacy Behavior (default) + +Enabled when `OTEL_SEMCONV_STABILITY_OPT_IN` contains `database/dup` or DOES NOT CONTAIN `database`. Attributes collected: @@ -70,6 +91,25 @@ Attributes collected: | `net.peer.port` | Remote port number. | | `net.transport` | Transport protocol used. | +### RC Semantic Conventions 1.32 + +Enabled when `OTEL_SEMCONV_STABILITY_OPT_IN` contains `database` OR `database/dup`. +This is the recommended configuration, and will soon become the default behavior. + +Attributes collected: + +| Attribute | Short Description | +|----------------------|-----------------------------------------------------------------------------| +| `db.namespace` | This attribute is used to report the name of the database being accessed. | +| `db.operation.name` | The name of the operation being executed. | +| `db.collection.name` | The name of the primary table that the operation is acting upon. | +| `db.query.text` | 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. | +| `server.address` | Remote hostname or similar. | +| `server.port` | Remote port number. | +| `network.transport` | Transport protocol used. | + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/plugins/node/opentelemetry-instrumentation-knex/package.json b/plugins/node/opentelemetry-instrumentation-knex/package.json index a1b4bb0f0d..bbb7fa52e0 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/package.json +++ b/plugins/node/opentelemetry-instrumentation-knex/package.json @@ -33,7 +33,9 @@ "files": [ "build/src/**/*.js", "build/src/**/*.js.map", - "build/src/**/*.d.ts" + "build/src/**/*.d.ts", + "LICENSE", + "README.md" ], "publishConfig": { "access": "public" diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/env.ts b/plugins/node/opentelemetry-instrumentation-knex/src/env.ts new file mode 100644 index 0000000000..f4ee2c1ace --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-knex/src/env.ts @@ -0,0 +1,48 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Retrieves a string from an environment variable. + * - Returns `undefined` if the environment variable is empty, unset, or contains only whitespace. + * + * @param {string} key - The name of the environment variable to retrieve. + * @returns {string | undefined} - The string value or `undefined`. + */ +export function getStringFromEnv(key: string): string | undefined { + const raw = process.env[key]; + if (raw == null || raw.trim() === '') { + return undefined; + } + return raw; +} + +/** + * Retrieves a list of strings from an environment variable. + * - Uses ',' as the delimiter. + * - Trims leading and trailing whitespace from each entry. + * - Excludes empty entries. + * - Returns `undefined` if the environment variable is empty or contains only whitespace. + * - Returns an empty array if all entries are empty or whitespace. + * + * @param {string} key - The name of the environment variable to retrieve. + * @returns {string[] | undefined} - The list of strings or `undefined`. + */ +export function getStringListFromEnv(key: string): string[] | undefined { + return getStringFromEnv(key) + ?.split(',') + .map(v => v.trim()) + .filter(s => s !== ''); +} diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts index 5b7086895d..d7539d8c6e 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts @@ -24,7 +24,14 @@ import { InstrumentationNodeModuleFile, isWrapped, } from '@opentelemetry/instrumentation'; +import * as utils from './utils'; +import { KnexInstrumentationConfig } from './types'; +import { SemconvStability } from './internal-types'; +import { getStringListFromEnv } from './env'; import { + ATTR_NETWORK_TRANSPORT, + ATTR_SERVER_ADDRESS, + ATTR_SERVER_PORT, SEMATTRS_DB_NAME, SEMATTRS_DB_OPERATION, SEMATTRS_DB_SQL_TABLE, @@ -35,8 +42,15 @@ import { SEMATTRS_NET_PEER_PORT, SEMATTRS_NET_TRANSPORT, } from '@opentelemetry/semantic-conventions'; -import * as utils from './utils'; -import { KnexInstrumentationConfig } from './types'; +import { + ATTR_DB_COLLECTION_NAME, + ATTR_DB_NAMESPACE, + ATTR_DB_OPERATION_NAME, + ATTR_DB_QUERY_TEXT, + ATTR_DB_SYSTEM_NAME, + ATTR_DB_USER, +} from './semconv'; +import { mapSystem } from './utils'; const contextSymbol = Symbol('opentelemetry.instrumentation-knex.context'); const DEFAULT_CONFIG: KnexInstrumentationConfig = { @@ -45,8 +59,21 @@ const DEFAULT_CONFIG: KnexInstrumentationConfig = { }; export class KnexInstrumentation extends InstrumentationBase { + private _semconvStability: SemconvStability = SemconvStability.OLD; + constructor(config: KnexInstrumentationConfig = {}) { super(PACKAGE_NAME, PACKAGE_VERSION, { ...DEFAULT_CONFIG, ...config }); + + for (const entry of getStringListFromEnv('OTEL_SEMCONV_STABILITY_OPT_IN') ?? + []) { + if (entry.toLowerCase() === 'database/dup') { + // database/dup takes highest precedence. If it is found, there is no need to read the rest of the list + this._semconvStability = SemconvStability.DUPLICATE; + break; + } else if (entry.toLowerCase() === 'database') { + this._semconvStability = SemconvStability.STABLE; + } + } } override setConfig(config: KnexInstrumentationConfig = {}) { @@ -122,6 +149,10 @@ export class KnexInstrumentation extends InstrumentationBase any) { return function wrapped_logging_method(this: any, query: any) { const config = this.client.config; @@ -134,24 +165,45 @@ export class KnexInstrumentation extends InstrumentationBase { From aef24d6199aa492bdeb5df98615234abea018e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Tue, 15 Apr 2025 10:05:40 +0200 Subject: [PATCH 2/9] feat(instrumentation-knex): Use getStringListFromEnv from core --- .../package.json | 1 + .../src/env.ts | 48 ------------------- .../src/instrumentation.ts | 2 +- 3 files changed, 2 insertions(+), 49 deletions(-) delete mode 100644 plugins/node/opentelemetry-instrumentation-knex/src/env.ts diff --git a/plugins/node/opentelemetry-instrumentation-knex/package.json b/plugins/node/opentelemetry-instrumentation-knex/package.json index bbb7fa52e0..ca993cc303 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/package.json +++ b/plugins/node/opentelemetry-instrumentation-knex/package.json @@ -58,6 +58,7 @@ "typescript": "5.0.4" }, "dependencies": { + "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.200.0", "@opentelemetry/semantic-conventions": "^1.27.0" }, diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/env.ts b/plugins/node/opentelemetry-instrumentation-knex/src/env.ts deleted file mode 100644 index f4ee2c1ace..0000000000 --- a/plugins/node/opentelemetry-instrumentation-knex/src/env.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Retrieves a string from an environment variable. - * - Returns `undefined` if the environment variable is empty, unset, or contains only whitespace. - * - * @param {string} key - The name of the environment variable to retrieve. - * @returns {string | undefined} - The string value or `undefined`. - */ -export function getStringFromEnv(key: string): string | undefined { - const raw = process.env[key]; - if (raw == null || raw.trim() === '') { - return undefined; - } - return raw; -} - -/** - * Retrieves a list of strings from an environment variable. - * - Uses ',' as the delimiter. - * - Trims leading and trailing whitespace from each entry. - * - Excludes empty entries. - * - Returns `undefined` if the environment variable is empty or contains only whitespace. - * - Returns an empty array if all entries are empty or whitespace. - * - * @param {string} key - The name of the environment variable to retrieve. - * @returns {string[] | undefined} - The list of strings or `undefined`. - */ -export function getStringListFromEnv(key: string): string[] | undefined { - return getStringFromEnv(key) - ?.split(',') - .map(v => v.trim()) - .filter(s => s !== ''); -} diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts index d7539d8c6e..b2a3f3b8f9 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts @@ -27,7 +27,7 @@ import { import * as utils from './utils'; import { KnexInstrumentationConfig } from './types'; import { SemconvStability } from './internal-types'; -import { getStringListFromEnv } from './env'; +import { getStringListFromEnv } from '@opentelemetry/core'; import { ATTR_NETWORK_TRANSPORT, ATTR_SERVER_ADDRESS, From ff6e0bf2e7e687d59d8341c8f0b8dc7bd556a961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Tue, 13 May 2025 10:56:43 +0200 Subject: [PATCH 3/9] Apply suggestions from code review Co-authored-by: Trent Mick --- plugins/node/opentelemetry-instrumentation-knex/README.md | 2 +- .../opentelemetry-instrumentation-knex/src/instrumentation.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-knex/README.md b/plugins/node/opentelemetry-instrumentation-knex/README.md index a30f4c83a1..001c691e91 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/README.md +++ b/plugins/node/opentelemetry-instrumentation-knex/README.md @@ -73,7 +73,7 @@ When upgrading to the new semantic conventions, it is recommended to do so in th This will cause both the old and new semantic conventions to be emitted during the transition period. -### ### Legacy Behavior (default) +### Legacy Behavior (default) Enabled when `OTEL_SEMCONV_STABILITY_OPT_IN` contains `database/dup` or DOES NOT CONTAIN `database`. diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts index b2a3f3b8f9..40f609463d 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts @@ -171,7 +171,7 @@ export class KnexInstrumentation extends InstrumentationBase Date: Wed, 14 May 2025 20:02:54 +0200 Subject: [PATCH 4/9] feat(instrumentation-knex): Implement fixes after review * Bump semantic-conventions to ^1.33.0 * Update used attributes to stabilised ones --- package-lock.json | 29 +++++++---- .../README.md | 49 +++++-------------- .../package.json | 6 +-- .../src/instrumentation.ts | 29 ++++------- .../src/semconv.ts | 30 ------------ .../src/utils.ts | 2 +- 6 files changed, 45 insertions(+), 100 deletions(-) delete mode 100644 plugins/node/opentelemetry-instrumentation-knex/src/semconv.ts diff --git a/package-lock.json b/package-lock.json index a031d3c9d0..4e971f3a27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8774,9 +8774,10 @@ } }, "node_modules/@opentelemetry/semantic-conventions": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.30.0.tgz", - "integrity": "sha512-4VlGgo32k2EQ2wcCY3vEU28A0O13aOtHz3Xt2/2U5FAh9EfhD6t6DqL5Z6yAnRCntbTFDU4YfbpyzSlHNWycPw==", + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.33.0.tgz", + "integrity": "sha512-TIpZvE8fiEILFfTlfPnltpBaD3d9/+uQHVCyC3vfdh6WfCXKhNFzoP5RyDDIndfvZC5GrA4pyEDNyjPloJud+w==", + "license": "Apache-2.0", "engines": { "node": ">=14" } @@ -36128,8 +36129,9 @@ "version": "0.45.0", "license": "Apache-2.0", "dependencies": { + "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.200.0", - "@opentelemetry/semantic-conventions": "^1.27.0" + "@opentelemetry/semantic-conventions": "^1.33.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -36706,7 +36708,7 @@ "@types/node": "18.18.14", "@types/sinon": "17.0.4", "cross-env": "7.0.3", - "nyc": "15.1.0", + "nyc": "17.1.0", "oracledb": "^6.7.0", "rimraf": "5.0.10", "safe-stable-stringify": "^2.4.1", @@ -45004,10 +45006,11 @@ "requires": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^2.0.0", + "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.200.0", "@opentelemetry/sdk-trace-base": "^2.0.0", "@opentelemetry/sdk-trace-node": "^2.0.0", - "@opentelemetry/semantic-conventions": "^1.27.0", + "@opentelemetry/semantic-conventions": "^1.33.0", "@types/mocha": "10.0.10", "@types/node": "18.18.14", "better-sqlite3": "11.0.0", @@ -45543,7 +45546,7 @@ "@types/oracledb": "6.5.2", "@types/sinon": "17.0.4", "cross-env": "7.0.3", - "nyc": "15.1.0", + "nyc": "17.1.0", "oracledb": "^6.7.0", "rimraf": "5.0.10", "safe-stable-stringify": "^2.4.1", @@ -45554,6 +45557,8 @@ "dependencies": { "@types/node": { "version": "18.18.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.14.tgz", + "integrity": "sha512-iSOeNeXYNYNLLOMDSVPvIFojclvMZ/HDY2dU17kUlcsOsSQETbWIslJbYLZgA+ox8g2XQwSHKTkght1a5X26lQ==", "dev": true, "requires": { "undici-types": "~5.26.4" @@ -45561,10 +45566,14 @@ }, "typescript": { "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", "dev": true }, "undici-types": { "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "dev": true } } @@ -47243,9 +47252,9 @@ } }, "@opentelemetry/semantic-conventions": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.30.0.tgz", - "integrity": "sha512-4VlGgo32k2EQ2wcCY3vEU28A0O13aOtHz3Xt2/2U5FAh9EfhD6t6DqL5Z6yAnRCntbTFDU4YfbpyzSlHNWycPw==" + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.33.0.tgz", + "integrity": "sha512-TIpZvE8fiEILFfTlfPnltpBaD3d9/+uQHVCyC3vfdh6WfCXKhNFzoP5RyDDIndfvZC5GrA4pyEDNyjPloJud+w==" }, "@opentelemetry/sql-common": { "version": "file:packages/opentelemetry-sql-common", diff --git a/plugins/node/opentelemetry-instrumentation-knex/README.md b/plugins/node/opentelemetry-instrumentation-knex/README.md index 001c691e91..0a62c03a5a 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/README.md +++ b/plugins/node/opentelemetry-instrumentation-knex/README.md @@ -54,9 +54,9 @@ registerInstrumentations({ ## Semantic Conventions -This package uses `@opentelemetry/semantic-conventions` version `1.27+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) +This package uses `@opentelemetry/semantic-conventions` version `1.33+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) -This package is capable of emitting both Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) and [Version 1.32.0](https://github.com/open-telemetry/semantic-conventions/blob/v1.32.0/docs/database/database-metrics.md) +This package is capable of emitting both Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) and [Version 1.33.0](https://github.com/open-telemetry/semantic-conventions/blob/v1.33.0/docs/database/database-metrics.md) It is controlled using the environment variable `OTEL_SEMCONV_STABILITY_OPT_IN`, which is a comma separated list of values. The values `database` and `database/dup` control this instrumentation. See details for the behavior of each of these values below. @@ -73,42 +73,19 @@ When upgrading to the new semantic conventions, it is recommended to do so in th This will cause both the old and new semantic conventions to be emitted during the transition period. -### Legacy Behavior (default) - -Enabled when `OTEL_SEMCONV_STABILITY_OPT_IN` contains `database/dup` or DOES NOT CONTAIN `database`. - -Attributes collected: - -| Attribute | Short Description | -| ----------------------- | ------------------------------------------------------------------------------ | -| `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.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. | -| `net.transport` | Transport protocol used. | - -### RC Semantic Conventions 1.32 - -Enabled when `OTEL_SEMCONV_STABILITY_OPT_IN` contains `database` OR `database/dup`. -This is the recommended configuration, and will soon become the default behavior. - Attributes collected: -| Attribute | Short Description | -|----------------------|-----------------------------------------------------------------------------| -| `db.namespace` | This attribute is used to report the name of the database being accessed. | -| `db.operation.name` | The name of the operation being executed. | -| `db.collection.name` | The name of the primary table that the operation is acting upon. | -| `db.query.text` | 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. | -| `server.address` | Remote hostname or similar. | -| `server.port` | Remote port number. | -| `network.transport` | Transport protocol used. | +| v1.7.0 semconv | v1.23.0 semconv | Short Description | +|-----------------|----------------------|-----------------------------------------------------------------------------| +| `db.name` | `db.namespace` | This attribute is used to report the name of the database being accessed. | +| `db.operation` | `db.operation.name` | The name of the operation being executed. | +| `db.sql.table` | `db.collection.name` | The name of the primary table that the operation is acting upon. | +| `db.statement` | `db.query.text` | The database statement being executed. | +| `db.system` | `db.system.name` | An identifier for the database management system (DBMS) product being used. | +| `db.user` | (not included) | Username for accessing the database. | +| `net.peer.name` | `server.address` | Remote hostname or similar. | +| `net.peer.port` | `server.port` | Remote port number. | +| `net.transport` | (not included) | Transport protocol used. | ## Useful links diff --git a/plugins/node/opentelemetry-instrumentation-knex/package.json b/plugins/node/opentelemetry-instrumentation-knex/package.json index 6f6d9129f2..1cb2069751 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/package.json +++ b/plugins/node/opentelemetry-instrumentation-knex/package.json @@ -33,9 +33,7 @@ "files": [ "build/src/**/*.js", "build/src/**/*.js.map", - "build/src/**/*.d.ts", - "LICENSE", - "README.md" + "build/src/**/*.d.ts" ], "publishConfig": { "access": "public" @@ -60,7 +58,7 @@ "dependencies": { "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.200.0", - "@opentelemetry/semantic-conventions": "^1.27.0" + "@opentelemetry/semantic-conventions": "^1.33.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-knex#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts index 40f609463d..f42bb18750 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts @@ -25,11 +25,16 @@ import { isWrapped, } from '@opentelemetry/instrumentation'; import * as utils from './utils'; +import { mapSystem } from './utils'; import { KnexInstrumentationConfig } from './types'; import { SemconvStability } from './internal-types'; import { getStringListFromEnv } from '@opentelemetry/core'; import { - ATTR_NETWORK_TRANSPORT, + ATTR_DB_COLLECTION_NAME, + ATTR_DB_NAMESPACE, + ATTR_DB_OPERATION_NAME, + ATTR_DB_QUERY_TEXT, + ATTR_DB_SYSTEM_NAME, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, SEMATTRS_DB_NAME, @@ -42,15 +47,6 @@ import { SEMATTRS_NET_PEER_PORT, SEMATTRS_NET_TRANSPORT, } from '@opentelemetry/semantic-conventions'; -import { - ATTR_DB_COLLECTION_NAME, - ATTR_DB_NAMESPACE, - ATTR_DB_OPERATION_NAME, - ATTR_DB_QUERY_TEXT, - ATTR_DB_SYSTEM_NAME, - ATTR_DB_USER, -} from './semconv'; -import { mapSystem } from './utils'; const contextSymbol = Symbol('opentelemetry.instrumentation-knex.context'); const DEFAULT_CONFIG: KnexInstrumentationConfig = { @@ -150,9 +146,6 @@ export class KnexInstrumentation extends InstrumentationBase any) { return function wrapped_logging_method(this: any, query: any) { const config = this.client.config; @@ -171,7 +164,7 @@ export class KnexInstrumentation extends InstrumentationBase Date: Fri, 16 May 2025 14:38:50 +0200 Subject: [PATCH 5/9] feat(instrumentation-knex): Use semconvStabilityFromStr Use semconvStabilityFromStr from @opentelemetry/instrumentation, to avoid duplicating code. --- .../src/instrumentation.ts | 18 +++++---------- .../src/internal-types.ts | 23 ------------------- 2 files changed, 6 insertions(+), 35 deletions(-) delete mode 100644 plugins/node/opentelemetry-instrumentation-knex/src/internal-types.ts diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts index f42bb18750..1f13c5746f 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts @@ -23,12 +23,12 @@ import { InstrumentationNodeModuleDefinition, InstrumentationNodeModuleFile, isWrapped, + SemconvStability, + semconvStabilityFromStr, } from '@opentelemetry/instrumentation'; import * as utils from './utils'; import { mapSystem } from './utils'; import { KnexInstrumentationConfig } from './types'; -import { SemconvStability } from './internal-types'; -import { getStringListFromEnv } from '@opentelemetry/core'; import { ATTR_DB_COLLECTION_NAME, ATTR_DB_NAMESPACE, @@ -60,16 +60,10 @@ export class KnexInstrumentation extends InstrumentationBase Date: Fri, 16 May 2025 21:15:34 +0200 Subject: [PATCH 6/9] feat(instrumentation-knex): Drop core from dependencies --- package-lock.json | 2 -- plugins/node/opentelemetry-instrumentation-knex/package.json | 1 - 2 files changed, 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f9d0f88c22..f8ae23794b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36147,7 +36147,6 @@ "version": "0.46.0", "license": "Apache-2.0", "dependencies": { - "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.201.0", "@opentelemetry/semantic-conventions": "^1.33.0" }, @@ -45017,7 +45016,6 @@ "requires": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^2.0.0", - "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.201.0", "@opentelemetry/sdk-trace-base": "^2.0.0", "@opentelemetry/sdk-trace-node": "^2.0.0", diff --git a/plugins/node/opentelemetry-instrumentation-knex/package.json b/plugins/node/opentelemetry-instrumentation-knex/package.json index 8322744265..3d622217b6 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/package.json +++ b/plugins/node/opentelemetry-instrumentation-knex/package.json @@ -56,7 +56,6 @@ "typescript": "5.0.4" }, "dependencies": { - "@opentelemetry/core": "^2.0.0", "@opentelemetry/instrumentation": "^0.201.0", "@opentelemetry/semantic-conventions": "^1.33.0" }, From a8d4c0561361fdef67639bc4cb5ec23ef3d2d8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Mon, 19 May 2025 17:21:20 +0200 Subject: [PATCH 7/9] feat(instrumentation-knex): Update instrumentation version --- package-lock.json | 66 ++++++++++++++++++- .../package.json | 2 +- .../src/instrumentation.ts | 7 +- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index f8ae23794b..c71b23d18c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36147,7 +36147,7 @@ "version": "0.46.0", "license": "Apache-2.0", "dependencies": { - "@opentelemetry/instrumentation": "^0.201.0", + "@opentelemetry/instrumentation": "^0.201.1", "@opentelemetry/semantic-conventions": "^1.33.0" }, "devDependencies": { @@ -36171,6 +36171,37 @@ "@opentelemetry/api": "^1.3.0" } }, + "plugins/node/opentelemetry-instrumentation-knex/node_modules/@opentelemetry/api-logs": { + "version": "0.201.1", + "resolved": "https://registry.npmjs.org/@opentelemetry/api-logs/-/api-logs-0.201.1.tgz", + "integrity": "sha512-IxcFDP1IGMDemVFG2by/AMK+/o6EuBQ8idUq3xZ6MxgQGeumYZuX5OwR0h9HuvcUc/JPjQGfU5OHKIKYDJcXeA==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/api": "^1.3.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "plugins/node/opentelemetry-instrumentation-knex/node_modules/@opentelemetry/instrumentation": { + "version": "0.201.1", + "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.201.1.tgz", + "integrity": "sha512-6EOSoT2zcyBM3VryAzn35ytjRrOMeaWZyzQ/PHVfxoXp5rMf7UUgVToqxOhQffKOHtC7Dma4bHt+DuwIBBZyZA==", + "license": "Apache-2.0", + "dependencies": { + "@opentelemetry/api-logs": "0.201.1", + "@types/shimmer": "^1.2.0", + "import-in-the-middle": "^1.8.1", + "require-in-the-middle": "^7.1.1", + "shimmer": "^1.2.1" + }, + "engines": { + "node": "^18.19.0 || >=20.6.0" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.3.0" + } + }, "plugins/node/opentelemetry-instrumentation-knex/node_modules/@types/node": { "version": "18.18.14", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.14.tgz", @@ -36180,6 +36211,12 @@ "undici-types": "~5.26.4" } }, + "plugins/node/opentelemetry-instrumentation-knex/node_modules/@types/shimmer": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@types/shimmer/-/shimmer-1.2.0.tgz", + "integrity": "sha512-UE7oxhQLLd9gub6JKIAhDq06T0F6FnztwMNRvYgjeQSBeMc1ZG/tA47EwfduvkuQS8apbkM/lpLpWsaCeYsXVg==", + "license": "MIT" + }, "plugins/node/opentelemetry-instrumentation-knex/node_modules/typescript": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", @@ -45016,7 +45053,7 @@ "requires": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^2.0.0", - "@opentelemetry/instrumentation": "^0.201.0", + "@opentelemetry/instrumentation": "^0.201.1", "@opentelemetry/sdk-trace-base": "^2.0.0", "@opentelemetry/sdk-trace-node": "^2.0.0", "@opentelemetry/semantic-conventions": "^1.33.0", @@ -45030,6 +45067,26 @@ "typescript": "5.0.4" }, "dependencies": { + "@opentelemetry/api-logs": { + "version": "0.201.1", + "resolved": "https://registry.npmjs.org/@opentelemetry/api-logs/-/api-logs-0.201.1.tgz", + "integrity": "sha512-IxcFDP1IGMDemVFG2by/AMK+/o6EuBQ8idUq3xZ6MxgQGeumYZuX5OwR0h9HuvcUc/JPjQGfU5OHKIKYDJcXeA==", + "requires": { + "@opentelemetry/api": "^1.3.0" + } + }, + "@opentelemetry/instrumentation": { + "version": "0.201.1", + "resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.201.1.tgz", + "integrity": "sha512-6EOSoT2zcyBM3VryAzn35ytjRrOMeaWZyzQ/PHVfxoXp5rMf7UUgVToqxOhQffKOHtC7Dma4bHt+DuwIBBZyZA==", + "requires": { + "@opentelemetry/api-logs": "0.201.1", + "@types/shimmer": "^1.2.0", + "import-in-the-middle": "^1.8.1", + "require-in-the-middle": "^7.1.1", + "shimmer": "^1.2.1" + } + }, "@types/node": { "version": "18.18.14", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.18.14.tgz", @@ -45039,6 +45096,11 @@ "undici-types": "~5.26.4" } }, + "@types/shimmer": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@types/shimmer/-/shimmer-1.2.0.tgz", + "integrity": "sha512-UE7oxhQLLd9gub6JKIAhDq06T0F6FnztwMNRvYgjeQSBeMc1ZG/tA47EwfduvkuQS8apbkM/lpLpWsaCeYsXVg==" + }, "typescript": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", diff --git a/plugins/node/opentelemetry-instrumentation-knex/package.json b/plugins/node/opentelemetry-instrumentation-knex/package.json index 3d622217b6..30fdebb843 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/package.json +++ b/plugins/node/opentelemetry-instrumentation-knex/package.json @@ -56,7 +56,7 @@ "typescript": "5.0.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.201.0", + "@opentelemetry/instrumentation": "^0.201.1", "@opentelemetry/semantic-conventions": "^1.33.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-knex#readme" diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts index 1f13c5746f..bc13842a77 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/instrumentation.ts @@ -27,7 +27,6 @@ import { semconvStabilityFromStr, } from '@opentelemetry/instrumentation'; import * as utils from './utils'; -import { mapSystem } from './utils'; import { KnexInstrumentationConfig } from './types'; import { ATTR_DB_COLLECTION_NAME, @@ -55,7 +54,7 @@ const DEFAULT_CONFIG: KnexInstrumentationConfig = { }; export class KnexInstrumentation extends InstrumentationBase { - private _semconvStability: SemconvStability = SemconvStability.OLD; + private _semconvStability: SemconvStability; constructor(config: KnexInstrumentationConfig = {}) { super(PACKAGE_NAME, PACKAGE_VERSION, { ...DEFAULT_CONFIG, ...config }); @@ -160,7 +159,7 @@ export class KnexInstrumentation extends InstrumentationBase Date: Wed, 21 May 2025 11:31:11 +0200 Subject: [PATCH 8/9] feat(instrumentation-knex): Fix semconv versions --- package-lock.json | 16 ++++++------ .../README.md | 2 +- .../package.json | 2 +- .../src/semconv.ts | 26 +++++++++++++++++++ .../src/utils.ts | 6 ++--- 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 plugins/node/opentelemetry-instrumentation-knex/src/semconv.ts diff --git a/package-lock.json b/package-lock.json index c71b23d18c..07f4c445e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8810,9 +8810,9 @@ } }, "node_modules/@opentelemetry/semantic-conventions": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.33.0.tgz", - "integrity": "sha512-TIpZvE8fiEILFfTlfPnltpBaD3d9/+uQHVCyC3vfdh6WfCXKhNFzoP5RyDDIndfvZC5GrA4pyEDNyjPloJud+w==", + "version": "1.33.1", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.33.1.tgz", + "integrity": "sha512-tBco+nVMoGqJ0LHPKOWlN9o1PX2AA9zxDMgvL210YYXlG9UkMXpiXhsWvvQriZrjOzTXXEpH6jleCgAuVGg3EQ==", "license": "Apache-2.0", "engines": { "node": ">=14" @@ -36148,7 +36148,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.201.1", - "@opentelemetry/semantic-conventions": "^1.33.0" + "@opentelemetry/semantic-conventions": "^1.33.1" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -45056,7 +45056,7 @@ "@opentelemetry/instrumentation": "^0.201.1", "@opentelemetry/sdk-trace-base": "^2.0.0", "@opentelemetry/sdk-trace-node": "^2.0.0", - "@opentelemetry/semantic-conventions": "^1.33.0", + "@opentelemetry/semantic-conventions": "^1.33.1", "@types/mocha": "10.0.10", "@types/node": "18.18.14", "better-sqlite3": "11.0.0", @@ -47303,9 +47303,9 @@ } }, "@opentelemetry/semantic-conventions": { - "version": "1.33.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.33.0.tgz", - "integrity": "sha512-TIpZvE8fiEILFfTlfPnltpBaD3d9/+uQHVCyC3vfdh6WfCXKhNFzoP5RyDDIndfvZC5GrA4pyEDNyjPloJud+w==" + "version": "1.33.1", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.33.1.tgz", + "integrity": "sha512-tBco+nVMoGqJ0LHPKOWlN9o1PX2AA9zxDMgvL210YYXlG9UkMXpiXhsWvvQriZrjOzTXXEpH6jleCgAuVGg3EQ==" }, "@opentelemetry/sql-common": { "version": "file:packages/opentelemetry-sql-common", diff --git a/plugins/node/opentelemetry-instrumentation-knex/README.md b/plugins/node/opentelemetry-instrumentation-knex/README.md index 0a62c03a5a..be61ddce58 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/README.md +++ b/plugins/node/opentelemetry-instrumentation-knex/README.md @@ -56,7 +56,7 @@ registerInstrumentations({ This package uses `@opentelemetry/semantic-conventions` version `1.33+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) -This package is capable of emitting both Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) and [Version 1.33.0](https://github.com/open-telemetry/semantic-conventions/blob/v1.33.0/docs/database/database-metrics.md) +This package is capable of emitting both Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) and [Version 1.33.0](https://github.com/open-telemetry/semantic-conventions/blob/v1.33.0/docs/database/database-spans.md) It is controlled using the environment variable `OTEL_SEMCONV_STABILITY_OPT_IN`, which is a comma separated list of values. The values `database` and `database/dup` control this instrumentation. See details for the behavior of each of these values below. diff --git a/plugins/node/opentelemetry-instrumentation-knex/package.json b/plugins/node/opentelemetry-instrumentation-knex/package.json index 30fdebb843..47710a914e 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/package.json +++ b/plugins/node/opentelemetry-instrumentation-knex/package.json @@ -57,7 +57,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.201.1", - "@opentelemetry/semantic-conventions": "^1.33.0" + "@opentelemetry/semantic-conventions": "^1.33.1" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-knex#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/semconv.ts b/plugins/node/opentelemetry-instrumentation-knex/src/semconv.ts new file mode 100644 index 0000000000..f2a9b5043d --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-knex/src/semconv.ts @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * This file contains a copy of unstable semantic convention definitions + * used by this package. + * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv + */ + +/** + * Enum value "sqlite" for attribute {@link ATTR_DB_SYSTEM_NAME}. + */ +export const DB_SYSTEM_NAME_VALUE_SQLITE = 'sqlite' as const; diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/utils.ts b/plugins/node/opentelemetry-instrumentation-knex/src/utils.ts index 3eb40f1414..bd7495e7c0 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/utils.ts @@ -15,10 +15,8 @@ */ import { Exception } from '@opentelemetry/api'; -import { - DB_SYSTEM_NAME_VALUE_POSTGRESQL, - DB_SYSTEM_NAME_VALUE_SQLITE, -} from '@opentelemetry/semantic-conventions'; +import { DB_SYSTEM_NAME_VALUE_POSTGRESQL } from '@opentelemetry/semantic-conventions'; +import { DB_SYSTEM_NAME_VALUE_SQLITE } from '@opentelemetry/semantic-conventions/incubating'; type KnexError = Error & { code?: string; From 4e43e12309dc8f05db19e78144289bd2369f16ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Wed, 21 May 2025 13:42:15 +0200 Subject: [PATCH 9/9] feat(instrumentation-knex): Fix import --- plugins/node/opentelemetry-instrumentation-knex/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/node/opentelemetry-instrumentation-knex/src/utils.ts b/plugins/node/opentelemetry-instrumentation-knex/src/utils.ts index bd7495e7c0..38fbcce5e3 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-knex/src/utils.ts @@ -16,7 +16,7 @@ import { Exception } from '@opentelemetry/api'; import { DB_SYSTEM_NAME_VALUE_POSTGRESQL } from '@opentelemetry/semantic-conventions'; -import { DB_SYSTEM_NAME_VALUE_SQLITE } from '@opentelemetry/semantic-conventions/incubating'; +import { DB_SYSTEM_NAME_VALUE_SQLITE } from './semconv'; type KnexError = Error & { code?: string;