Skip to content

Commit 5b44f24

Browse files
committed
refactor(trace): add span hook
1 parent 11be3b5 commit 5b44f24

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/tracing.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
88
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
99
import { TypeormInstrumentation } from '@opentelemetry/instrumentation-typeorm';
1010
import { isEmpty } from 'omniboxd/utils/is-empty';
11+
import { Span } from '@opentelemetry/api';
12+
import { ServerResponse } from 'http';
1113

1214
const env = process.env.ENV || 'unknown';
1315
const serviceName = `omnibox-backend`;
@@ -43,6 +45,12 @@ if (isTracingEnabled()) {
4345
ignoreIncomingRequestHook: (req) => {
4446
return excludedUrls.some((url) => req.url?.includes(url)) || false;
4547
},
48+
responseHook: (span: Span, response: ServerResponse) => {
49+
const req = response.req as any;
50+
if (req.user?.id) {
51+
span.setAttribute('user.id', req.user.id);
52+
}
53+
},
4654
}),
4755
new ExpressInstrumentation(),
4856
new NestInstrumentation(),

0 commit comments

Comments
 (0)