diff --git a/packages/core-shared/src/instrumentation/otel/init-server-node.ts b/packages/core-shared/src/instrumentation/otel/init-server-node.ts index 0905879..d151f3c 100644 --- a/packages/core-shared/src/instrumentation/otel/init-server-node.ts +++ b/packages/core-shared/src/instrumentation/otel/init-server-node.ts @@ -1,4 +1,8 @@ import { NodeSDK, tracing } from "@opentelemetry/sdk-node"; +import { registerInstrumentations } from "@opentelemetry/instrumentation"; +import { HttpInstrumentation } from "@opentelemetry/instrumentation-http"; +import { UndiciInstrumentation } from "@opentelemetry/instrumentation-undici"; +import { PgInstrumentation } from "@opentelemetry/instrumentation-pg"; import { buildResource } from "./resource"; import { createSentryOtelBridge } from "./sentry-bridge"; @@ -57,5 +61,23 @@ export function initOtelServerNode(opts: InitOtelServerNodeOpts): NodeSDK { }); sdk.start(); + + registerInstrumentations({ + instrumentations: [ + new HttpInstrumentation({ + requestHook: (span, request) => { + const url = (request as { url?: string }).url ?? ""; + span.setAttribute("http.url.path", url.split("?")[0] ?? ""); + }, + ignoreIncomingRequestHook: (req) => { + const url = (req as { url?: string }).url ?? ""; + return url === "/_health" || url === "/_otel-export"; + }, + }), + new UndiciInstrumentation(), + new PgInstrumentation({ enhancedDatabaseReporting: false }), + ], + }); + return sdk; }