diff --git a/package-lock.json b/package-lock.json index e7be22b429..1ec8f3fbe4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38417,7 +38417,7 @@ "license": "Apache-2.0", "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.23.0" }, "devDependencies": { "@opentelemetry/api": "^1.3.0", @@ -47174,7 +47174,7 @@ "@opentelemetry/instrumentation": "^0.51.0", "@opentelemetry/sdk-trace-base": "^1.8.0", "@opentelemetry/sdk-trace-node": "^1.8.0", - "@opentelemetry/semantic-conventions": "^1.0.0", + "@opentelemetry/semantic-conventions": "^1.23.0", "@types/mocha": "7.0.2", "@types/node": "18.6.5", "@types/sinon": "10.0.18", diff --git a/plugins/node/opentelemetry-instrumentation-net/README.md b/plugins/node/opentelemetry-instrumentation-net/README.md index d63211a389..2b6d7b841a 100644 --- a/plugins/node/opentelemetry-instrumentation-net/README.md +++ b/plugins/node/opentelemetry-instrumentation-net/README.md @@ -35,17 +35,20 @@ registerInstrumentations({ }); ``` -### Attributes added to `connect` spans +## Semantic Conventions -* `net.transport`: `IP.TCP`, `pipe` or `Unix` -* `net.peer.name`: host name or the IPC file path +This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) -For TCP: +Attributes added to `connect` spans: -* `net.peer.ip` -* `net.peer.port` -* `net.host.ip` -* `net.host.port` +| Attribute | Short Description | +|---------------------------|--------------------------------------------------------------------------| +| `net.transport` | `IP.TCP`, `pipe` or `Unix` | +| `net.peer.name` | Host name or the IPC file path | +| `net.peer.ip` (for TCP) | Remote address of the peer (dotted decimal for IPv4 or RFC5952 for IPv6) | +| `net.peer.port` (for TCP) | Remote port number | +| `net.host.ip` (for TCP) | Like net.peer.ip but for the host IP. Useful in case of a multi-IP host | +| `net.host.port` (for TCP) | Like net.peer.port but for the host port | ## Useful links diff --git a/plugins/node/opentelemetry-instrumentation-net/package.json b/plugins/node/opentelemetry-instrumentation-net/package.json index 41eb0902b7..b109a1c7c9 100644 --- a/plugins/node/opentelemetry-instrumentation-net/package.json +++ b/plugins/node/opentelemetry-instrumentation-net/package.json @@ -59,7 +59,7 @@ }, "dependencies": { "@opentelemetry/instrumentation": "^0.51.0", - "@opentelemetry/semantic-conventions": "^1.0.0" + "@opentelemetry/semantic-conventions": "^1.23.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-net/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-net/src/instrumentation.ts index b832473ef4..1cac375019 100644 --- a/plugins/node/opentelemetry-instrumentation-net/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-net/src/instrumentation.ts @@ -23,8 +23,13 @@ import { safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation'; import { - SemanticAttributes, - NetTransportValues, + SEMATTRS_NET_HOST_IP, + SEMATTRS_NET_HOST_PORT, + SEMATTRS_NET_PEER_IP, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, + SEMATTRS_NET_TRANSPORT, + NETTRANSPORTVALUES_IP_TCP, } from '@opentelemetry/semantic-conventions'; import { TLSAttributes } from './types'; import { NormalizedOptions, SocketEvent } from './internal-types'; @@ -184,8 +189,8 @@ export class NetInstrumentation extends InstrumentationBase { private _startIpcSpan(options: NormalizedOptions, socket: Socket) { const span = this.tracer.startSpan('ipc.connect', { attributes: { - [SemanticAttributes.NET_TRANSPORT]: IPC_TRANSPORT, - [SemanticAttributes.NET_PEER_NAME]: options.path, + [SEMATTRS_NET_TRANSPORT]: IPC_TRANSPORT, + [SEMATTRS_NET_PEER_NAME]: options.path, }, }); @@ -197,9 +202,9 @@ export class NetInstrumentation extends InstrumentationBase { private _startTcpSpan(options: NormalizedOptions, socket: Socket) { const span = this.tracer.startSpan('tcp.connect', { attributes: { - [SemanticAttributes.NET_TRANSPORT]: NetTransportValues.IP_TCP, - [SemanticAttributes.NET_PEER_NAME]: options.host, - [SemanticAttributes.NET_PEER_PORT]: options.port, + [SEMATTRS_NET_TRANSPORT]: NETTRANSPORTVALUES_IP_TCP, + [SEMATTRS_NET_PEER_NAME]: options.host, + [SEMATTRS_NET_PEER_PORT]: options.port, }, }); @@ -240,9 +245,9 @@ function registerListeners( const setHostAttributes = () => { span.setAttributes({ - [SemanticAttributes.NET_PEER_IP]: socket.remoteAddress, - [SemanticAttributes.NET_HOST_IP]: socket.localAddress, - [SemanticAttributes.NET_HOST_PORT]: socket.localPort, + [SEMATTRS_NET_PEER_IP]: socket.remoteAddress, + [SEMATTRS_NET_HOST_IP]: socket.localAddress, + [SEMATTRS_NET_HOST_PORT]: socket.localPort, }); }; diff --git a/plugins/node/opentelemetry-instrumentation-net/src/utils.ts b/plugins/node/opentelemetry-instrumentation-net/src/utils.ts index 8b013deead..8e1b67187b 100644 --- a/plugins/node/opentelemetry-instrumentation-net/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-net/src/utils.ts @@ -15,11 +15,14 @@ */ import { NormalizedOptions } from './internal-types'; -import { NetTransportValues } from '@opentelemetry/semantic-conventions'; +import { + NETTRANSPORTVALUES_PIPE, + NETTRANSPORTVALUES_UNIX, +} from '@opentelemetry/semantic-conventions'; import { platform } from 'os'; export const IPC_TRANSPORT = - platform() === 'win32' ? NetTransportValues.PIPE : NetTransportValues.UNIX; + platform() === 'win32' ? NETTRANSPORTVALUES_PIPE : NETTRANSPORTVALUES_UNIX; function getHost(args: unknown[]) { return typeof args[1] === 'string' ? args[1] : 'localhost'; diff --git a/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts b/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts index 1aefd0e466..55849289ee 100644 --- a/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts +++ b/plugins/node/opentelemetry-instrumentation-net/test/connect.test.ts @@ -19,7 +19,7 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/sdk-trace-base'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { SEMATTRS_NET_TRANSPORT } from '@opentelemetry/semantic-conventions'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import * as net from 'net'; import * as assert from 'assert'; @@ -186,7 +186,7 @@ describe('NetInstrumentation', () => { try { const span = getSpan(); assert.strictEqual( - span.attributes[SemanticAttributes.NET_TRANSPORT], + span.attributes[SEMATTRS_NET_TRANSPORT], undefined ); assert.strictEqual(span.status.code, SpanStatusCode.ERROR); diff --git a/plugins/node/opentelemetry-instrumentation-net/test/utils.ts b/plugins/node/opentelemetry-instrumentation-net/test/utils.ts index 23bc6db72b..7d3651d2df 100644 --- a/plugins/node/opentelemetry-instrumentation-net/test/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-net/test/utils.ts @@ -17,8 +17,12 @@ import { SpanKind } from '@opentelemetry/api'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { - NetTransportValues, - SemanticAttributes, + NETTRANSPORTVALUES_IP_TCP, + SEMATTRS_NET_HOST_IP, + SEMATTRS_NET_HOST_PORT, + SEMATTRS_NET_PEER_NAME, + SEMATTRS_NET_PEER_PORT, + SEMATTRS_NET_TRANSPORT, } from '@opentelemetry/semantic-conventions'; import * as assert from 'assert'; import * as path from 'path'; @@ -37,21 +41,17 @@ export const IPC_PATH = export function assertTcpSpan(span: ReadableSpan, socket: Socket) { assertSpanKind(span); - assertAttrib( - span, - SemanticAttributes.NET_TRANSPORT, - NetTransportValues.IP_TCP - ); - assertAttrib(span, SemanticAttributes.NET_PEER_NAME, HOST); - assertAttrib(span, SemanticAttributes.NET_PEER_PORT, PORT); - assertAttrib(span, SemanticAttributes.NET_HOST_IP, socket.localAddress); - assertAttrib(span, SemanticAttributes.NET_HOST_PORT, socket.localPort); + assertAttrib(span, SEMATTRS_NET_TRANSPORT, NETTRANSPORTVALUES_IP_TCP); + assertAttrib(span, SEMATTRS_NET_PEER_NAME, HOST); + assertAttrib(span, SEMATTRS_NET_PEER_PORT, PORT); + assertAttrib(span, SEMATTRS_NET_HOST_IP, socket.localAddress); + assertAttrib(span, SEMATTRS_NET_HOST_PORT, socket.localPort); } export function assertIpcSpan(span: ReadableSpan) { assertSpanKind(span); - assertAttrib(span, SemanticAttributes.NET_TRANSPORT, IPC_TRANSPORT); - assertAttrib(span, SemanticAttributes.NET_PEER_NAME, IPC_PATH); + assertAttrib(span, SEMATTRS_NET_TRANSPORT, IPC_TRANSPORT); + assertAttrib(span, SEMATTRS_NET_PEER_NAME, IPC_PATH); } export function assertTLSSpan( @@ -60,17 +60,13 @@ export function assertTLSSpan( ) { assertParentChild(tlsSpan, netSpan); assertSpanKind(netSpan); - assertAttrib( - netSpan, - SemanticAttributes.NET_TRANSPORT, - NetTransportValues.IP_TCP - ); - assertAttrib(netSpan, SemanticAttributes.NET_PEER_NAME, HOST); - assertAttrib(netSpan, SemanticAttributes.NET_PEER_PORT, PORT); + assertAttrib(netSpan, SEMATTRS_NET_TRANSPORT, NETTRANSPORTVALUES_IP_TCP); + assertAttrib(netSpan, SEMATTRS_NET_PEER_NAME, HOST); + assertAttrib(netSpan, SEMATTRS_NET_PEER_PORT, PORT); // Node.JS 10 sets socket.localAddress & socket.localPort to "undefined" when a connection is // ended, so one of the tests fails, so we skip them for TLS - // assertAttrib(span, SemanticAttributes.NET_HOST_IP, socket.localAddress); - //assertAttrib(netSpan, SemanticAttributes.NET_HOST_PORT, socket.localPort); + // assertAttrib(span, SEMATTRS_NET_HOST_IP, socket.localAddress); + //assertAttrib(netSpan, SEMATTRS_NET_HOST_PORT, socket.localPort); assertAttrib(tlsSpan, TLSAttributes.PROTOCOL, 'TLSv1.2'); assertAttrib(tlsSpan, TLSAttributes.AUTHORIZED, 'true');