Search code examples
pythonapitracedatadogapm

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


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")

Solution

  • 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.