Skip to content

Commit

Permalink
Forward header to tracing (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek authored Dec 4, 2023
1 parent 725f6f5 commit 73fd18e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion server/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { Resource } from "@opentelemetry/resources";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import { FastifyRequest } from "fastify";

const sensibleHeaderKeys = ["authorization", "cookie", "x-swan-token"];

if (process.env.TRACING_SERVICE_NAME != null) {
const provider = new NodeTracerProvider({
Expand All @@ -31,7 +34,15 @@ if (process.env.TRACING_SERVICE_NAME != null) {
new HttpInstrumentation({
ignoreIncomingPaths: [/\/health/],
}),
new FastifyInstrumentation(),
new FastifyInstrumentation({
requestHook: (span, { request: { headers } }: { request: FastifyRequest }) => {
for (const [key, value = ""] of Object.entries(headers)) {
if (!sensibleHeaderKeys.includes(key.toLowerCase())) {
span.setAttribute(`http.header.${key}`, value);
}
}
},
}),
],
});
}

0 comments on commit 73fd18e

Please sign in to comment.