dd-trace-java
dd-trace-java copied to clipboard
Can we add Datadog span/traces to the messages/events that are pushed in the queue (RabbitMq or Kafka) ? I would like to add datadog trace to the message and end that span on consumer side.
Yes, this should work out-of-the-box if you attach the Java Tracer to both producing and consuming sides.
The produce span will be attached to the consume span in the distributed trace - if you want a span covering the time spent in the queue then set -Ddd.kafka.legacy.tracing.enabled=false (-Ddd.rabbitmq.legacy.tracing.enabled=false if you're using RabbitMQ)
Actually, I want to add the the span to every event on the producer side. While on the consumer side, I would like to extract span from that event. There can be multiple producer and consumer with different spans. Is it possible to add span to the event if yes can you share some documentation ?
The trace id and producing span id will be automatically added to every message if you have the Java Tracer attached to the JVM producing the message. Likewise if you have the Java Tracer attached to the JVM consuming messages then it will detect messages containing trace and span ids and automatically create consume spans that link back to the producer span.
If you want to do some/all of this yourself then you could follow this example https://github.com/DataDog/dd-trace-java-kinesis-example which demonstrates how to inject and extract the trace context.
func Inject(ctx ddtrace.SpanContext, carrier interface{}) error { return internal.GetGlobalTracer().Inject(ctx, carrier) }
In golang don't we need to pass the builtin format while injecting ? Opentracing allows us to choose between textmap,Httpheaders,binary etc but in datadog trace injection are we using a default builtin format ?
This github repository is for the Java Tracer - golang is a separate repository but it should also let you inject and extract trace and span ids.
Regarding trace/span ids you can choose to use the Datadog format or codecs like B3: https://docs.datadoghq.com/tracing/setup_overview/custom_instrumentation/java/#b3-headers-extraction-and-injection
You can also use the OpenTracing API to get the current trace/span ids, propagate them via headers or the message content, and extract them into new spans on the other side because the Java Tracer supports the OpenTracing API
May I ask you to document these properties in the official DataDog docs? It will also help DataDog's sales engineers, as they seemed to not be aware this exists.