Skip to content

Commit

Permalink
fix(tracing): fix handling of x-request-id header
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Jul 9, 2024
1 parent 0a2e34c commit f250346
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions oada/services/http-handler/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const serializers = {
req(request: FastifyRequest) {
const version = request.headers?.['accept-version'];
return {
requestId: request.headers?.['x-request-id'],
method: request.method,
url: request.url,
version: version ? `${version}` : undefined,
Expand Down Expand Up @@ -161,14 +162,14 @@ if (process.env.NODE_ENV !== 'production') {
request.log.error({ err: error, res });
void reply.code(code).send(res?.body ?? res);
});

// Add request id header for debugging purposes
fastify.addHook('onSend', async (request, reply, payload) => {
void reply.header('X-Request-Id', request.id);
return payload;
});
}

// Add request id header for tracing/debugging purposes
fastify.addHook('onSend', async (request, reply, payload) => {
void reply.header('X-Request-Id', request.headers['x-request-id']);
return payload;
});

const port = config.get('server.port');
export async function start(): Promise<void> {
await fastify.listen({
Expand Down

0 comments on commit f250346

Please sign in to comment.