Passing traceids/spanids to library functions and correlating calls
See original GitHub issueI have a python library which implements Open census logging.
How to pass traceid from main application to the library functions so that all calls from main application can be correlated with library functions? Also, is it possible to see those calls in Application map. Is there some sample code covering this scenario? Do we also need to take care about passing span-ids?
Here is test code:
Wheel Package contains util.py
. This is part of a library
This contains some functions like
def test():
logger.info("Test Log")
with tracer.span(name="span1"):
test2()
Now this library function is called from some other application main.py
from util import test
logger = logging.getlogger()
log_exporter = AzureExporter(connection_string=app_insights_cs)
tracer = Tracer(exporter=log_exporter, sampler=AlwaysOnSampler()
with tracer.span(name="test"):
test()
``
I would like correlate calls from main to test() and then test2() function.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Distributed tracing with Spring Cloud Sleuth and Zipkin
Trace ID — Trace ID is the equivalent term for correlation ID. It's a unique number that represents an entire transaction. Span ID—...
Read more >Spring Boot and Tracing Calls - The Blog of Ivan Krizsan
We can see that the values passed in the HTTP headers “x-b3-traceid” and “x-b3-spanid” are the values that are used for the trace...
Read more >Spring Cloud Sleuth - Single Application
This article focuses on using Spring Sleuth for tracing requests within a single application use cases.
Read more >How to Do Tracing in Go Microservice? | by Jin Feng
Under a trace, there are many spans, each captures a unit of work inside the calling chain and it is identified by “spanId”....
Read more >Spring Cloud Sleuth Features
Besides trace identifiers, other properties (Baggage) can also be passed along ... services that connect the trace together: traceId and spanId notably.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @lzchen I was able to resolve this issue by doing like this:
In main.py, first we can created tracer and pass it to util.py In util.py, create tracer using span_context of passed tracer
Yes you can use
telemetry_processor
to modify traceid before export. https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-filtering-sampling#opencensus-python-telemetry-processorsThe field you are looking for is
envelope.tags['ai.operation.id']
.