Skip to content

Commit

Permalink
Log active span if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
akgagnat committed Jun 13, 2024
1 parent 1abe543 commit b738e29
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/fyllut-backend/src/security/idportenAuthHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SpanKind, SpanStatusCode, trace } from '@opentelemetry/api';
import { SpanKind, SpanStatusCode, context, trace } from '@opentelemetry/api';
import { NextFunction, Request, Response } from 'express';
import { FlattenedJWSInput, JWSHeaderParameters, createRemoteJWKSet, jwtVerify } from 'jose';
import { GetKeyFunction } from 'jose/dist/types/types';
Expand Down Expand Up @@ -28,6 +28,14 @@ const idportenAuthHandler = async (req: Request, res: Response, next: NextFuncti
req.getIdportenJwt = () => mockIdportenJwt;
req.getIdportenPid = () => mockIdportenPid!;
} else if (authHeader) {
const activeSpan = trace.getSpan(context.active());
if (activeSpan) {
const { spanId, traceId, traceState } = activeSpan.spanContext();
logger.info(`Active span :: spanId=${spanId} traceId=${traceId} traceState=${traceState || '<undefined>'}`);
} else {
logger.info('No active span');
}

const tracer = trace.getTracer(process.env.NAIS_APP_NAME!);
const spanOptions = {
kind: SpanKind.SERVER,
Expand Down

0 comments on commit b738e29

Please sign in to comment.