Skip to content

Commit

Permalink
fix(net.peer.port): net.peer.port needs to be a number not a string
Browse files Browse the repository at this point in the history
Signed-off-by: esara <endresara@gmail.com>
  • Loading branch information
esara committed Jan 28, 2024
1 parent 12834d5 commit e4170d0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
16 changes: 12 additions & 4 deletions plugins/node/opentelemetry-instrumentation-memcached/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
16 changes: 14 additions & 2 deletions plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 14 additions & 2 deletions plugins/node/opentelemetry-instrumentation-mysql2/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e4170d0

Please sign in to comment.