Skip to content

Commit

Permalink
fix: otel hook (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenos authored Jan 24, 2025
1 parent ddc5163 commit f4ae982
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/internal/monitoring/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit f4ae982

Please sign in to comment.