Skip to content

Commit db48c1f

Browse files
committed
fix: improve HTTP span name
1 parent 80c8560 commit db48c1f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/telemetry/register.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This module MUST be loaded via --require before any application code.
22
// It instantiates OpenTelemetry instrumentations that monkey-patch require()
33
// hooks, ensuring all subsequently loaded modules (http, pg, etc.) are patched.
4+
import { ClientRequest } from 'node:http';
45
import type { Span } from '@opentelemetry/api';
56

67
import FastifyOtelInstrumentation from '@fastify/otel';
@@ -36,6 +37,12 @@ const ignorePaths = ['/health', '/liveness', '/metrics'];
3637

3738
const getInstrumentations = () => [
3839
new HttpInstrumentation({
40+
requestHook: (span, req) => {
41+
if (!span.isRecording()) return;
42+
const suffix =
43+
req instanceof ClientRequest ? ` ${req.host}${req.path}` : req.url;
44+
span.updateName(`${req.method} ${suffix}`);
45+
},
3946
ignoreIncomingRequestHook: (request) =>
4047
ignorePaths.some((path) => request.url?.includes(path)),
4148
}),

0 commit comments

Comments
 (0)