From ccf1efe0cf8f144ab0d0aab490dfff499bd3158e Mon Sep 17 00:00:00 2001 From: Jarle Fosen Date: Thu, 10 Aug 2023 14:09:27 +0200 Subject: [PATCH 1/4] fix(redis-4): omit credentials from db.connection_string span attribute (#1562) * fix(redis-4): omit credentials from db.connection_string span attribute * Reconstruct non-sensitive db.connection_string using built-in URL.href * style(redis-4): Fix code style according to community standards * fix(redis-4): Log error on connection string sanitization failure --------- Co-authored-by: Amir Blum Co-authored-by: Haddas Bronfman <85441461+haddasbronfman@users.noreply.github.com> --- .../src/instrumentation.ts | 4 +- .../src/utils.ts | 33 +++++++++- .../test/redis.test.ts | 63 ++++++++++++++++++- 3 files changed, 95 insertions(+), 5 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts index 4bf503e6c4..07628f2055 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-redis-4/src/instrumentation.ts @@ -354,7 +354,7 @@ export class RedisInstrumentation extends InstrumentationBase { return function patchedConnect(this: any): Promise { const options = this.options; - const attributes = getClientAttributes(options); + const attributes = getClientAttributes(this._diag, options); const span = plugin.tracer.startSpan( `${RedisInstrumentation.COMPONENT}-connect`, @@ -405,7 +405,7 @@ export class RedisInstrumentation extends InstrumentationBase { const dbStatementSerializer = this._config?.dbStatementSerializer || defaultDbStatementSerializer; - const attributes = getClientAttributes(clientOptions); + const attributes = getClientAttributes(this._diag, clientOptions); try { const dbStatement = dbStatementSerializer(commandName, commandArgs); diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/src/utils.ts b/plugins/node/opentelemetry-instrumentation-redis-4/src/utils.ts index f102606474..336bf7f2b2 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-redis-4/src/utils.ts @@ -13,16 +13,45 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { DiagLogger } from '@opentelemetry/api'; import { DbSystemValues, SemanticAttributes, } from '@opentelemetry/semantic-conventions'; -export function getClientAttributes(options: any) { +export function getClientAttributes(diag: DiagLogger, options: any) { return { [SemanticAttributes.DB_SYSTEM]: DbSystemValues.REDIS, [SemanticAttributes.NET_PEER_NAME]: options?.socket?.host, [SemanticAttributes.NET_PEER_PORT]: options?.socket?.port, - [SemanticAttributes.DB_CONNECTION_STRING]: options?.url, + [SemanticAttributes.DB_CONNECTION_STRING]: + removeCredentialsFromDBConnectionStringAttribute(diag, options?.url), }; } + +/** + * removeCredentialsFromDBConnectionStringAttribute removes basic auth from url and user_pwd from query string + * + * Examples: + * redis://user:pass@localhost:6379/mydb => redis://localhost:6379/mydb + * redis://localhost:6379?db=mydb&user_pwd=pass => redis://localhost:6379?db=mydb + */ +function removeCredentialsFromDBConnectionStringAttribute( + diag: DiagLogger, + url?: unknown +): string | undefined { + if (typeof url !== 'string') { + return; + } + + try { + const u = new URL(url); + u.searchParams.delete('user_pwd'); + u.username = ''; + u.password = ''; + return u.href; + } catch (err) { + diag.error('failed to sanitize redis connection url', err); + } + return; +} diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/test/redis.test.ts b/plugins/node/opentelemetry-instrumentation-redis-4/test/redis.test.ts index 615572cf5a..ac5abf5bce 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/test/redis.test.ts +++ b/plugins/node/opentelemetry-instrumentation-redis-4/test/redis.test.ts @@ -220,8 +220,11 @@ describe('redis@^4.0.0', () => { }); it('sets error status on connection failure', async () => { + const redisURL = `redis://${redisTestConfig.host}:${ + redisTestConfig.port + 1 + }`; const newClient = createClient({ - url: `redis://${redisTestConfig.host}:${redisTestConfig.port + 1}`, + url: redisURL, }); await assert.rejects(newClient.connect()); @@ -230,6 +233,64 @@ describe('redis@^4.0.0', () => { assert.strictEqual(span.name, 'redis-connect'); assert.strictEqual(span.status.code, SpanStatusCode.ERROR); + assert.strictEqual( + span.attributes[SemanticAttributes.DB_CONNECTION_STRING], + redisURL + ); + }); + + it('omits basic auth from DB_CONNECTION_STRING span attribute', async () => { + const redisURL = `redis://myuser:mypassword@${redisTestConfig.host}:${ + redisTestConfig.port + 1 + }`; + const expectAttributeConnString = `redis://${redisTestConfig.host}:${ + redisTestConfig.port + 1 + }`; + const newClient = createClient({ + url: redisURL, + }); + + await assert.rejects(newClient.connect()); + + const [span] = getTestSpans(); + + assert.strictEqual(span.name, 'redis-connect'); + assert.strictEqual(span.status.code, SpanStatusCode.ERROR); + assert.strictEqual( + span.attributes[SemanticAttributes.NET_PEER_NAME], + redisTestConfig.host + ); + assert.strictEqual( + span.attributes[SemanticAttributes.DB_CONNECTION_STRING], + expectAttributeConnString + ); + }); + + it('omits user_pwd query parameter from DB_CONNECTION_STRING span attribute', async () => { + const redisURL = `redis://${redisTestConfig.host}:${ + redisTestConfig.port + 1 + }?db=mydb&user_pwd=mypassword`; + const expectAttributeConnString = `redis://${redisTestConfig.host}:${ + redisTestConfig.port + 1 + }?db=mydb`; + const newClient = createClient({ + url: redisURL, + }); + + await assert.rejects(newClient.connect()); + + const [span] = getTestSpans(); + + assert.strictEqual(span.name, 'redis-connect'); + assert.strictEqual(span.status.code, SpanStatusCode.ERROR); + assert.strictEqual( + span.attributes[SemanticAttributes.NET_PEER_NAME], + redisTestConfig.host + ); + assert.strictEqual( + span.attributes[SemanticAttributes.DB_CONNECTION_STRING], + expectAttributeConnString + ); }); }); From 4f1124524aee565c3cfbf3975aa5d3d039377621 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Thu, 10 Aug 2023 14:57:58 +0200 Subject: [PATCH 2/4] fix(deps): update otel core experimental to v0.41.2 (#1628) --- .../opentelemetry-resource-detector-instana/package.json | 2 +- metapackages/auto-instrumentations-node/package.json | 8 ++++---- metapackages/auto-instrumentations-web/package.json | 6 +++--- packages/opentelemetry-test-utils/package.json | 2 +- plugins/node/instrumentation-amqplib/package.json | 2 +- plugins/node/instrumentation-cucumber/package.json | 2 +- plugins/node/instrumentation-dataloader/package.json | 2 +- plugins/node/instrumentation-fs/package.json | 2 +- plugins/node/instrumentation-lru-memoizer/package.json | 2 +- plugins/node/instrumentation-mongoose/package.json | 2 +- plugins/node/instrumentation-socket.io/package.json | 2 +- plugins/node/instrumentation-tedious/package.json | 2 +- .../opentelemetry-instrumentation-aws-lambda/package.json | 2 +- .../opentelemetry-instrumentation-aws-sdk/package.json | 2 +- .../opentelemetry-instrumentation-bunyan/package.json | 2 +- .../opentelemetry-instrumentation-cassandra/package.json | 2 +- .../opentelemetry-instrumentation-connect/package.json | 2 +- .../node/opentelemetry-instrumentation-dns/package.json | 2 +- .../examples/package.json | 4 ++-- .../opentelemetry-instrumentation-express/package.json | 2 +- .../opentelemetry-instrumentation-fastify/package.json | 4 ++-- .../package.json | 2 +- .../opentelemetry-instrumentation-graphql/package.json | 2 +- .../node/opentelemetry-instrumentation-hapi/package.json | 2 +- .../opentelemetry-instrumentation-ioredis/package.json | 2 +- .../node/opentelemetry-instrumentation-knex/package.json | 2 +- .../examples/package.json | 4 ++-- .../node/opentelemetry-instrumentation-koa/package.json | 2 +- .../opentelemetry-instrumentation-memcached/package.json | 2 +- .../examples/package.json | 4 ++-- .../opentelemetry-instrumentation-mongodb/package.json | 2 +- .../examples/package.json | 6 +++--- .../node/opentelemetry-instrumentation-mysql/package.json | 2 +- .../opentelemetry-instrumentation-mysql2/package.json | 2 +- .../package.json | 2 +- .../node/opentelemetry-instrumentation-net/package.json | 2 +- .../node/opentelemetry-instrumentation-pg/package.json | 2 +- .../node/opentelemetry-instrumentation-pino/package.json | 2 +- .../opentelemetry-instrumentation-redis-4/package.json | 2 +- .../examples/package.json | 4 ++-- .../node/opentelemetry-instrumentation-redis/package.json | 2 +- .../opentelemetry-instrumentation-restify/package.json | 2 +- .../opentelemetry-instrumentation-router/package.json | 2 +- .../opentelemetry-instrumentation-winston/package.json | 2 +- .../package.json | 2 +- .../opentelemetry-instrumentation-long-task/package.json | 2 +- .../package.json | 4 ++-- 47 files changed, 60 insertions(+), 60 deletions(-) diff --git a/detectors/node/opentelemetry-resource-detector-instana/package.json b/detectors/node/opentelemetry-resource-detector-instana/package.json index b1918ed6f4..35fb4e0cdc 100644 --- a/detectors/node/opentelemetry-resource-detector-instana/package.json +++ b/detectors/node/opentelemetry-resource-detector-instana/package.json @@ -41,7 +41,7 @@ "devDependencies": { "@opentelemetry/api": "^1.3.0", "@opentelemetry/contrib-test-utils": "^0.34.0", - "@opentelemetry/sdk-node": "^0.41.0", + "@opentelemetry/sdk-node": "^0.41.2", "@types/mocha": "8.2.3", "@types/node": "18.16.19", "@types/semver": "7.5.0", diff --git a/metapackages/auto-instrumentations-node/package.json b/metapackages/auto-instrumentations-node/package.json index 56d43288f5..4b82be75b6 100644 --- a/metapackages/auto-instrumentations-node/package.json +++ b/metapackages/auto-instrumentations-node/package.json @@ -49,7 +49,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/instrumentation-amqplib": "^0.33.0", "@opentelemetry/instrumentation-aws-lambda": "^0.36.0", "@opentelemetry/instrumentation-aws-sdk": "^0.35.0", @@ -64,9 +64,9 @@ "@opentelemetry/instrumentation-fastify": "^0.32.0", "@opentelemetry/instrumentation-generic-pool": "^0.32.0", "@opentelemetry/instrumentation-graphql": "^0.35.0", - "@opentelemetry/instrumentation-grpc": "^0.41.0", + "@opentelemetry/instrumentation-grpc": "^0.41.2", "@opentelemetry/instrumentation-hapi": "^0.32.0", - "@opentelemetry/instrumentation-http": "^0.41.0", + "@opentelemetry/instrumentation-http": "^0.41.2", "@opentelemetry/instrumentation-ioredis": "^0.35.0", "@opentelemetry/instrumentation-knex": "^0.32.0", "@opentelemetry/instrumentation-koa": "^0.35.0", @@ -92,6 +92,6 @@ "@opentelemetry/resource-detector-container": "^0.3.0", "@opentelemetry/resource-detector-gcp": "^0.29.0", "@opentelemetry/resources": "^1.12.0", - "@opentelemetry/sdk-node": "^0.41.0" + "@opentelemetry/sdk-node": "^0.41.2" } } diff --git a/metapackages/auto-instrumentations-web/package.json b/metapackages/auto-instrumentations-web/package.json index e5cc476e7e..79836489d3 100644 --- a/metapackages/auto-instrumentations-web/package.json +++ b/metapackages/auto-instrumentations-web/package.json @@ -59,10 +59,10 @@ "webpack-merge": "5.8.0" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/instrumentation-document-load": "^0.33.0", - "@opentelemetry/instrumentation-fetch": "^0.41.0", + "@opentelemetry/instrumentation-fetch": "^0.41.2", "@opentelemetry/instrumentation-user-interaction": "^0.33.0", - "@opentelemetry/instrumentation-xml-http-request": "^0.41.0" + "@opentelemetry/instrumentation-xml-http-request": "^0.41.2" } } diff --git a/packages/opentelemetry-test-utils/package.json b/packages/opentelemetry-test-utils/package.json index b8e3e3479e..3995735c51 100644 --- a/packages/opentelemetry-test-utils/package.json +++ b/packages/opentelemetry-test-utils/package.json @@ -48,7 +48,7 @@ "dependencies": { "@opentelemetry/core": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.3.1", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/sdk-trace-node": "^1.8.0", "@opentelemetry/resources": "^1.8.0", "@opentelemetry/sdk-trace-base": "^1.8.0", diff --git a/plugins/node/instrumentation-amqplib/package.json b/plugins/node/instrumentation-amqplib/package.json index 9f6a80634d..3505cbb613 100644 --- a/plugins/node/instrumentation-amqplib/package.json +++ b/plugins/node/instrumentation-amqplib/package.json @@ -47,7 +47,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "devDependencies": { diff --git a/plugins/node/instrumentation-cucumber/package.json b/plugins/node/instrumentation-cucumber/package.json index 289c073ea9..d23c06e907 100644 --- a/plugins/node/instrumentation-cucumber/package.json +++ b/plugins/node/instrumentation-cucumber/package.json @@ -66,7 +66,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.36.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-cucumber#readme" diff --git a/plugins/node/instrumentation-dataloader/package.json b/plugins/node/instrumentation-dataloader/package.json index ab90424d92..590b3886fa 100644 --- a/plugins/node/instrumentation-dataloader/package.json +++ b/plugins/node/instrumentation-dataloader/package.json @@ -61,7 +61,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0" + "@opentelemetry/instrumentation": "^0.41.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-dataloader#readme" } diff --git a/plugins/node/instrumentation-fs/package.json b/plugins/node/instrumentation-fs/package.json index 92edeb1c0d..4361e87fec 100644 --- a/plugins/node/instrumentation-fs/package.json +++ b/plugins/node/instrumentation-fs/package.json @@ -59,7 +59,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-fs#readme" diff --git a/plugins/node/instrumentation-lru-memoizer/package.json b/plugins/node/instrumentation-lru-memoizer/package.json index 506350a388..ceccfb35ea 100644 --- a/plugins/node/instrumentation-lru-memoizer/package.json +++ b/plugins/node/instrumentation-lru-memoizer/package.json @@ -57,7 +57,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0" + "@opentelemetry/instrumentation": "^0.41.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-lru-memoizer#readme" } diff --git a/plugins/node/instrumentation-mongoose/package.json b/plugins/node/instrumentation-mongoose/package.json index 71cda93208..5f320f246f 100644 --- a/plugins/node/instrumentation-mongoose/package.json +++ b/plugins/node/instrumentation-mongoose/package.json @@ -61,7 +61,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-mongoose#readme" diff --git a/plugins/node/instrumentation-socket.io/package.json b/plugins/node/instrumentation-socket.io/package.json index eb26da2b1f..1e64ffb84a 100644 --- a/plugins/node/instrumentation-socket.io/package.json +++ b/plugins/node/instrumentation-socket.io/package.json @@ -58,7 +58,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-socket.io#readme" diff --git a/plugins/node/instrumentation-tedious/package.json b/plugins/node/instrumentation-tedious/package.json index 59f37c9fd9..b9c4219a8c 100644 --- a/plugins/node/instrumentation-tedious/package.json +++ b/plugins/node/instrumentation-tedious/package.json @@ -62,7 +62,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/tedious": "^4.0.6" }, diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json b/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json index 525f0faab9..415d231a3f 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/package.json @@ -59,7 +59,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/propagator-aws-xray": "^1.3.0", "@opentelemetry/resources": "^1.8.0", "@opentelemetry/semantic-conventions": "^1.0.0", diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json b/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json index 38837b7987..7a382575e5 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/package.json @@ -47,7 +47,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@opentelemetry/propagation-utils": "^0.30.0" }, diff --git a/plugins/node/opentelemetry-instrumentation-bunyan/package.json b/plugins/node/opentelemetry-instrumentation-bunyan/package.json index 9979f86f61..70f8d8e6a0 100644 --- a/plugins/node/opentelemetry-instrumentation-bunyan/package.json +++ b/plugins/node/opentelemetry-instrumentation-bunyan/package.json @@ -64,7 +64,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@types/bunyan": "1.8.8" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-bunyan#readme" diff --git a/plugins/node/opentelemetry-instrumentation-cassandra/package.json b/plugins/node/opentelemetry-instrumentation-cassandra/package.json index 306215305c..82b5e743b1 100644 --- a/plugins/node/opentelemetry-instrumentation-cassandra/package.json +++ b/plugins/node/opentelemetry-instrumentation-cassandra/package.json @@ -64,7 +64,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-cassandra#readme" diff --git a/plugins/node/opentelemetry-instrumentation-connect/package.json b/plugins/node/opentelemetry-instrumentation-connect/package.json index 6eca188dd5..81adf97d4d 100644 --- a/plugins/node/opentelemetry-instrumentation-connect/package.json +++ b/plugins/node/opentelemetry-instrumentation-connect/package.json @@ -59,7 +59,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/connect": "3.4.35" }, diff --git a/plugins/node/opentelemetry-instrumentation-dns/package.json b/plugins/node/opentelemetry-instrumentation-dns/package.json index 14d1a37647..0f6f627514 100644 --- a/plugins/node/opentelemetry-instrumentation-dns/package.json +++ b/plugins/node/opentelemetry-instrumentation-dns/package.json @@ -62,7 +62,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "semver": "^7.3.2" }, diff --git a/plugins/node/opentelemetry-instrumentation-express/examples/package.json b/plugins/node/opentelemetry-instrumentation-express/examples/package.json index 710ad522c8..c829a5ac71 100644 --- a/plugins/node/opentelemetry-instrumentation-express/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-express/examples/package.json @@ -32,9 +32,9 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/instrumentation-express": "0.28.0", - "@opentelemetry/instrumentation-http": "^0.41.0", + "@opentelemetry/instrumentation-http": "^0.41.2", "@opentelemetry/resources": "^1.0.0", "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-node": "^1.0.0", diff --git a/plugins/node/opentelemetry-instrumentation-express/package.json b/plugins/node/opentelemetry-instrumentation-express/package.json index b4924b0984..77de1e3131 100644 --- a/plugins/node/opentelemetry-instrumentation-express/package.json +++ b/plugins/node/opentelemetry-instrumentation-express/package.json @@ -66,7 +66,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/express": "4.17.17" }, diff --git a/plugins/node/opentelemetry-instrumentation-fastify/package.json b/plugins/node/opentelemetry-instrumentation-fastify/package.json index c3950496be..65c8c2cc8c 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/package.json +++ b/plugins/node/opentelemetry-instrumentation-fastify/package.json @@ -48,7 +48,7 @@ "@fastify/express": "^2.0.2", "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-async-hooks": "^1.8.0", - "@opentelemetry/instrumentation-http": "0.41.0", + "@opentelemetry/instrumentation-http": "0.41.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", "@types/express": "4.17.17", @@ -63,7 +63,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-fastify#readme" diff --git a/plugins/node/opentelemetry-instrumentation-generic-pool/package.json b/plugins/node/opentelemetry-instrumentation-generic-pool/package.json index f716d2ba0f..f892564893 100644 --- a/plugins/node/opentelemetry-instrumentation-generic-pool/package.json +++ b/plugins/node/opentelemetry-instrumentation-generic-pool/package.json @@ -61,7 +61,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/generic-pool": "^3.1.9" }, diff --git a/plugins/node/opentelemetry-instrumentation-graphql/package.json b/plugins/node/opentelemetry-instrumentation-graphql/package.json index 8c8eb4d1ca..7f76139977 100644 --- a/plugins/node/opentelemetry-instrumentation-graphql/package.json +++ b/plugins/node/opentelemetry-instrumentation-graphql/package.json @@ -61,7 +61,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0" + "@opentelemetry/instrumentation": "^0.41.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-graphql#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-hapi/package.json b/plugins/node/opentelemetry-instrumentation-hapi/package.json index 0dec59a585..464fca8502 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/package.json +++ b/plugins/node/opentelemetry-instrumentation-hapi/package.json @@ -60,7 +60,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/hapi__hapi": "20.0.13" }, diff --git a/plugins/node/opentelemetry-instrumentation-ioredis/package.json b/plugins/node/opentelemetry-instrumentation-ioredis/package.json index f60baa4ace..d5232bd687 100644 --- a/plugins/node/opentelemetry-instrumentation-ioredis/package.json +++ b/plugins/node/opentelemetry-instrumentation-ioredis/package.json @@ -69,7 +69,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/redis-common": "^0.36.0", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/ioredis4": "npm:@types/ioredis@^4.28.10" diff --git a/plugins/node/opentelemetry-instrumentation-knex/package.json b/plugins/node/opentelemetry-instrumentation-knex/package.json index 1983536b1f..687e6f4ef4 100644 --- a/plugins/node/opentelemetry-instrumentation-knex/package.json +++ b/plugins/node/opentelemetry-instrumentation-knex/package.json @@ -60,7 +60,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.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-koa/examples/package.json b/plugins/node/opentelemetry-instrumentation-koa/examples/package.json index 9875722081..4c21e26897 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-koa/examples/package.json @@ -34,8 +34,8 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.41.0", - "@opentelemetry/instrumentation-http": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", + "@opentelemetry/instrumentation-http": "^0.41.2", "@opentelemetry/instrumentation-koa": "^0.31.0", "@opentelemetry/sdk-trace-node": "^1.0.0", "@opentelemetry/sdk-trace-base": "^1.0.0", diff --git a/plugins/node/opentelemetry-instrumentation-koa/package.json b/plugins/node/opentelemetry-instrumentation-koa/package.json index 8084874db8..7332fa4c26 100644 --- a/plugins/node/opentelemetry-instrumentation-koa/package.json +++ b/plugins/node/opentelemetry-instrumentation-koa/package.json @@ -68,7 +68,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/koa": "2.13.8", "@types/koa__router": "8.0.11" diff --git a/plugins/node/opentelemetry-instrumentation-memcached/package.json b/plugins/node/opentelemetry-instrumentation-memcached/package.json index 47d0761155..2454c18ce2 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/package.json +++ b/plugins/node/opentelemetry-instrumentation-memcached/package.json @@ -63,7 +63,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/memcached": "^2.2.6" }, diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/examples/package.json b/plugins/node/opentelemetry-instrumentation-mongodb/examples/package.json index 3ee2b0c022..3b4f670047 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/examples/package.json @@ -33,8 +33,8 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.41.0", - "@opentelemetry/instrumentation-http": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", + "@opentelemetry/instrumentation-http": "^0.41.2", "@opentelemetry/instrumentation-mongodb": "^0.32.0", "@opentelemetry/sdk-trace-node": "^1.0.0", "@opentelemetry/sdk-trace-base": "^1.0.0", diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/package.json b/plugins/node/opentelemetry-instrumentation-mongodb/package.json index a1c123792c..241426f8fa 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/package.json +++ b/plugins/node/opentelemetry-instrumentation-mongodb/package.json @@ -71,7 +71,7 @@ }, "dependencies": { "@opentelemetry/sdk-metrics": "^1.9.1", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb#readme" diff --git a/plugins/node/opentelemetry-instrumentation-mysql/examples/package.json b/plugins/node/opentelemetry-instrumentation-mysql/examples/package.json index 36a9339882..698bd86aa5 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql/examples/package.json @@ -34,12 +34,12 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.41.0", - "@opentelemetry/instrumentation-http": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", + "@opentelemetry/instrumentation-http": "^0.41.2", "@opentelemetry/instrumentation-mysql": "^0.31.0", "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-node": "^1.0.0", - "@opentelemetry/exporter-metrics-otlp-grpc": "0.33.0", + "@opentelemetry/exporter-metrics-otlp-grpc": "0.41.2", "mysql": "^2.18.1" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", diff --git a/plugins/node/opentelemetry-instrumentation-mysql/package.json b/plugins/node/opentelemetry-instrumentation-mysql/package.json index 52e61596d5..d9a09e3f27 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql/package.json @@ -63,7 +63,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@types/mysql": "2.15.21" }, diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/package.json b/plugins/node/opentelemetry-instrumentation-mysql2/package.json index e2db066922..423274ead7 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/package.json +++ b/plugins/node/opentelemetry-instrumentation-mysql2/package.json @@ -65,7 +65,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@opentelemetry/sql-common": "^0.40.0" }, diff --git a/plugins/node/opentelemetry-instrumentation-nestjs-core/package.json b/plugins/node/opentelemetry-instrumentation-nestjs-core/package.json index 548ecc4d28..7777b1b293 100644 --- a/plugins/node/opentelemetry-instrumentation-nestjs-core/package.json +++ b/plugins/node/opentelemetry-instrumentation-nestjs-core/package.json @@ -73,7 +73,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-nestjs-core#readme" diff --git a/plugins/node/opentelemetry-instrumentation-net/package.json b/plugins/node/opentelemetry-instrumentation-net/package.json index 8272e92008..82584add10 100644 --- a/plugins/node/opentelemetry-instrumentation-net/package.json +++ b/plugins/node/opentelemetry-instrumentation-net/package.json @@ -61,7 +61,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-net#readme" diff --git a/plugins/node/opentelemetry-instrumentation-pg/package.json b/plugins/node/opentelemetry-instrumentation-pg/package.json index 797ffc4633..03caf54269 100644 --- a/plugins/node/opentelemetry-instrumentation-pg/package.json +++ b/plugins/node/opentelemetry-instrumentation-pg/package.json @@ -75,7 +75,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0", "@opentelemetry/sql-common": "^0.40.0", "@types/pg": "8.6.1", diff --git a/plugins/node/opentelemetry-instrumentation-pino/package.json b/plugins/node/opentelemetry-instrumentation-pino/package.json index 3b8d1a76e4..fbca6c4d77 100644 --- a/plugins/node/opentelemetry-instrumentation-pino/package.json +++ b/plugins/node/opentelemetry-instrumentation-pino/package.json @@ -66,7 +66,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0" + "@opentelemetry/instrumentation": "^0.41.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pino#readme" } diff --git a/plugins/node/opentelemetry-instrumentation-redis-4/package.json b/plugins/node/opentelemetry-instrumentation-redis-4/package.json index b9155f4252..84e65f16da 100644 --- a/plugins/node/opentelemetry-instrumentation-redis-4/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis-4/package.json @@ -69,7 +69,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/redis-common": "^0.36.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, diff --git a/plugins/node/opentelemetry-instrumentation-redis/examples/package.json b/plugins/node/opentelemetry-instrumentation-redis/examples/package.json index 3162130ecf..3d6c759807 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/examples/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis/examples/package.json @@ -34,8 +34,8 @@ "@opentelemetry/api": "^1.0.0", "@opentelemetry/exporter-jaeger": "^1.0.0", "@opentelemetry/exporter-zipkin": "^1.0.0", - "@opentelemetry/instrumentation": "^0.41.0", - "@opentelemetry/instrumentation-http": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", + "@opentelemetry/instrumentation-http": "^0.41.2", "@opentelemetry/instrumentation-redis": "^0.32.0", "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-node": "^1.0.0", diff --git a/plugins/node/opentelemetry-instrumentation-redis/package.json b/plugins/node/opentelemetry-instrumentation-redis/package.json index e90fca4e8e..114097676d 100644 --- a/plugins/node/opentelemetry-instrumentation-redis/package.json +++ b/plugins/node/opentelemetry-instrumentation-redis/package.json @@ -70,7 +70,7 @@ "@types/redis": "2.8.32" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/redis-common": "^0.36.0", "@opentelemetry/semantic-conventions": "^1.0.0" }, diff --git a/plugins/node/opentelemetry-instrumentation-restify/package.json b/plugins/node/opentelemetry-instrumentation-restify/package.json index 42b62378b2..10f36902ab 100644 --- a/plugins/node/opentelemetry-instrumentation-restify/package.json +++ b/plugins/node/opentelemetry-instrumentation-restify/package.json @@ -65,7 +65,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-restify#readme" diff --git a/plugins/node/opentelemetry-instrumentation-router/package.json b/plugins/node/opentelemetry-instrumentation-router/package.json index b3b12ed911..8b0a049242 100644 --- a/plugins/node/opentelemetry-instrumentation-router/package.json +++ b/plugins/node/opentelemetry-instrumentation-router/package.json @@ -59,7 +59,7 @@ "typescript": "4.4.4" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/semantic-conventions": "^1.0.0" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-router#readme" diff --git a/plugins/node/opentelemetry-instrumentation-winston/package.json b/plugins/node/opentelemetry-instrumentation-winston/package.json index afd7294be3..713fd7c897 100644 --- a/plugins/node/opentelemetry-instrumentation-winston/package.json +++ b/plugins/node/opentelemetry-instrumentation-winston/package.json @@ -66,7 +66,7 @@ "winston2": "npm:winston@2.4.7" }, "dependencies": { - "@opentelemetry/instrumentation": "^0.41.0" + "@opentelemetry/instrumentation": "^0.41.2" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-winston#readme" } diff --git a/plugins/web/opentelemetry-instrumentation-document-load/package.json b/plugins/web/opentelemetry-instrumentation-document-load/package.json index e32e1c4f54..3abf89be2a 100644 --- a/plugins/web/opentelemetry-instrumentation-document-load/package.json +++ b/plugins/web/opentelemetry-instrumentation-document-load/package.json @@ -77,7 +77,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/sdk-trace-base": "^1.0.0", "@opentelemetry/sdk-trace-web": "^1.15.0", "@opentelemetry/semantic-conventions": "^1.0.0" diff --git a/plugins/web/opentelemetry-instrumentation-long-task/package.json b/plugins/web/opentelemetry-instrumentation-long-task/package.json index 7d0a82ebf0..b78a6af9c6 100644 --- a/plugins/web/opentelemetry-instrumentation-long-task/package.json +++ b/plugins/web/opentelemetry-instrumentation-long-task/package.json @@ -78,7 +78,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/sdk-trace-web": "^1.8.0" }, "peerDependencies": { diff --git a/plugins/web/opentelemetry-instrumentation-user-interaction/package.json b/plugins/web/opentelemetry-instrumentation-user-interaction/package.json index 3528e3619a..bae6996228 100644 --- a/plugins/web/opentelemetry-instrumentation-user-interaction/package.json +++ b/plugins/web/opentelemetry-instrumentation-user-interaction/package.json @@ -50,7 +50,7 @@ "@babel/core": "7.22.10", "@opentelemetry/api": "^1.3.0", "@opentelemetry/context-zone-peer-dep": "^1.8.0", - "@opentelemetry/instrumentation-xml-http-request": "^0.41.0", + "@opentelemetry/instrumentation-xml-http-request": "^0.41.2", "@opentelemetry/sdk-trace-base": "^1.8.0", "@types/jquery": "3.5.16", "@types/mocha": "7.0.2", @@ -80,7 +80,7 @@ }, "dependencies": { "@opentelemetry/core": "^1.8.0", - "@opentelemetry/instrumentation": "^0.41.0", + "@opentelemetry/instrumentation": "^0.41.2", "@opentelemetry/sdk-trace-web": "^1.8.0" }, "peerDependencies": { From 8802eae92d70825d4e8fea526e657ce5f16f8502 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Fri, 11 Aug 2023 07:45:21 +0200 Subject: [PATCH 3/4] chore(deps): update dependency @cucumber/cucumber to v9 (#1623) --- plugins/node/instrumentation-cucumber/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/node/instrumentation-cucumber/package.json b/plugins/node/instrumentation-cucumber/package.json index d23c06e907..34378b3ba1 100644 --- a/plugins/node/instrumentation-cucumber/package.json +++ b/plugins/node/instrumentation-cucumber/package.json @@ -46,7 +46,7 @@ "@opentelemetry/api": "^1.0.0" }, "devDependencies": { - "@cucumber/cucumber": "^8.8.0", + "@cucumber/cucumber": "^9.0.0", "@opentelemetry/api": "^1.0.0", "@opentelemetry/core": "^1.3.1", "@opentelemetry/sdk-trace-base": "^1.3.1", From 704f76f5b84793238bfb9f44ce018f02948738ce Mon Sep 17 00:00:00 2001 From: Chi Ma Date: Sat, 12 Aug 2023 14:11:43 +0700 Subject: [PATCH 4/4] fix(connect): fix wrong rpcMetada.route value not handle nested route (#1555) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(connect): fix wrong rpcMetada.route value not handle nested route * fix: update base on PR feedback * fix: lint issue * Fix PR's feedback * Fix lint issue * Fix typo --------- Co-authored-by: Marc Pichler Co-authored-by: Gerhard Stöbich Co-authored-by: Haddas Bronfman <85441461+haddasbronfman@users.noreply.github.com> --- .../src/instrumentation.ts | 46 ++++++++- .../src/internal-types.ts | 9 +- .../src/utils.ts | 55 +++++++++++ .../test/instrumentation.test.ts | 83 ++++++++++++++++ .../test/utils.test.ts | 96 +++++++++++++++++++ 5 files changed, 285 insertions(+), 4 deletions(-) create mode 100644 plugins/node/opentelemetry-instrumentation-connect/src/utils.ts create mode 100644 plugins/node/opentelemetry-instrumentation-connect/test/utils.test.ts diff --git a/plugins/node/opentelemetry-instrumentation-connect/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-connect/src/instrumentation.ts index a2fce4cd40..97a06d8a37 100644 --- a/plugins/node/opentelemetry-instrumentation-connect/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-connect/src/instrumentation.ts @@ -23,7 +23,7 @@ import { ConnectNames, ConnectTypes, } from './enums/AttributeNames'; -import { Use, UseArgs, UseArgs2 } from './internal-types'; +import { PatchedRequest, Use, UseArgs, UseArgs2 } from './internal-types'; import { VERSION } from './version'; import { InstrumentationBase, @@ -32,6 +32,11 @@ import { isWrapped, } from '@opentelemetry/instrumentation'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { + replaceCurrentStackRoute, + addNewStackLayer, + generateRoute, +} from './utils'; export const ANONYMOUS_NAME = 'anonymous'; @@ -65,6 +70,9 @@ export class ConnectInstrumentation extends InstrumentationBase { if (!isWrapped(patchedApp.use)) { this._wrap(patchedApp, 'use', this._patchUse.bind(this)); } + if (!isWrapped(patchedApp.handle)) { + this._wrap(patchedApp, 'handle', this._patchHandle.bind(this)); + } } private _patchConstructor(original: () => Server): () => Server { @@ -120,14 +128,20 @@ export class ConnectInstrumentation extends InstrumentationBase { if (!instrumentation.isEnabled()) { return (middleWare as any).apply(this, arguments); } - const [resArgIdx, nextArgIdx] = isErrorMiddleware ? [2, 3] : [1, 2]; + const [reqArgIdx, resArgIdx, nextArgIdx] = isErrorMiddleware + ? [1, 2, 3] + : [0, 1, 2]; + const req = arguments[reqArgIdx] as PatchedRequest; const res = arguments[resArgIdx] as ServerResponse; const next = arguments[nextArgIdx] as NextFunction; + replaceCurrentStackRoute(req, routeName); + const rpcMetadata = getRPCMetadata(context.active()); if (routeName && rpcMetadata?.type === RPCType.HTTP) { - rpcMetadata.route = routeName; + rpcMetadata.route = generateRoute(req); } + let spanName = ''; if (routeName) { spanName = `request handler - ${routeName}`; @@ -180,4 +194,30 @@ export class ConnectInstrumentation extends InstrumentationBase { return original.apply(this, args as UseArgs2); }; } + + public _patchHandle(original: Server['handle']): Server['handle'] { + const instrumentation = this; + return function (this: Server): ReturnType { + const [reqIdx, outIdx] = [0, 2]; + const req = arguments[reqIdx] as PatchedRequest; + const out = arguments[outIdx]; + const completeStack = addNewStackLayer(req); + + if (typeof out === 'function') { + arguments[outIdx] = instrumentation._patchOut( + out as NextFunction, + completeStack + ); + } + + return (original as any).apply(this, arguments); + }; + } + + public _patchOut(out: NextFunction, completeStack: () => void): NextFunction { + return function nextFunction(this: NextFunction, ...args: any[]): void { + completeStack(); + return Reflect.apply(out, this, args); + }; + } } diff --git a/plugins/node/opentelemetry-instrumentation-connect/src/internal-types.ts b/plugins/node/opentelemetry-instrumentation-connect/src/internal-types.ts index 15947a401f..b8fce41f36 100644 --- a/plugins/node/opentelemetry-instrumentation-connect/src/internal-types.ts +++ b/plugins/node/opentelemetry-instrumentation-connect/src/internal-types.ts @@ -14,9 +14,16 @@ * limitations under the License. */ -import type { HandleFunction, Server } from 'connect'; +import type { HandleFunction, IncomingMessage, Server } from 'connect'; + +export const _LAYERS_STORE_PROPERTY: unique symbol = Symbol( + 'opentelemetry.instrumentation-connect.request-route-stack' +); export type UseArgs1 = [HandleFunction]; export type UseArgs2 = [string, HandleFunction]; export type UseArgs = UseArgs1 | UseArgs2; export type Use = (...args: UseArgs) => Server; +export type PatchedRequest = { + [_LAYERS_STORE_PROPERTY]: string[]; +} & IncomingMessage; diff --git a/plugins/node/opentelemetry-instrumentation-connect/src/utils.ts b/plugins/node/opentelemetry-instrumentation-connect/src/utils.ts new file mode 100644 index 0000000000..02887ef518 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-connect/src/utils.ts @@ -0,0 +1,55 @@ +/* + * 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. + */ +import { diag } from '@opentelemetry/api'; +import { _LAYERS_STORE_PROPERTY, PatchedRequest } from './internal-types'; + +export const addNewStackLayer = (request: PatchedRequest) => { + if (Array.isArray(request[_LAYERS_STORE_PROPERTY]) === false) { + Object.defineProperty(request, _LAYERS_STORE_PROPERTY, { + enumerable: false, + value: [], + }); + } + request[_LAYERS_STORE_PROPERTY].push('/'); + + const stackLength = request[_LAYERS_STORE_PROPERTY].length; + + return () => { + if (stackLength === request[_LAYERS_STORE_PROPERTY].length) { + request[_LAYERS_STORE_PROPERTY].pop(); + } else { + diag.warn('Connect: Trying to pop the stack multiple time'); + } + }; +}; + +export const replaceCurrentStackRoute = ( + request: PatchedRequest, + newRoute?: string +) => { + if (newRoute) { + request[_LAYERS_STORE_PROPERTY].splice(-1, 1, newRoute); + } +}; + +// generage route from existing stack on request object. +// splash between stack layer will be dedup +// ["/first/", "/second", "/third/"] => /first/second/thrid/ +export const generateRoute = (request: PatchedRequest) => { + return request[_LAYERS_STORE_PROPERTY].reduce( + (acc, sub) => acc.replace(/\/+$/, '') + sub + ); +}; diff --git a/plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts b/plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts index e871885e2b..c6ab9456d2 100644 --- a/plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts +++ b/plugins/node/opentelemetry-instrumentation-connect/test/instrumentation.test.ts @@ -243,5 +243,88 @@ describe('connect', () => { changedRootSpan.spanContext().spanId ); }); + + it('should append nested route in RpcMetadata', async () => { + const rootSpan = tracer.startSpan('root span'); + const rpcMetadata: RPCMetadata = { type: RPCType.HTTP, span: rootSpan }; + app.use((req, res, next) => { + return context.with( + setRPCMetadata( + trace.setSpan(context.active(), rootSpan), + rpcMetadata + ), + next + ); + }); + + const nestedApp = connect(); + + app.use('/foo/', nestedApp); + nestedApp.use('/bar/', (req, res, next) => { + next(); + }); + + await httpRequest.get(`http://localhost:${PORT}/foo/bar`); + rootSpan.end(); + + assert.strictEqual(rpcMetadata.route, '/foo/bar/'); + }); + + it('should use latest match route when multiple route is match', async () => { + const rootSpan = tracer.startSpan('root span'); + const rpcMetadata: RPCMetadata = { type: RPCType.HTTP, span: rootSpan }; + app.use((req, res, next) => { + return context.with( + setRPCMetadata( + trace.setSpan(context.active(), rootSpan), + rpcMetadata + ), + next + ); + }); + + app.use('/foo', (req, res, next) => { + next(); + }); + + app.use('/foo/bar', (req, res, next) => { + next(); + }); + + await httpRequest.get(`http://localhost:${PORT}/foo/bar`); + rootSpan.end(); + + assert.strictEqual(rpcMetadata.route, '/foo/bar'); + }); + + it('should use latest match route when multiple route is match (with nested app)', async () => { + const rootSpan = tracer.startSpan('root span'); + const rpcMetadata: RPCMetadata = { type: RPCType.HTTP, span: rootSpan }; + app.use((req, res, next) => { + return context.with( + setRPCMetadata( + trace.setSpan(context.active(), rootSpan), + rpcMetadata + ), + next + ); + }); + + const nestedApp = connect(); + + app.use('/foo/', nestedApp); + nestedApp.use('/bar/', (req, res, next) => { + next(); + }); + + app.use('/foo/bar/test', (req, res, next) => { + next(); + }); + + await httpRequest.get(`http://localhost:${PORT}/foo/bar/test`); + rootSpan.end(); + + assert.strictEqual(rpcMetadata.route, '/foo/bar/test'); + }); }); }); diff --git a/plugins/node/opentelemetry-instrumentation-connect/test/utils.test.ts b/plugins/node/opentelemetry-instrumentation-connect/test/utils.test.ts new file mode 100644 index 0000000000..b62d3d6ab8 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-connect/test/utils.test.ts @@ -0,0 +1,96 @@ +/* + * 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. + */ +import * as assert from 'assert'; + +import { PatchedRequest, _LAYERS_STORE_PROPERTY } from '../src/internal-types'; +import { + addNewStackLayer, + generateRoute, + replaceCurrentStackRoute, +} from '../src/utils'; + +describe('utils', () => { + describe('addNewStackLayer', () => { + it('should inject new array to symbol property if not exist', () => { + const fakeRequest = {} as PatchedRequest; + + addNewStackLayer(fakeRequest); + + assert.strictEqual(fakeRequest[_LAYERS_STORE_PROPERTY].length, 1); + }); + + it('should append new stack item if private symbol already exists', () => { + const stack = ['/first']; + const fakeRequest = { + [_LAYERS_STORE_PROPERTY]: stack, + } as PatchedRequest; + + addNewStackLayer(fakeRequest); + + assert.equal(fakeRequest[_LAYERS_STORE_PROPERTY], stack); + assert.strictEqual(fakeRequest[_LAYERS_STORE_PROPERTY].length, 2); + }); + + it('should return pop method to remove newly add stack', () => { + const fakeRequest = {} as PatchedRequest; + + const pop = addNewStackLayer(fakeRequest); + + assert.notStrictEqual(pop, undefined); + + pop(); + + assert.strictEqual(fakeRequest[_LAYERS_STORE_PROPERTY].length, 0); + }); + + it('should prevent pop the same stack item multiple time', () => { + const fakeRequest = {} as PatchedRequest; + + addNewStackLayer(fakeRequest); // add first stack item + const pop = addNewStackLayer(fakeRequest); // add second stack item + + pop(); + pop(); + + assert.strictEqual(fakeRequest[_LAYERS_STORE_PROPERTY].length, 1); + }); + }); + + describe('replaceCurrentStackRoute', () => { + it('should replace the last stack item with new value', () => { + const fakeRequest = { + [_LAYERS_STORE_PROPERTY]: ['/first', '/second'], + } as PatchedRequest; + + replaceCurrentStackRoute(fakeRequest, '/new_route'); + + assert.strictEqual(fakeRequest[_LAYERS_STORE_PROPERTY].length, 2); + assert.strictEqual(fakeRequest[_LAYERS_STORE_PROPERTY][1], '/new_route'); + }); + }); + + describe('generateRoute', () => { + it('should combine the stack and striped any slash between layer', () => { + const fakeRequest = { + [_LAYERS_STORE_PROPERTY]: ['/first/', '/second', '/third/'], + } as PatchedRequest; + + const route = generateRoute(fakeRequest); + + assert.strictEqual(route, '/first/second/third/'); + }); + }); +});