Skip to content

Commit f4ae982

Browse files
authored
fix: otel hook (#624)
1 parent ddc5163 commit f4ae982

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/internal/monitoring/otel.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,25 @@ const sdk = new NodeSDK({
9595
const ignoreRoutes = ['/metrics', '/status', '/health', '/healthcheck']
9696
return ignoreRoutes.some((url) => req.url?.includes(url)) ?? false
9797
},
98-
applyCustomAttributesOnSpan: (span, req) => {
98+
startIncomingSpanHook: (req) => {
9999
let tenantId = ''
100100
if (isMultitenant) {
101101
if (requestXForwardedHostRegExp) {
102-
const serverRequest = req as IncomingMessage
102+
const serverRequest = req
103103
const xForwardedHost = serverRequest.headers['x-forwarded-host']
104-
if (typeof xForwardedHost !== 'string') return
104+
if (typeof xForwardedHost !== 'string') return {}
105105
const result = xForwardedHost.match(requestXForwardedHostRegExp)
106-
if (!result) return
106+
if (!result) return {}
107107
tenantId = result[1]
108108
}
109109
} else {
110110
tenantId = defaultTenantId
111111
}
112-
span.setAttribute('tenant.ref', tenantId)
113-
span.setAttribute('region', region)
112+
113+
return {
114+
'tenant.ref': tenantId,
115+
region,
116+
}
114117
},
115118
headersToSpanAttributes: {
116119
client: {

0 commit comments

Comments
 (0)