opentelemetry-specification
opentelemetry-specification copied to clipboard
Log "parentId" received as HTTP header in MDC
Hi, I am trying to look for a solution to log using MDC, the "parentId" received as an HTTP header(as a W3C header or B3 header) in a microservice using Spring WebFlux application.
Currently the logs using MDC are logging the traceId and spanId but not the "parentId". I have been reading documentation of OpenTelemetry and it seems that currently the parentId is stored in the Span created in OpenTelemetry but the api does not expose the parentId. So it seems that I have to put manually in some way this property in the MDC but I dont know how do it and besides I am using Spring WebFlux that uses Context from Reactor so I will have to do it in a reactive way.
OpenTelemetry does store the traceId and spanId received as http headers in the MDC context in a reactive way so I have to do the same for the parentId. Is there some guide, example or documentacion to achieve this?.
Thanks.
hi @fer1979, can you explain why you need both span id and parent span id on your log records? generally all you should need is the span id in order to connect your log record to your span graph
Hi, because lets say I have a microservice 1 that receives an http request and to process it it has to create multiple threads. Each of these threads has its own flow calling to other microservices. Logging just the traceId and spanId in microservice 1 would be enough to know the "the flow" in microservice 1 but if I look in microservice 2, I will have the same traceId but different spanId than the microservice 1 not knowing which thread of microservice 1 made this request to the microservice 2 and losing the flow view from a particular thread in the microservice1. I already found a solution to log it and is using the ThreadLocalAccesor from micrometer( https://javadoc.io/doc/io.micrometer/context-propagation/latest/io/micrometer/context/ThreadLocalAccessor.html ) for the context propagation between Reactor and ThreadLocal.
Thanks.
I will have the same traceId but different spanId than the microservice 1 not knowing which thread of microservice 1 made this request to the microservice 2 and losing the flow view from a particular thread in the microservice1
from the trace_id / span_id pair on your log record, you can look up the span record in your backend and get the parent_span_id if you want to traverse higher up. most backends will do this automatically for you.
Ok, but you mean I cant get the "parent_span_id" using a backend tracing system like Zipkin for example?. Currently we just have logs and not a tracing system.
Thanks.
Currently we just have logs and not a tracing system.
ah, I understand now, thanks
to answer your original question:
Is there some guide, example or documentacion to achieve this?
I don't believe there is any such documentation, since this is not a typical use case
@fer1979 do you need any more guidance?
No thanks.