Manually set the Trace ID in a root span #1919
Replies: 4 comments 8 replies
-
Which code snippets are you referring to?
There is no specific code example yet, but feel free to add one if it is a common case. You can get the rate as a property of the
|
Beta Was this translation helpful? Give feedback.
-
Hi Srikanth,
Thanks for the answer. Basically, we are trying to stitch together several independent processes (some python, some java) together so that the distributed trace is shared between them. Some of the processes will define the trace ID while others will need to continue the distributed tracing using an already defined trace ID. The method that the already defined trace ID is communicated between processes is varied and non-standard (i.e. not in a gRPC or HTTP header). Also, we will sometimes want to force a trace to not be sampled, but have it appear in the system (i.e. via trace flags).
I tried the method you suggested fulfills everything we need and I confirmed that it works. I had actually seen this sample in the cookbook, but discarded it because the spec seemed to indicate that it would cause a “noop” – that it was for situations where a dummy trace was needed. And I could see in the code that it was the only way to set a span context via the SDK. Here is the material in the spec that fooled me:
Wrapping a SpanContext in a Span
The API MUST provide an operation for wrapping a SpanContext with an object implementing the Span interface. This is done in order to expose a SpanContext as a Span in operations such as in-process Span propagation.
If a new type is required for supporting this operation, it SHOULD NOT be exposed publicly if possible (e.g. by only exposing a function that returns something with the Span interface type). If a new type is required to be publicly exposed, it SHOULD be named NonRecordingSpan.
The behavior is defined as follows:
* GetContext MUST return the wrapped SpanContext.
* **IsRecording MUST return false to signal that events, attributes and other elements are not being recorded, i.e. they are being dropped.**
**The remaining functionality of Span MUST be defined as no-op operations.** Note: This includes End, so as an exception from the general rule, it is not required (or even helpful) to end such a Span.
This functionality MUST be fully implemented in the API, and SHOULD NOT be overridable.
Anyways, thanks for pointing out the correct approach. Don’t the above words in bold seem a bit strange given that I can see that the span is recorded in Jaeger? Or maybe that is not what is meant by “recording”? Am I missing something in terms of understanding?
Best Regards,
John
|
Beta Was this translation helpful? Give feedback.
-
One thought that came to mind as I was reading the use-case is that sounds like it would be a good case for creating a custom propagator which could be implemented once in each language the system supports then configured via the existing opentelemetry APIs. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to implement a custom distributed tracing and pass the trace ID over the network. Is it a use case that the library can support? I see how I can extract the trace ID ( |
Beta Was this translation helpful? Give feedback.
-
Hi,
How does one manually set the trace ID in the root span? I am surprised that this common use case is not covered in the docs since it is a fundamental aspect of distributed tracing. I am not looking for fancy convenience methods that parse HTTP headers and transparently load a context with Trace ID..., I am looking for the basic methods one would use to take a Trace ID from a python variable and load it into the root span context.
We have python processes that start spontaneously and that need to propagate a Trace ID. How this trace ID gets into the python process is irrelevant - we simply need a way to take a trace ID and insert it into the root span. An official working code example on how to do this would be appreciated.
P.S. I have noticed questions in the past on this topic, but the code snippets given throw "no such member" type errors, which implies a hacking of non-official API methods?
P.S. 2 The sampling rate needs to also be exposed to the user if we are to go live with this library in a production system. Any examples of that?
Beta Was this translation helpful? Give feedback.
All reactions