Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a trace ID from OpenTracing API?

In #105 davidB asks:

I would like to have read access to the Span id (SpanContext id) to be able to use it in log and in error reported (to end user,...). [skip] I need to expose the "trace id" in error message, then dev could use the trace to debug error reported by support, QA, end-user.

like image 686
Yuri Shkuro Avatar asked Mar 09 '17 15:03

Yuri Shkuro


People also ask

Is OpenTracing deprecated?

OpenTracing is now deprecated, and users of OpenTracing are advised to migrate to OpenTelemetry.

What is open tracing?

So, what is OpenTracing? It's a vendor-agnostic API to help developers easily instrument tracing into their code base. It's open because no one company owns it. In fact, many tracing tooling companies are getting behind OpenTracing as a standardized way to instrument distributed tracing.


2 Answers

At the moment the OpenTracing API does not expose trace ID. It is being discussed in this issue: https://github.com/opentracing/specification/issues/24

like image 162
Yuri Shkuro Avatar answered Dec 02 '22 22:12

Yuri Shkuro


One thing you can do right now is to call tracer.inject(null, Builtin.HTTP_HEADERS, map. It will put all IDs with baggage (SpanContext) into the map. Then you can get ID by its name. However this solution is not vedor neutral.

Other solution is to cast SpanContext into specific implementation and get the IDs by getter (if there is any)

like image 33
Pavol Loffay Avatar answered Dec 02 '22 22:12

Pavol Loffay