From 7f14820b1b9b113233d8edb78c699c5f58e55496 Mon Sep 17 00:00:00 2001 From: fenos Date: Wed, 22 Jan 2025 13:41:46 +0100 Subject: [PATCH] fix: otel hook --- src/internal/monitoring/otel.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/internal/monitoring/otel.ts b/src/internal/monitoring/otel.ts index 37d1ac91..30b31c83 100644 --- a/src/internal/monitoring/otel.ts +++ b/src/internal/monitoring/otel.ts @@ -95,22 +95,25 @@ const sdk = new NodeSDK({ const ignoreRoutes = ['/metrics', '/status', '/health', '/healthcheck'] return ignoreRoutes.some((url) => req.url?.includes(url)) ?? false }, - applyCustomAttributesOnSpan: (span, req) => { + startIncomingSpanHook: (req) => { let tenantId = '' if (isMultitenant) { if (requestXForwardedHostRegExp) { - const serverRequest = req as IncomingMessage + const serverRequest = req const xForwardedHost = serverRequest.headers['x-forwarded-host'] - if (typeof xForwardedHost !== 'string') return + if (typeof xForwardedHost !== 'string') return {} const result = xForwardedHost.match(requestXForwardedHostRegExp) - if (!result) return + if (!result) return {} tenantId = result[1] } } else { tenantId = defaultTenantId } - span.setAttribute('tenant.ref', tenantId) - span.setAttribute('region', region) + + return { + 'tenant.ref': tenantId, + region, + } }, headersToSpanAttributes: { client: {