question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing traceids/spanids to library functions and correlating calls

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
anandchughcommented, Jan 20, 2021

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

parent_tracer = <tracer-from-main.py>
tracer = Tracer(
                span_context=parent_tracer.span_context,
                exporter=log_exporter,
                sampler=sampler,
            )
0reactions
lzchencommented, Jan 19, 2021

Is it not possible to just set traceid rather than complete tracer in library?

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-processors

The field you are looking for is envelope.tags['ai.operation.id'].

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found