How do I set custom "trace_id" for Datadog tracing?

6.9k views Asked by At

How do I set custom "trace_id" for Datadog tracing? I searched high and low but can't find an answer to this. I suspect it's not supported. Would really appreciate it if I can get some help here.

As an example, if I can do the following in multiple files, then I can view these spans together in the Datadog UI since they all have the same trace ID:

@tracer.wrap(service='foo', resource='bar')
def bar(self, ttt):
    span = tracer.current_span()
    span.set_trace_id("my_customer_trace_id")
2

There are 2 answers

0
Tony Jiang On BEST ANSWER

It turns out that trace id can be set via HTTP endpoint https://docs.datadoghq.com/api/v1/tracing/#send-traces. There doesn't seem to be an option for sending traces to the agent directly.

This can still be useful if the performance penalty of making HTTP calls is not a concern, i.e., if you are not working on a real-time system.

1
Alexey Shrub On

I am not well familiar with Datadog UI, but I see that ddtrace allow you to set tags:

span.set_tag('your_own_id', '12345')