From c63d2a4206b8d4ba0fb337b253ff6c84f0814a09 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 30 Oct 2022 19:15:32 +0200 Subject: [PATCH] fix(mongodb): use net.peer namespace for mongo host and port (#1257) --- .../src/instrumentation.ts | 4 ++-- .../test/mongodb-v3.test.ts | 4 ++-- .../node/opentelemetry-instrumentation-mongodb/test/utils.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts index acf2e2f90f..f950dd49a8 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts @@ -569,8 +569,8 @@ export class MongoDBInstrumentation extends InstrumentationBase { if (host && port) { span.setAttributes({ - [SemanticAttributes.NET_HOST_NAME]: host, - [SemanticAttributes.NET_HOST_PORT]: port, + [SemanticAttributes.NET_PEER_NAME]: host, + [SemanticAttributes.NET_PEER_PORT]: port, }); } if (!commandObj) return; diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts index 45229d8789..3a663957f6 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/test/mongodb-v3.test.ts @@ -510,11 +510,11 @@ describe('MongoDBInstrumentation', () => { (err, address) => { if (err) return done(err); assert.strictEqual( - mongoSpan.attributes[SemanticAttributes.NET_HOST_NAME], + mongoSpan.attributes[SemanticAttributes.NET_PEER_NAME], address ); assert.strictEqual( - mongoSpan.attributes[SemanticAttributes.NET_HOST_PORT], + mongoSpan.attributes[SemanticAttributes.NET_PEER_PORT], process.env.MONGODB_PORT || '27017' ); done(); diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/test/utils.ts b/plugins/node/opentelemetry-instrumentation-mongodb/test/utils.ts index b63d60e57c..fde0af56d8 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/test/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/test/utils.ts @@ -84,7 +84,7 @@ export function assertSpans( 'mongodb' ); assert.strictEqual( - mongoSpan.attributes[SemanticAttributes.NET_HOST_NAME], + mongoSpan.attributes[SemanticAttributes.NET_PEER_NAME], process.env.MONGODB_HOST || DEFAULT_MONGO_HOST ); assert.strictEqual(mongoSpan.status.code, SpanStatusCode.UNSET);