From f4ae98281df741fea4210ad5faefe3f71cca950a Mon Sep 17 00:00:00 2001 From: Fabrizio Date: Fri, 24 Jan 2025 16:01:00 +0100 Subject: [PATCH] fix: otel hook (#624) --- 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: {