Copy parent trace_id from parent span#80
Copy parent trace_id from parent span#80maximebedard wants to merge 1 commit intotokio-rs:v0.1.xfrom
Conversation
|
Hm could you elaborate more on the case where parent span ids are not currently copied? Currently the trace id is intentionally only tracked for cases where there is no active parent so it can be used for pre-sampling. |
|
TIL, I didn't know that's how sampling was handled internally. I haven't looked to much in depth how it's implemented, but I suppose the trace_id is generated when the span is closed instead of when it's created? If that's the case, I'm not really sure how I could solve my problem. The use-case I currently have is to copy the I had to close the original PR due to a circular dependency issue, but I'm using my own version of the |
|
So the main issue is ordering around calls to |
|
Could a more reliable approach be to buffer the LogRecords, this way we could retrieve a stable trace_id and export them without having to consider calls to |
|
@maximebedard maybe, you could explore that path and see what tradeoffs you would have to make. Potentially unbounded buffering as logs within a given span aren't capped, also delaying log export until the parent is closed be undesirable. Alternatively we could consider a special field type solution where if a trace id has been set there it can't be re assigned, and there may be other possible alternative solutions to explore as well. |
|
@jtescher the related opentelemetry rust change open-telemetry/opentelemetry-rust#1394 |
|
This has been reworked and now changing the parent after some operations should not work anymore (and return an error). So I'm going to close this but feel free to open an issue if there are still issues with IDs. |
Motivation
I ran into an issue where the trace_id of the parent span is not copied into the
SpanContextof the current span. This can be especially problematic when downstream APIs rely on theOtelDatastructure to extract the trace_id and span_id.I believe the test was incorrect as it was only checking that the value was left unchanged in the parent span, not that the trace_id of the current span was set.
I believe this is related to #77.
Solution
I'm copying the trace_id from the
parent_cx.spanwhen the span has a parent context. Otherwise we generate a new trace_id. I've updated the test_tracer to generate sequential{TraceId,SpanId}to potentially avoid comparing against{TraceId,SpanId}::INVALID.Thanks!