Skip to content

Commit 996c587

Browse files
committed
Enrich log with traces with mixin feature
1 parent 4f54eb9 commit 996c587

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

bufflog.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import tracer from "dd-trace";
2+
import formats from "dd-trace/ext/formats";
13

24
export class BuffLog {
35
pinoLogger: any;
@@ -12,8 +14,20 @@ export class BuffLog {
1214

1315
// Define "base" fields
1416
// soon: remove the `v` field https://github.com/pinojs/pino/issues/620
15-
base: {
16-
},
17+
base: {},
18+
19+
mixin () {
20+
// Check here if a current trace exist to inject it in the log
21+
// `tracer` is a singleton, will no-op if no tracer was initialized
22+
var span = tracer.scope().active()
23+
if (span) {
24+
const traceInfo = {}
25+
tracer.inject(span.context(), formats.LOG, traceInfo);
26+
return traceInfo;
27+
} else {
28+
return {}
29+
}
30+
}
1731

1832
// notice doesn't exist in pino, let's add it
1933
customLevels: {

0 commit comments

Comments
 (0)