From e4170d0273255b72363de97680f864b3d670b729 Mon Sep 17 00:00:00 2001 From: esara Date: Sun, 28 Jan 2024 14:17:00 -0500 Subject: [PATCH] fix(net.peer.port): net.peer.port needs to be a number not a string Signed-off-by: esara --- .../src/utils.ts | 16 ++++++++++++---- .../src/instrumentation.ts | 9 +++++---- .../src/utils.ts | 16 ++++++++++++++-- .../src/utils.ts | 16 ++++++++++++++-- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts b/plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts index aa49f6c357..4cebd4112e 100644 --- a/plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts @@ -45,10 +45,18 @@ export const getPeerAttributes = ( if (typeof server === 'string') { const [host, port] = server && server.split(':'); - return { - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.NET_PEER_PORT]: port, - }; + if (host && port) { + const portNumber = parseInt(port, 10); + if (!isNaN(portNumber)) { + return { + [SemanticAttributes.NET_PEER_NAME]: host, + [SemanticAttributes.NET_PEER_PORT]: portNumber, + }; + } + return { + [SemanticAttributes.NET_PEER_NAME]: host, + }; + } } return {}; }; diff --git a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts index 3be3019848..02af814bf2 100644 --- a/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mongodb/src/instrumentation.ts @@ -813,10 +813,11 @@ export class MongoDBInstrumentation extends InstrumentationBase { }); if (host && port) { - span.setAttributes({ - [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.NET_PEER_PORT]: port, - }); + span.setAttribute(SemanticAttributes.NET_PEER_NAME, host); + const portNumber = parseInt(port, 10); + if (!isNaN(portNumber)) { + span.setAttribute(SemanticAttributes.NET_PEER_PORT, portNumber); + } } if (!commandObj) return; const dbStatementSerializer = diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts index 9eb7e90827..05eb1d809f 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts @@ -33,10 +33,22 @@ export function getConnectionAttributes( config: ConnectionConfig | PoolActualConfig ): SpanAttributes { const { host, port, database, user } = getConfig(config); - + const portNumber = parseInt(port, 10); + if (!isNaN(portNumber)) { + return { + [SemanticAttributes.NET_PEER_NAME]: host, + [SemanticAttributes.NET_PEER_PORT]: portNumber, + [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( + host, + port, + database + ), + [SemanticAttributes.DB_NAME]: database, + [SemanticAttributes.DB_USER]: user, + }; + } return { [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.NET_PEER_PORT]: port, [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( host, port, diff --git a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts index 3091569a40..c38f5ac683 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts @@ -48,10 +48,22 @@ interface Config { */ export function getConnectionAttributes(config: Config): SpanAttributes { const { host, port, database, user } = getConfig(config); - + const portNumber = parseInt(port, 10); + if (!isNaN(portNumber)) { + return { + [SemanticAttributes.NET_PEER_NAME]: host, + [SemanticAttributes.NET_PEER_PORT]: portNumber, + [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( + host, + port, + database + ), + [SemanticAttributes.DB_NAME]: database, + [SemanticAttributes.DB_USER]: user, + }; + } return { [SemanticAttributes.NET_PEER_NAME]: host, - [SemanticAttributes.NET_PEER_PORT]: port, [SemanticAttributes.DB_CONNECTION_STRING]: getJDBCString( host, port,