From 8858e60217dda81a0416c3902e393ef68a60e1df Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Sat, 8 May 2021 10:09:45 +0200 Subject: [PATCH 1/2] moving dev dependency for types to main dependency (#468) Co-authored-by: Valentin Marchaud --- .../opentelemetry-instrumentation-aws-lambda/package.json | 4 ++-- .../node/opentelemetry-instrumentation-bunyan/package.json | 4 ++-- .../node/opentelemetry-instrumentation-express/package.json | 4 ++-- .../node/opentelemetry-instrumentation-graphql/package.json | 4 ++-- .../node/opentelemetry-instrumentation-hapi/package.json | 4 ++-- .../node/opentelemetry-instrumentation-ioredis/package.json | 5 ++--- plugins/node/opentelemetry-instrumentation-koa/package.json | 6 +++--- .../node/opentelemetry-instrumentation-mongodb/package.json | 4 ++-- .../node/opentelemetry-instrumentation-mysql/package.json | 4 ++-- plugins/node/opentelemetry-instrumentation-pg/package.json | 6 +++--- .../node/opentelemetry-instrumentation-pino/package.json | 4 ++-- .../node/opentelemetry-instrumentation-redis/package.json | 4 ++-- .../node/opentelemetry-instrumentation-restify/package.json | 4 ++-- .../package.json | 1 - 14 files changed, 28 insertions(+), 30 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json b/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json index 91f49bc91d..ef41aae7e8 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json @@ -42,7 +42,6 @@ }, "devDependencies": { "@opentelemetry/node": "0.19.0", - "@types/aws-lambda": "8.10.76", "@types/mocha": "7.0.2", "@types/node": "14.14.43", "codecov": "3.8.1", @@ -58,6 +57,7 @@ "@opentelemetry/instrumentation": "^0.19.0", "@opentelemetry/resources": "^0.19.0", "@opentelemetry/semantic-conventions": "^0.19.0", - "@opentelemetry/tracing": "^0.19.0" + "@opentelemetry/tracing": "^0.19.0", + "@types/aws-lambda": "8.10.76" } } diff --git a/plugins/node/opentelemetry-instrumentation-bunyan/package.json b/plugins/node/opentelemetry-instrumentation-bunyan/package.json index 9aea67646a..839cfc40c9 100644 --- a/plugins/node/opentelemetry-instrumentation-bunyan/package.json +++ b/plugins/node/opentelemetry-instrumentation-bunyan/package.json @@ -45,7 +45,6 @@ "@opentelemetry/context-async-hooks": "0.19.0", "@opentelemetry/node": "0.19.0", "@opentelemetry/tracing": "0.19.0", - "@types/bunyan": "1.8.6", "@types/mocha": "7.0.2", "@types/node": "14.14.43", "@types/sinon": "9.0.11", @@ -61,6 +60,7 @@ }, "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", - "@opentelemetry/instrumentation": "^0.19.0" + "@opentelemetry/instrumentation": "^0.19.0", + "@types/bunyan": "1.8.6" } } diff --git a/plugins/node/opentelemetry-instrumentation-express/package.json b/plugins/node/opentelemetry-instrumentation-express/package.json index f8209757d8..0dbef8ab34 100644 --- a/plugins/node/opentelemetry-instrumentation-express/package.json +++ b/plugins/node/opentelemetry-instrumentation-express/package.json @@ -45,7 +45,6 @@ "@opentelemetry/context-async-hooks": "0.19.0", "@opentelemetry/node": "0.19.0", "@opentelemetry/tracing": "0.19.0", - "@types/express": "4.17.11", "@types/mocha": "7.0.2", "@types/node": "14.14.43", "codecov": "3.8.1", @@ -61,6 +60,7 @@ "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/core": "^0.19.0", "@opentelemetry/instrumentation": "^0.19.0", - "@opentelemetry/semantic-conventions": "^0.19.0" + "@opentelemetry/semantic-conventions": "^0.19.0", + "@types/express": "4.17.11" } } diff --git a/plugins/node/opentelemetry-instrumentation-graphql/package.json b/plugins/node/opentelemetry-instrumentation-graphql/package.json index f6fb3af929..8c821bdafc 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/package.json +++ b/plugins/node/opentelemetry-instrumentation-graphql/package.json @@ -44,7 +44,6 @@ }, "devDependencies": { "@opentelemetry/tracing": "0.19.0", - "@types/graphql": "14.5.0", "@types/mocha": "8.2.2", "@types/node": "14.14.43", "codecov": "3.8.1", @@ -58,6 +57,7 @@ }, "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", - "@opentelemetry/instrumentation": "^0.19.0" + "@opentelemetry/instrumentation": "^0.19.0", + "@types/graphql": "14.5.0" } } diff --git a/plugins/node/opentelemetry-instrumentation-hapi/package.json b/plugins/node/opentelemetry-instrumentation-hapi/package.json index eebf3043bf..1ee63dad8b 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/package.json +++ b/plugins/node/opentelemetry-instrumentation-hapi/package.json @@ -45,7 +45,6 @@ "@opentelemetry/context-async-hooks": "0.19.0", "@opentelemetry/node": "0.19.0", "@opentelemetry/tracing": "0.19.0", - "@types/hapi__hapi": "20.0.8", "@types/mocha": "7.0.2", "@types/node": "12.20.11", "codecov": "3.8.1", @@ -60,6 +59,7 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", - "@opentelemetry/semantic-conventions": "^0.19.0" + "@opentelemetry/semantic-conventions": "^0.19.0", + "@types/hapi__hapi": "20.0.8" } } diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/package.json b/plugins/node/opentelemetry-instrumentation-ioredis/package.json index cef7ce084c..7e33ca6563 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/package.json +++ b/plugins/node/opentelemetry-instrumentation-ioredis/package.json @@ -48,10 +48,8 @@ "@opentelemetry/node": "0.19.0", "@opentelemetry/test-utils": "^0.16.0", "@opentelemetry/tracing": "0.19.0", - "@types/ioredis": "4.26.1", "@types/mocha": "7.0.2", "@types/node": "14.14.43", - "@types/shimmer": "1.0.1", "codecov": "3.8.1", "cross-env": "7.0.3", "gts": "3.1.0", @@ -65,6 +63,7 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", - "@opentelemetry/semantic-conventions": "^0.19.0" + "@opentelemetry/semantic-conventions": "^0.19.0", + "@types/ioredis": "4.26.0" } } diff --git a/plugins/node/opentelemetry-instrumentation-koa/package.json b/plugins/node/opentelemetry-instrumentation-koa/package.json index da41d1e00a..1e2c3d6c39 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/package.json +++ b/plugins/node/opentelemetry-instrumentation-koa/package.json @@ -47,8 +47,6 @@ "@opentelemetry/context-async-hooks": "0.19.0", "@opentelemetry/node": "0.19.0", "@opentelemetry/tracing": "0.19.0", - "@types/koa": "2.13.1", - "@types/koa__router": "8.0.4", "@types/mocha": "7.0.2", "@types/node": "12.20.11", "codecov": "3.8.1", @@ -63,6 +61,8 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", - "@opentelemetry/semantic-conventions": "^0.19.0" + "@opentelemetry/semantic-conventions": "^0.19.0", + "@types/koa": "2.13.1", + "@types/koa__router": "8.0.4" } } diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/package.json b/plugins/node/opentelemetry-instrumentation-mongodb/package.json index 600274dd7a..bdaf3a3032 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/package.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/package.json @@ -47,7 +47,6 @@ "@opentelemetry/node": "0.19.0", "@opentelemetry/tracing": "0.19.0", "@types/mocha": "7.0.2", - "@types/mongodb": "3.6.12", "@types/node": "14.14.43", "codecov": "3.8.1", "gts": "3.1.0", @@ -61,6 +60,7 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", - "@opentelemetry/semantic-conventions": "^0.19.0" + "@opentelemetry/semantic-conventions": "^0.19.0", + "@types/mongodb": "3.6.12" } } diff --git a/plugins/node/opentelemetry-instrumentation-mysql/package.json b/plugins/node/opentelemetry-instrumentation-mysql/package.json index 98639bc45b..9382004aca 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql/package.json @@ -45,7 +45,6 @@ "@opentelemetry/test-utils": "^0.16.0", "@opentelemetry/tracing": "0.19.0", "@types/mocha": "7.0.2", - "@types/mysql": "2.15.18", "@types/node": "14.14.43", "codecov": "3.8.1", "gts": "3.1.0", @@ -59,6 +58,7 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", - "@opentelemetry/semantic-conventions": "^0.19.0" + "@opentelemetry/semantic-conventions": "^0.19.0", + "@types/mysql": "2.15.18" } } diff --git a/plugins/node/opentelemetry-instrumentation-pg/package.json b/plugins/node/opentelemetry-instrumentation-pg/package.json index 629bfc7880..2442b4b92c 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/package.json +++ b/plugins/node/opentelemetry-instrumentation-pg/package.json @@ -53,8 +53,6 @@ "@opentelemetry/tracing": "0.19.0", "@types/mocha": "7.0.2", "@types/node": "14.14.43", - "@types/pg": "7.14.11", - "@types/pg-pool": "2.0.2", "codecov": "3.8.1", "cross-env": "7.0.3", "gts": "3.1.0", @@ -68,6 +66,8 @@ }, "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", - "@opentelemetry/instrumentation": "^0.19.0" + "@opentelemetry/instrumentation": "^0.19.0", + "@types/pg": "7.14.11", + "@types/pg-pool": "2.0.2" } } diff --git a/plugins/node/opentelemetry-instrumentation-pino/package.json b/plugins/node/opentelemetry-instrumentation-pino/package.json index e731dbeb6b..9c39e6ca10 100644 --- a/plugins/node/opentelemetry-instrumentation-pino/package.json +++ b/plugins/node/opentelemetry-instrumentation-pino/package.json @@ -47,7 +47,6 @@ "@opentelemetry/tracing": "0.19.0", "@types/mocha": "7.0.2", "@types/node": "14.14.43", - "@types/pino": "6.3.8", "@types/semver": "7.3.5", "@types/sinon": "9.0.11", "codecov": "3.8.1", @@ -64,6 +63,7 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", - "semver": "^7.3.5" + "semver": "^7.3.5", + "@types/pino": "6.3.8" } } diff --git a/plugins/node/opentelemetry-instrumentation-redis/package.json b/plugins/node/opentelemetry-instrumentation-redis/package.json index 91753c361a..c44742b169 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis/package.json @@ -49,7 +49,6 @@ "@opentelemetry/tracing": "0.19.0", "@types/mocha": "7.0.2", "@types/node": "14.14.43", - "@types/redis": "2.8.28", "codecov": "3.8.1", "cross-env": "7.0.3", "gts": "3.1.0", @@ -63,6 +62,7 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", - "@opentelemetry/semantic-conventions": "^0.19.0" + "@opentelemetry/semantic-conventions": "^0.19.0", + "@types/redis": "2.8.28" } } diff --git a/plugins/node/opentelemetry-instrumentation-restify/package.json b/plugins/node/opentelemetry-instrumentation-restify/package.json index 0c9937c21a..85a44efea9 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/package.json +++ b/plugins/node/opentelemetry-instrumentation-restify/package.json @@ -46,7 +46,6 @@ "@opentelemetry/tracing": "0.19.0", "@types/mocha": "7.0.2", "@types/node": "14.14.43", - "@types/restify": "4.3.7", "codecov": "3.8.1", "gts": "3.1.0", "mocha": "7.2.0", @@ -59,6 +58,7 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", - "@opentelemetry/semantic-conventions": "^0.19.0" + "@opentelemetry/semantic-conventions": "^0.19.0", + "@types/restify": "4.3.7" } } diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/package.json b/plugins/web/opentelemetry-instrumentation-user-interaction/package.json index 88f1c973e3..88d6efe061 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/package.json +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/package.json @@ -54,7 +54,6 @@ "@types/jquery": "3.5.5", "@types/mocha": "7.0.2", "@types/node": "14.14.43", - "@types/shimmer": "1.0.1", "@types/sinon": "9.0.11", "@types/webpack-env": "1.16.0", "babel-loader": "8.2.2", From 1386d75d6c5713a96d537a7de27b8399e950f127 Mon Sep 17 00:00:00 2001 From: Severin Neumann Date: Sat, 8 May 2021 10:35:33 +0200 Subject: [PATCH 2/2] Fix semantic conventions for PG and PG Pool (#467) Co-authored-by: vmarchaud --- examples/postgres/package.json | 4 +- .../package.json | 1 + .../src/enums.ts | 27 +++---------- .../src/pg.ts | 18 +++++---- .../src/utils.ts | 23 ++++++----- .../test/pg-pool.test.ts | 38 ++++++++++--------- .../test/pg.test.ts | 33 ++++++++-------- 7 files changed, 69 insertions(+), 75 deletions(-) diff --git a/examples/postgres/package.json b/examples/postgres/package.json index d4525cd9de..bd4414b987 100644 --- a/examples/postgres/package.json +++ b/examples/postgres/package.json @@ -35,11 +35,11 @@ "@opentelemetry/exporter-zipkin": "^0.19.0", "@opentelemetry/instrumentation": "^0.19.0", "@opentelemetry/instrumentation-http": "^0.19.0", - "@opentelemetry/instrumentation-pg": "^0.15.0", + "@opentelemetry/instrumentation-pg": "^0.16.0", "@opentelemetry/node": "^0.19.0", "@opentelemetry/tracing": "^0.19.0", "express": "^4.17.1", - "pg": "^7.12.1" + "pg": "^8.6.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "devDependencies": { diff --git a/plugins/node/opentelemetry-instrumentation-pg/package.json b/plugins/node/opentelemetry-instrumentation-pg/package.json index 2442b4b92c..656f59630b 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/package.json +++ b/plugins/node/opentelemetry-instrumentation-pg/package.json @@ -67,6 +67,7 @@ "dependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/instrumentation": "^0.19.0", + "@opentelemetry/semantic-conventions": "^0.19.0", "@types/pg": "7.14.11", "@types/pg-pool": "2.0.2" } diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/enums.ts b/plugins/node/opentelemetry-instrumentation-pg/src/enums.ts index 435a531c8a..994de4cb4f 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/enums.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/enums.ts @@ -14,27 +14,10 @@ * limitations under the License. */ +// Postgresql specific attributes not covered by semantic conventions export enum AttributeNames { - // required by https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/data-database.md - COMPONENT = 'component', - DB_TYPE = 'db.type', - DB_INSTANCE = 'db.instance', - DB_STATEMENT = 'db.statement', - PEER_ADDRESS = 'peer.address', - PEER_HOSTNAME = 'peer.host', - - // optional - DB_USER = 'db.user', - PEER_PORT = 'peer.port', - PEER_IPV4 = 'peer.ipv4', - PEER_IPV6 = 'peer.ipv6', - PEER_SERVICE = 'peer.service', - - // PG specific -- not specified by spec - PG_VALUES = 'pg.values', - PG_PLAN = 'pg.plan', - - // PG-POOL specific -- not specified by spec - IDLE_TIMEOUT_MILLIS = 'idle.timeout.millis', - MAX_CLIENT = 'max', + PG_VALUES = 'db.postgresql.values', + PG_PLAN = 'db.postgresql.plan', + IDLE_TIMEOUT_MILLIS = 'db.postgresql.idle.timeout.millis', + MAX_CLIENT = 'db.postgresql.max.client', } diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/pg.ts b/plugins/node/opentelemetry-instrumentation-pg/src/pg.ts index 1e2cca96a3..00496a190e 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/pg.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/pg.ts @@ -39,6 +39,10 @@ import { } from './types'; import * as utils from './utils'; import { AttributeNames } from './enums'; +import { + SemanticAttributes, + DbSystemValues, +} from '@opentelemetry/semantic-conventions'; import { VERSION } from './version'; export interface PgInstrumentationConfig extends InstrumentationConfig { @@ -54,7 +58,6 @@ const PG_POOL_COMPONENT = 'pg-pool'; export class PgInstrumentation extends InstrumentationBase { static readonly COMPONENT = 'pg'; - static readonly DB_TYPE = 'sql'; static readonly BASE_SPAN_NAME = PgInstrumentation.COMPONENT + '.query'; @@ -227,13 +230,12 @@ export class PgInstrumentation extends InstrumentationBase { const span = plugin.tracer.startSpan(`${PG_POOL_COMPONENT}.connect`, { kind: SpanKind.CLIENT, attributes: { - [AttributeNames.COMPONENT]: PgInstrumentation.COMPONENT, // required - [AttributeNames.DB_TYPE]: PgInstrumentation.DB_TYPE, // required - [AttributeNames.DB_INSTANCE]: this.options.database, // required - [AttributeNames.PEER_HOSTNAME]: this.options.host, // required - [AttributeNames.PEER_ADDRESS]: jdbcString, // required - [AttributeNames.PEER_PORT]: this.options.port, - [AttributeNames.DB_USER]: this.options.user, + [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, + [SemanticAttributes.DB_NAME]: this.options.database, // required + [SemanticAttributes.NET_PEER_NAME]: this.options.host, // required + [SemanticAttributes.DB_CONNECTION_STRING]: jdbcString, // required + [SemanticAttributes.NET_PEER_PORT]: this.options.port, + [SemanticAttributes.DB_USER]: this.options.user, [AttributeNames.IDLE_TIMEOUT_MILLIS]: this.options .idleTimeoutMillis, [AttributeNames.MAX_CLIENT]: this.options.maxClient, diff --git a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts index 950d4e28f7..8d70757cab 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/src/utils.ts @@ -15,6 +15,10 @@ */ import { Span, SpanStatusCode, Tracer, SpanKind } from '@opentelemetry/api'; +import { + SemanticAttributes, + DbSystemValues, +} from '@opentelemetry/semantic-conventions'; import { AttributeNames } from './enums'; import { PgClientExtended, @@ -51,13 +55,12 @@ function pgStartSpan(tracer: Tracer, client: PgClientExtended, name: string) { return tracer.startSpan(name, { kind: SpanKind.CLIENT, attributes: { - [AttributeNames.COMPONENT]: PgInstrumentation.COMPONENT, // required - [AttributeNames.DB_INSTANCE]: client.connectionParameters.database, // required - [AttributeNames.DB_TYPE]: PgInstrumentation.DB_TYPE, // required - [AttributeNames.PEER_ADDRESS]: jdbcString, // required - [AttributeNames.PEER_HOSTNAME]: client.connectionParameters.host, // required - [AttributeNames.PEER_PORT]: client.connectionParameters.port, - [AttributeNames.DB_USER]: client.connectionParameters.user, + [SemanticAttributes.DB_NAME]: client.connectionParameters.database, // required + [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, // required + [SemanticAttributes.DB_CONNECTION_STRING]: jdbcString, // required + [SemanticAttributes.NET_PEER_NAME]: client.connectionParameters.host, // required + [SemanticAttributes.NET_PEER_PORT]: client.connectionParameters.port, + [SemanticAttributes.DB_USER]: client.connectionParameters.user, }, }); } @@ -76,7 +79,7 @@ export function handleConfigQuery( // Set attributes if (queryConfig.text) { - span.setAttribute(AttributeNames.DB_STATEMENT, queryConfig.text); + span.setAttribute(SemanticAttributes.DB_STATEMENT, queryConfig.text); } if ( instrumentationConfig.enhancedDatabaseReporting && @@ -109,7 +112,7 @@ export function handleParameterizedQuery( const span = pgStartSpan(tracer, this, name); // Set attributes - span.setAttribute(AttributeNames.DB_STATEMENT, query); + span.setAttribute(SemanticAttributes.DB_STATEMENT, query); if (instrumentationConfig.enhancedDatabaseReporting) { span.setAttribute(AttributeNames.PG_VALUES, arrayStringifyHelper(values)); } @@ -129,7 +132,7 @@ export function handleTextQuery( const span = pgStartSpan(tracer, this, name); // Set attributes - span.setAttribute(AttributeNames.DB_STATEMENT, query); + span.setAttribute(SemanticAttributes.DB_STATEMENT, query); return span; } diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts index c28eda899b..df49d97387 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg-pool.test.ts @@ -36,6 +36,10 @@ import * as assert from 'assert'; import * as pg from 'pg'; import * as pgPool from 'pg-pool'; import { AttributeNames } from '../src/enums'; +import { + SemanticAttributes, + DbSystemValues, +} from '@opentelemetry/semantic-conventions'; const memoryExporter = new InMemorySpanExporter(); @@ -52,25 +56,23 @@ const CONFIG = { }; const DEFAULT_PGPOOL_ATTRIBUTES = { - [AttributeNames.COMPONENT]: PgInstrumentation.COMPONENT, - [AttributeNames.DB_INSTANCE]: CONFIG.database, - [AttributeNames.DB_TYPE]: PgInstrumentation.DB_TYPE, - [AttributeNames.PEER_HOSTNAME]: CONFIG.host, - [AttributeNames.PEER_ADDRESS]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, - [AttributeNames.PEER_PORT]: CONFIG.port, - [AttributeNames.DB_USER]: CONFIG.user, + [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, + [SemanticAttributes.DB_NAME]: CONFIG.database, + [SemanticAttributes.NET_PEER_NAME]: CONFIG.host, + [SemanticAttributes.DB_CONNECTION_STRING]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, + [SemanticAttributes.NET_PEER_PORT]: CONFIG.port, + [SemanticAttributes.DB_USER]: CONFIG.user, [AttributeNames.MAX_CLIENT]: CONFIG.maxClient, [AttributeNames.IDLE_TIMEOUT_MILLIS]: CONFIG.idleTimeoutMillis, }; const DEFAULT_PG_ATTRIBUTES = { - [AttributeNames.COMPONENT]: PgInstrumentation.COMPONENT, - [AttributeNames.DB_INSTANCE]: CONFIG.database, - [AttributeNames.DB_TYPE]: PgInstrumentation.DB_TYPE, - [AttributeNames.PEER_HOSTNAME]: CONFIG.host, - [AttributeNames.PEER_ADDRESS]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, - [AttributeNames.PEER_PORT]: CONFIG.port, - [AttributeNames.DB_USER]: CONFIG.user, + [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, + [SemanticAttributes.DB_NAME]: CONFIG.database, + [SemanticAttributes.NET_PEER_NAME]: CONFIG.host, + [SemanticAttributes.DB_CONNECTION_STRING]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, + [SemanticAttributes.NET_PEER_PORT]: CONFIG.port, + [SemanticAttributes.DB_USER]: CONFIG.user, }; const unsetStatus: SpanStatus = { @@ -162,7 +164,7 @@ describe('pg-pool@2.x', () => { }; const pgAttributes = { ...DEFAULT_PG_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', + [SemanticAttributes.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; const span = provider.getTracer('test-pg-pool').startSpan('test span'); @@ -186,7 +188,7 @@ describe('pg-pool@2.x', () => { }; const pgAttributes = { ...DEFAULT_PG_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', + [SemanticAttributes.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; const parentSpan = provider @@ -242,7 +244,7 @@ describe('pg-pool@2.x', () => { }; const pgAttributes = { ...DEFAULT_PG_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', + [SemanticAttributes.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; const span = provider.getTracer('test-pg-pool').startSpan('test span'); @@ -261,7 +263,7 @@ describe('pg-pool@2.x', () => { }; const pgAttributes = { ...DEFAULT_PG_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', + [SemanticAttributes.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; const parentSpan = provider diff --git a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts index 4182cfd015..4837846bca 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts +++ b/plugins/node/opentelemetry-instrumentation-pg/test/pg.test.ts @@ -36,6 +36,10 @@ import * as assert from 'assert'; import type * as pg from 'pg'; import { PgInstrumentation } from '../src'; import { AttributeNames } from '../src/enums'; +import { + SemanticAttributes, + DbSystemValues, +} from '@opentelemetry/semantic-conventions'; const memoryExporter = new InMemorySpanExporter(); @@ -50,13 +54,12 @@ const CONFIG = { }; const DEFAULT_ATTRIBUTES = { - [AttributeNames.COMPONENT]: PgInstrumentation.COMPONENT, - [AttributeNames.DB_INSTANCE]: CONFIG.database, - [AttributeNames.DB_TYPE]: PgInstrumentation.DB_TYPE, - [AttributeNames.PEER_HOSTNAME]: CONFIG.host, - [AttributeNames.PEER_ADDRESS]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, - [AttributeNames.PEER_PORT]: CONFIG.port, - [AttributeNames.DB_USER]: CONFIG.user, + [SemanticAttributes.DB_SYSTEM]: DbSystemValues.POSTGRESQL, + [SemanticAttributes.DB_NAME]: CONFIG.database, + [SemanticAttributes.NET_PEER_NAME]: CONFIG.host, + [SemanticAttributes.DB_CONNECTION_STRING]: `jdbc:postgresql://${CONFIG.host}:${CONFIG.port}/${CONFIG.database}`, + [SemanticAttributes.NET_PEER_PORT]: CONFIG.port, + [SemanticAttributes.DB_USER]: CONFIG.user, }; const unsetStatus: SpanStatus = { @@ -200,7 +203,7 @@ describe('pg@7.x', () => { it('should intercept client.query(text, callback)', done => { const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: 'SELECT NOW()', + [SemanticAttributes.DB_STATEMENT]: 'SELECT NOW()', }; const events: TimedEvent[] = []; const span = tracer.startSpan('test span'); @@ -220,7 +223,7 @@ describe('pg@7.x', () => { const values = ['0']; const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, + [SemanticAttributes.DB_STATEMENT]: query, }; const events: TimedEvent[] = []; const span = tracer.startSpan('test span'); @@ -239,7 +242,7 @@ describe('pg@7.x', () => { const query = 'SELECT NOW()'; const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, + [SemanticAttributes.DB_STATEMENT]: query, }; const events: TimedEvent[] = []; const span = tracer.startSpan('test span'); @@ -261,7 +264,7 @@ describe('pg@7.x', () => { const query = 'SELECT NOW()'; const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, + [SemanticAttributes.DB_STATEMENT]: query, }; const events: TimedEvent[] = []; const span = tracer.startSpan('test span'); @@ -281,7 +284,7 @@ describe('pg@7.x', () => { const values = ['0']; const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, + [SemanticAttributes.DB_STATEMENT]: query, }; const events: TimedEvent[] = []; const span = tracer.startSpan('test span'); @@ -301,7 +304,7 @@ describe('pg@7.x', () => { const values = ['0']; const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, + [SemanticAttributes.DB_STATEMENT]: query, }; const events: TimedEvent[] = []; const span = tracer.startSpan('test span'); @@ -326,7 +329,7 @@ describe('pg@7.x', () => { const attributes = { ...DEFAULT_ATTRIBUTES, [AttributeNames.PG_PLAN]: name, - [AttributeNames.DB_STATEMENT]: query, + [SemanticAttributes.DB_STATEMENT]: query, }; const events: TimedEvent[] = []; const span = tracer.startSpan('test span'); @@ -350,7 +353,7 @@ describe('pg@7.x', () => { const query = 'SELECT NOW()'; const attributes = { ...DEFAULT_ATTRIBUTES, - [AttributeNames.DB_STATEMENT]: query, + [SemanticAttributes.DB_STATEMENT]: query, }; const events: TimedEvent[] = []; const span = tracer.startSpan('test span');