Skip to content

Commit 903b5a3

Browse files
committed
refactor(instrumentation-fastify): update semconv usage to ATTR_ exports
Refs: #2377
1 parent e0858f9 commit 903b5a3

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
InstrumentationNodeModuleDefinition,
2222
safeExecuteInTheMiddle,
2323
} from '@opentelemetry/instrumentation';
24-
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
24+
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
2525
import type {
2626
HookHandlerDoneFunction,
2727
FastifyInstance,
@@ -269,7 +269,7 @@ export class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumen
269269
const spanAttributes: Attributes = {
270270
[AttributeNames.PLUGIN_NAME]: this.pluginName,
271271
[AttributeNames.FASTIFY_TYPE]: FastifyTypes.REQUEST_HANDLER,
272-
[SEMATTRS_HTTP_ROUTE]: anyRequest.routeOptions
272+
[ATTR_HTTP_ROUTE]: anyRequest.routeOptions
273273
? anyRequest.routeOptions.url // since fastify@4.10.0
274274
: request.routerPath,
275275
};

plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
import * as assert from 'assert';
1818
import { context, SpanStatusCode } from '@opentelemetry/api';
19-
import {
20-
SEMATTRS_HTTP_ROUTE,
21-
SEMATTRS_HTTP_METHOD,
22-
} from '@opentelemetry/semantic-conventions';
19+
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
2320
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
2421
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
2522
import {
@@ -161,7 +158,7 @@ describe('fastify', () => {
161158
assert.deepStrictEqual(span.attributes, {
162159
'fastify.type': 'request_handler',
163160
'plugin.name': 'fastify -> @fastify/express',
164-
[SEMATTRS_HTTP_ROUTE]: '/test',
161+
[ATTR_HTTP_ROUTE]: '/test',
165162
});
166163
assert.strictEqual(
167164
span.name,
@@ -190,7 +187,7 @@ describe('fastify', () => {
190187
'fastify.type': 'request_handler',
191188
'fastify.name': 'namedHandler',
192189
'plugin.name': 'fastify -> @fastify/express',
193-
[SEMATTRS_HTTP_ROUTE]: '/test',
190+
[ATTR_HTTP_ROUTE]: '/test',
194191
});
195192
assert.strictEqual(span.name, 'request handler - namedHandler');
196193

@@ -502,7 +499,7 @@ describe('fastify', () => {
502499
describe('using requestHook in config', () => {
503500
it('calls requestHook provided function when set in config', async () => {
504501
const requestHook = (span: Span, info: FastifyRequestInfo) => {
505-
span.setAttribute(SEMATTRS_HTTP_METHOD, info.request.method);
502+
span.setAttribute('my.http.method', info.request.method);
506503
};
507504

508505
instrumentation.setConfig({
@@ -523,14 +520,14 @@ describe('fastify', () => {
523520
assert.deepStrictEqual(span.attributes, {
524521
'fastify.type': 'request_handler',
525522
'plugin.name': 'fastify -> @fastify/express',
526-
[SEMATTRS_HTTP_ROUTE]: '/test',
527-
[SEMATTRS_HTTP_METHOD]: 'GET',
523+
[ATTR_HTTP_ROUTE]: '/test',
524+
'my.http.method': 'GET',
528525
});
529526
});
530527

531528
it('does not propagate an error from a requestHook that throws exception', async () => {
532529
const requestHook = (span: Span, info: FastifyRequestInfo) => {
533-
span.setAttribute(SEMATTRS_HTTP_METHOD, info.request.method);
530+
span.setAttribute('my.http.method', info.request.method);
534531

535532
throw Error('error thrown in requestHook');
536533
};
@@ -553,8 +550,8 @@ describe('fastify', () => {
553550
assert.deepStrictEqual(span.attributes, {
554551
'fastify.type': 'request_handler',
555552
'plugin.name': 'fastify -> @fastify/express',
556-
[SEMATTRS_HTTP_ROUTE]: '/test',
557-
[SEMATTRS_HTTP_METHOD]: 'GET',
553+
[ATTR_HTTP_ROUTE]: '/test',
554+
'my.http.method': 'GET',
558555
});
559556
});
560557
});

0 commit comments

Comments
 (0)