mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
fix(api): send trace context to sentry
This helps associating errors in sentry with the full trace context
This commit is contained in:
parent
3528a6d205
commit
8d9e99039c
1 changed files with 15 additions and 4 deletions
19
src/main.ts
19
src/main.ts
|
|
@ -10,15 +10,14 @@ import { RavenInterceptor } from "nest-raven";
|
||||||
import Pino from "pino";
|
import Pino from "pino";
|
||||||
import { AppModule } from "./app.module";
|
import { AppModule } from "./app.module";
|
||||||
import { Logger } from "nestjs-pino";
|
import { Logger } from "nestjs-pino";
|
||||||
|
import { Scope } from "@sentry/node";
|
||||||
|
|
||||||
const logger = Pino({
|
const logger = Pino({
|
||||||
formatters: {
|
formatters: {
|
||||||
log(object) {
|
log(object) {
|
||||||
const span = trace.getSpan(context.active());
|
const span = trace.getSpan(context.active());
|
||||||
if (!span) return { ...object };
|
if (!span) return { ...object };
|
||||||
const { spanId, traceId } = trace
|
const { spanId, traceId } = span.spanContext();
|
||||||
.getSpan(context.active())
|
|
||||||
?.spanContext();
|
|
||||||
return { ...object, spanId, traceId };
|
return { ...object, spanId, traceId };
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -39,7 +38,19 @@ function setupSentry(
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
app.useGlobalInterceptors(new RavenInterceptor());
|
app.useGlobalInterceptors(
|
||||||
|
new RavenInterceptor({
|
||||||
|
transformers: [
|
||||||
|
(scope: Scope) => {
|
||||||
|
const span = trace.getSpan(context.active());
|
||||||
|
if (span) {
|
||||||
|
const { spanId, traceId } = span.spanContext();
|
||||||
|
scope.setContext("trace", { span_id: spanId, trace_id: traceId });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue