Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

No way to access trace id/span id #146

Open
AudriusButkevicius opened this issue Aug 23, 2021 · 3 comments
Open

No way to access trace id/span id #146

AudriusButkevicius opened this issue Aug 23, 2021 · 3 comments

Comments

@AudriusButkevicius
Copy link

As it stands, the interfaces do not provide a way to access the trace id, nor the span id.

Jaeger client exposes span.trace_id and span.span_id, but if the tracer is not initialised, that obviously blows up, as the noop span doesn't have those attributes, requiring people to do hasattr checks.

It's useful to log the trace id/span id of the request being started, which can later be used to debug issues with the request somewhere downstream.

@yurishkuro
Copy link
Member

This was never implemented in Python opentracing/specification#123

@AudriusButkevicius
Copy link
Author

AudriusButkevicius commented Aug 23, 2021

What's the reason behind that, other than "nobody got to it", and what would the implementation look like?

@ibnu-assaumi
Copy link

try this way:

from opentracing.span import Span
from opentracing.propagation import Format

def get_trace_id(span:Span=None):
    if span is None:
        return ""
    
    try:
        carrier = {}
        span.tracer.inject(
            span_context=span.context,
            format=Format.TEXT_MAP,
            carrier=carrier
        )        
        return '{}'.format(carrier['uber-trace-id']).split(':')[0]
    except Exception as e:
        return ""

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants