From a27311d04e65cbecf13a1e69ea27cfc9204bba9d Mon Sep 17 00:00:00 2001 From: Nathan Sarang-Walters Date: Tue, 10 Dec 2024 13:23:01 -0800 Subject: [PATCH 1/4] chore(instrumentation-pg): Unpin @opentelemetry/semantic-conventions --- package-lock.json | 17 ++--------------- .../package.json | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index f93d0b9a64..f77ec43423 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38370,7 +38370,7 @@ "dependencies": { "@opentelemetry/core": "^1.26.0", "@opentelemetry/instrumentation": "^0.56.0", - "@opentelemetry/semantic-conventions": "1.27.0", + "@opentelemetry/semantic-conventions": "^1.27.0", "@opentelemetry/sql-common": "^0.40.1", "@types/pg": "8.6.1", "@types/pg-pool": "2.0.6" @@ -38401,14 +38401,6 @@ "@opentelemetry/api": "^1.3.0" } }, - "plugins/node/opentelemetry-instrumentation-pg/node_modules/@opentelemetry/semantic-conventions": { - "version": "1.27.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.27.0.tgz", - "integrity": "sha512-sAay1RrB+ONOem0OZanAR1ZI/k7yDpnOQSQmTMuGImUQb2y8EbSaCJ94FQluM74xoU03vlb2d2U90hZluL6nQg==", - "engines": { - "node": ">=14" - } - }, "plugins/node/opentelemetry-instrumentation-pg/node_modules/@types/mocha": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz", @@ -48413,7 +48405,7 @@ "@opentelemetry/instrumentation": "^0.56.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", - "@opentelemetry/semantic-conventions": "1.27.0", + "@opentelemetry/semantic-conventions": "^1.27.0", "@opentelemetry/sql-common": "^0.40.1", "@types/mocha": "7.0.2", "@types/node": "18.18.14", @@ -48431,11 +48423,6 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/semantic-conventions": { - "version": "1.27.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.27.0.tgz", - "integrity": "sha512-sAay1RrB+ONOem0OZanAR1ZI/k7yDpnOQSQmTMuGImUQb2y8EbSaCJ94FQluM74xoU03vlb2d2U90hZluL6nQg==" - }, "@types/mocha": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-7.0.2.tgz", diff --git a/plugins/node/opentelemetry-instrumentation-pg/package.json b/plugins/node/opentelemetry-instrumentation-pg/package.json index 4bf814a247..efcf4e9ae0 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/package.json +++ b/plugins/node/opentelemetry-instrumentation-pg/package.json @@ -71,7 +71,7 @@ "dependencies": { "@opentelemetry/core": "^1.26.0", "@opentelemetry/instrumentation": "^0.56.0", - "@opentelemetry/semantic-conventions": "1.27.0", + "@opentelemetry/semantic-conventions": "^1.27.0", "@opentelemetry/sql-common": "^0.40.1", "@types/pg": "8.6.1", "@types/pg-pool": "2.0.6" From 3a42a6a692da91d9d7e2a0aaa7b6375d3eaf1a5e Mon Sep 17 00:00:00 2001 From: Nathan Sarang-Walters Date: Wed, 11 Dec 2024 11:05:49 -0800 Subject: [PATCH 2/4] Inline incubating constants from semantic-conventions --- .../src/instrumentation.ts | 2 +- .../src/semantic-conventions.ts | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts index 933796be7c..4a7b3a53dd 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/instrumentation.ts @@ -65,7 +65,7 @@ import { METRIC_DB_CLIENT_OPERATION_DURATION, ATTR_DB_NAMESPACE, ATTR_DB_OPERATION_NAME, -} from '@opentelemetry/semantic-conventions/incubating'; +} from './semantic-conventions'; export class PgInstrumentation extends InstrumentationBase { private _operationDuration!: Histogram; diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts b/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts new file mode 100644 index 0000000000..8b75be16b5 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts @@ -0,0 +1,59 @@ +/** + * These constants are considered experimental exports of `@opentelemetry/semantic-conventions`. + * They're being inlined until they're officially exported by `@opentelemetry/semantic-conventions`. + */ + +/** + * The number of connections that are currently in state described by the `state` attribute + * + * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export declare const METRIC_DB_CLIENT_CONNECTION_COUNT: 'db.client.connection.count'; + +/** + * The number of pending requests for an open connection, cumulative for the entire pool + * + * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export declare const METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS: 'db.client.connection.pending_requests'; + +/** + * Duration of database client operations. + * + * @note Batch operations **SHOULD** be recorded as a single operation. + * + * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export declare const METRIC_DB_CLIENT_OPERATION_DURATION: 'db.client.operation.duration'; + +/** + * The name of the database, fully qualified within the server address and port. + * + * @example customers + * + * @example test.users + * + * @note If a database system has multiple namespace components, they **SHOULD** be concatenated (potentially using database system specific conventions) from most general to most specific namespace component, and more specific namespaces **SHOULD** **NOT** be captured without the more general namespaces, to ensure that "startswith" queries for the more general namespaces will be valid. + * Semantic conventions for individual database systems **SHOULD** document what `db.namespace` means in the context of that system. + * It is RECOMMENDED to capture the value as provided by the application without attempting to do any case normalization. + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export declare const ATTR_DB_NAMESPACE: 'db.namespace'; + +/** + * The name of the operation or command being executed. + * + * @example findAndModify + * + * @example HMSET + * + * @example SELECT + * + * @note It is RECOMMENDED to capture the value as provided by the application without attempting to do any case normalization. + * If the operation name is parsed from the query text, it **SHOULD** be the first operation name found in the query. + * For batch operations, if the individual operations are known to have the same operation name then that operation name **SHOULD** be used prepended by `BATCH `, otherwise `db.operation.name` **SHOULD** be `BATCH` or some other database system specific term if more applicable. + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export declare const ATTR_DB_OPERATION_NAME: 'db.operation.name'; From 514a1d568b4757d22bd95d35bede5e6194375254 Mon Sep 17 00:00:00 2001 From: Nathan Sarang-Walters Date: Wed, 11 Dec 2024 11:13:11 -0800 Subject: [PATCH 3/4] Add missing header --- .../src/semantic-conventions.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts b/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts index 8b75be16b5..9157413748 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts @@ -1,3 +1,19 @@ +/* + * 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. + */ + /** * These constants are considered experimental exports of `@opentelemetry/semantic-conventions`. * They're being inlined until they're officially exported by `@opentelemetry/semantic-conventions`. From 6a07e556dd7cb9829f237d4f162814f88f898b17 Mon Sep 17 00:00:00 2001 From: Nathan Sarang-Walters Date: Wed, 11 Dec 2024 11:34:59 -0800 Subject: [PATCH 4/4] Inline more constants; fix failing tests --- .../src/semantic-conventions.ts | 41 ++++++++++++++++--- .../src/utils.ts | 2 +- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts b/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts index 9157413748..d25fb1137a 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/semantic-conventions.ts @@ -24,14 +24,44 @@ * * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. */ -export declare const METRIC_DB_CLIENT_CONNECTION_COUNT: 'db.client.connection.count'; +export const METRIC_DB_CLIENT_CONNECTION_COUNT = 'db.client.connection.count'; /** * The number of pending requests for an open connection, cumulative for the entire pool * * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. */ -export declare const METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS: 'db.client.connection.pending_requests'; +export const METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS = + 'db.client.connection.pending_requests'; + +/** + * The name of the connection pool; unique within the instrumented application. In case the connection pool implementation doesn't provide a name, instrumentation **SHOULD** use a combination of parameters that would make the name unique, for example, combining attributes `server.address`, `server.port`, and `db.namespace`, formatted as `server.address:server.port/db.namespace`. Instrumentations that generate connection pool name following different patterns **SHOULD** document it. + * + * @example myDataSource + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const ATTR_DB_CLIENT_CONNECTION_POOL_NAME = + 'db.client.connection.pool.name'; + +/** + * The state of a connection in the pool + * + * @example idle + * + * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. + */ +export const ATTR_DB_CLIENT_CONNECTION_STATE = 'db.client.connection.state'; + +/** + * Enum value "idle" for attribute {@link ATTR_DB_CLIENT_CONNECTION_STATE}. + */ +export const DB_CLIENT_CONNECTION_STATE_VALUE_IDLE = 'idle'; + +/** + * Enum value "used" for attribute {@link ATTR_DB_CLIENT_CONNECTION_STATE}. + */ +export const DB_CLIENT_CONNECTION_STATE_VALUE_USED = 'used'; /** * Duration of database client operations. @@ -40,7 +70,8 @@ export declare const METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS: 'db.client.co * * @experimental This metric is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. */ -export declare const METRIC_DB_CLIENT_OPERATION_DURATION: 'db.client.operation.duration'; +export const METRIC_DB_CLIENT_OPERATION_DURATION = + 'db.client.operation.duration'; /** * The name of the database, fully qualified within the server address and port. @@ -55,7 +86,7 @@ export declare const METRIC_DB_CLIENT_OPERATION_DURATION: 'db.client.operation.d * * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. */ -export declare const ATTR_DB_NAMESPACE: 'db.namespace'; +export const ATTR_DB_NAMESPACE = 'db.namespace'; /** * The name of the operation or command being executed. @@ -72,4 +103,4 @@ export declare const ATTR_DB_NAMESPACE: 'db.namespace'; * * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. */ -export declare const ATTR_DB_OPERATION_NAME: 'db.operation.name'; +export const ATTR_DB_OPERATION_NAME = 'db.operation.name'; diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts index de21084a95..48e9d6b8f7 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts @@ -42,7 +42,7 @@ import { ATTR_DB_CLIENT_CONNECTION_STATE, DB_CLIENT_CONNECTION_STATE_VALUE_USED, DB_CLIENT_CONNECTION_STATE_VALUE_IDLE, -} from '@opentelemetry/semantic-conventions/incubating'; +} from './semantic-conventions'; import { PgClientExtended, PostgresCallback,