Skip to content

Commit 170161b

Browse files
nicohrubecclaude
andauthored
ref(node): Vendor @fastify/otel (#21099)
Vendors `@fastify/otel@0.18.1` into the SDK with minimal changes. The original source is in plain Javascript so this was adapted with minimal type annotations to make it compatible with the TS compiler of this repo. The original instrumentation also had an `ignorePaths` code path, which relies on `minimatch` as a dependency but was never exposed by the Sentry integration. For this reason this was already cleaned out so we can avoid the `minimatch` dependency. Everything else is preserved as is. Closes #20162 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 683bee2 commit 170161b

8 files changed

Lines changed: 521 additions & 48 deletions

File tree

.oxlintrc.base.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@
159159
"**/integrations/tracing/amqplib/vendored/**/*.ts",
160160
"**/integrations/tracing/prisma/vendored/**/*.ts",
161161
"**/integrations/tracing/graphql/vendored/**/*.ts",
162-
"**/integrations/tracing/postgres/vendored/**/*.ts"
162+
"**/integrations/tracing/postgres/vendored/**/*.ts",
163+
"**/integrations/tracing/fastify/vendored/**/*.ts"
163164
],
164165
"rules": {
165166
"typescript/no-explicit-any": "off"

dev-packages/e2e-tests/test-applications/nestjs-fastify/tests/transactions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
6262
data: {
6363
'sentry.origin': 'auto.http.otel.fastify',
6464
'sentry.op': 'hook.fastify',
65-
'hook.name': 'fastify -> @fastify/otel -> @fastify/middie - onRequest',
65+
'hook.name': 'fastify -> @sentry/instrumentation-fastify -> @fastify/middie - onRequest',
6666
'fastify.type': 'hook',
6767
'hook.callback.name': 'runMiddie',
6868
},
@@ -80,7 +80,7 @@ test('Sends an API route transaction', async ({ baseURL }) => {
8080
data: {
8181
'sentry.origin': 'auto.http.otel.fastify',
8282
'sentry.op': 'request_handler.fastify',
83-
'hook.name': 'fastify -> @fastify/otel -> @fastify/middie - route-handler',
83+
'hook.name': 'fastify -> @sentry/instrumentation-fastify -> @fastify/middie - route-handler',
8484
'fastify.type': 'request-handler',
8585
'http.route': '/test-transaction',
8686
'hook.callback.name': 'anonymous',

dev-packages/e2e-tests/test-applications/node-fastify-4/tests/transactions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ test('Sends an API route transaction', async ({ baseURL }) => {
6969
data: {
7070
'fastify.type': 'hook',
7171
'hook.callback.name': 'anonymous',
72-
'hook.name': 'fastify -> @fastify/otel - onRequest',
72+
'hook.name': 'fastify -> @sentry/instrumentation-fastify - onRequest',
7373
'sentry.op': 'hook.fastify',
7474
'sentry.origin': 'auto.http.otel.fastify',
7575
},
76-
description: '@fastify/otel - onRequest',
76+
description: '@sentry/instrumentation-fastify - onRequest',
7777
op: 'hook.fastify',
7878
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
7979
span_id: expect.stringMatching(/[a-f0-9]{16}/),

dev-packages/e2e-tests/test-applications/node-fastify-5/tests/transactions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ test('Sends an API route transaction', async ({ baseURL }) => {
6969
data: {
7070
'fastify.type': 'hook',
7171
'hook.callback.name': 'anonymous',
72-
'hook.name': 'fastify -> @fastify/otel - onRequest',
72+
'hook.name': 'fastify -> @sentry/instrumentation-fastify - onRequest',
7373
'sentry.op': 'hook.fastify',
7474
'sentry.origin': 'auto.http.otel.fastify',
7575
},
76-
description: '@fastify/otel - onRequest',
76+
description: '@sentry/instrumentation-fastify - onRequest',
7777
op: 'hook.fastify',
7878
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
7979
span_id: expect.stringMatching(/[a-f0-9]{16}/),

packages/node/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"@opentelemetry/sql-common": "^0.41.2",
7272
"@opentelemetry/sdk-trace-base": "^2.6.1",
7373
"@opentelemetry/semantic-conventions": "^1.40.0",
74-
"@fastify/otel": "0.18.0",
7574
"@sentry/core": "10.53.1",
7675
"@sentry/node-core": "10.53.1",
7776
"@sentry/opentelemetry": "10.53.1",

packages/node/src/integrations/tracing/fastify/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as diagnosticsChannel from 'node:diagnostics_channel';
2-
import { FastifyOtelInstrumentation } from '@fastify/otel';
2+
import { FastifyOtelInstrumentation } from './vendored/instrumentation';
33
import type { Instrumentation, InstrumentationConfig } from '@opentelemetry/instrumentation';
44
import type { IntegrationFn, Span } from '@sentry/core';
55
import {
@@ -294,7 +294,10 @@ function addFastifySpanAttributes(span: Span): void {
294294
// Try removing `fastify -> ` and `@fastify/otel -> ` prefixes
295295
// This is a bit of a hack, and not always working for all spans
296296
// But it's the best we can do without a proper API
297-
const updatedName = attrName.replace(/^fastify -> /, '').replace(/^@fastify\/otel -> /, '');
297+
const updatedName = attrName
298+
.replace(/^fastify -> /, '')
299+
.replace(/^@fastify\/otel -> /, '')
300+
.replace(/^@sentry\/instrumentation-fastify -> /, '');
298301

299302
span.updateName(updatedName);
300303
}

0 commit comments

Comments
 (0)