Reputation: 936
I'm setting up Jager tracing in Istio, but I cannot figure out how i should propagate the headers required in NestJS.
I've searched around in documentation for injection per request, but cant really wrap my head around it.
The headers that needs to be propagated are the following:
x-request-id
x-b3-traceid
x-b3-spanid
x-b3-parentspanid
x-b3-sampled
x-b3-flags
x-ot-span-context
Upvotes: 1
Views: 4227
Reputation: 444
I used the hpropagate npm package to get this working on my Istio cluster. It takes care of all the heavy lifting of extracting the trace headers from the incoming request and appending them to any outbound requests.
Install
npm install hpropagate
Usage
In main.ts
, import the package and call the function (with whatever default overrides you need) before creating the Nest app.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import hpropagate from 'hpropagate';
async function bootstrap() {
hpropagate({
setAndPropagateCorrelationId: false,
});
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
For more info, check out this article: https://medium.com/ww-engineering/headers-propagation-with-hpropagate-27de8347f76a
Upvotes: 3