opentelemetry-angular-interceptor icon indicating copy to clipboard operation
opentelemetry-angular-interceptor copied to clipboard

Injecting TraceId and SpanId into Logs

Open Mehdi203 opened this issue 2 years ago • 1 comments

Is it possible to Inject TraceIds and SpanIds into Logs similar to what's available for JavaScript (example in the following link):

JavaScript TraceId and SpanId injection into logs

Mehdi203 avatar Jul 22 '22 19:07 Mehdi203

Hi @Mehdi203,

You can do it with the CustomSpan interface.

See more information about this here

And you can do it like

  add(span: Span, request: HttpRequest<unknown>, response: HttpResponse<unknown> | HttpErrorResponse): Span {
    span.setAttribute(this.myKey , request.params + ';' + response.status);
    console.log(`Example log trace_id:”${span.spanContext().traceId}” span_id:”${span.spanContext().spanId}” trace_flags:”${span.spanContext().traceFlags}”`);
    return span;
  }

jufab avatar Sep 25 '22 21:09 jufab