diff --git a/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts index af3fa98a14..9644497626 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/src/instrumentation.ts @@ -45,7 +45,6 @@ import { getExtMetadata, isDirectExtInput, isPatchableExtMethod, - getRootSpanMetadata, } from './utils'; /** Hapi instrumentation for OpenTelemetry */ @@ -389,9 +388,7 @@ export class HapiInstrumentation extends InstrumentationBase { } const rpcMetadata = getRPCMetadata(api.context.active()); if (rpcMetadata?.type === RPCType.HTTP) { - const rootSpanMetadata = getRootSpanMetadata(route); - rpcMetadata.span.updateName(rootSpanMetadata.name); - rpcMetadata.span.setAttributes(rootSpanMetadata.attributes); + rpcMetadata.route = route.path; } const metadata = getRouteMetadata(route, pluginName); const span = instrumentation.tracer.startSpan(metadata.name, { diff --git a/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts b/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts index 1ddebf0a5e..14de861366 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/src/utils.ts @@ -94,20 +94,6 @@ export const getRouteMetadata = ( }; }; -export const getRootSpanMetadata = ( - route: Hapi.ServerRoute -): { - attributes: SpanAttributes; - name: string; -} => { - return { - attributes: { - [SemanticAttributes.HTTP_ROUTE]: route.path, - }, - name: `${route.method} ${route.path}`, - }; -}; - export const getExtMetadata = ( extPoint: Hapi.ServerRequestExtType, pluginName?: string diff --git a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts index f255f762b7..7f2baff724 100644 --- a/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts +++ b/plugins/node/opentelemetry-instrumentation-hapi/test/hapi.test.ts @@ -15,8 +15,7 @@ */ import { context, trace, SpanStatusCode } from '@opentelemetry/api'; -import { RPCType, setRPCMetadata } from '@opentelemetry/core'; -import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; +import { RPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { @@ -379,7 +378,7 @@ describe('Hapi Instrumentation - Core Tests', () => { assert.deepStrictEqual(memoryExporter.getFinishedSpans().length, 0); }); - it('should rename root span with route information', async () => { + it('should update rpcMetadata.route information', async () => { const rootSpan = tracer.startSpan('rootSpan', {}); server.route({ method: 'GET', @@ -391,7 +390,7 @@ describe('Hapi Instrumentation - Core Tests', () => { await server.start(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); - const rpcMetadata = { type: RPCType.HTTP, span: rootSpan }; + const rpcMetadata: RPCMetadata = { type: RPCType.HTTP, span: rootSpan }; await context.with( setRPCMetadata(trace.setSpan(context.active(), rootSpan), rpcMetadata), async () => { @@ -404,14 +403,7 @@ describe('Hapi Instrumentation - Core Tests', () => { rootSpan.end(); assert.deepStrictEqual(memoryExporter.getFinishedSpans().length, 2); - const exportedRootSpan = memoryExporter - .getFinishedSpans() - .find(span => span.name === 'GET /users/{userId}'); - assert.notStrictEqual(exportedRootSpan, undefined); - assert.strictEqual( - exportedRootSpan?.attributes[SemanticAttributes.HTTP_ROUTE], - '/users/{userId}' - ); + assert.strictEqual(rpcMetadata.route, '/users/{userId}'); } ); });