Fork me on GitHub
#clj-otel
<
2023-12-05
>
devurandom13:12:34

@steffan I am trying to set up a valid trace context (in a unit test for a custom trace propagation via our task queue). I started with (span/with-span! {:name ,,,} ,,,), but that was not enough. The W3CTraceContextPropagator would not propagate the span, presumably because (= false (.isValid (span/get-span-context))). I had to add a hand-crafted span context until "span is valid" showed "true" and the W3CTraceContextPropagator would do anything:

(context/with-value! (Span/wrap (SpanContext/create "1234567890abcdef1234567890abcdef"
                                                    "1234567890abcdef"
                                                    (TraceFlags/getDefault)
                                                    (TraceState/getDefault)))
  (span/with-span! {:name "TEST"}
    (println "SPAN IS VALID" (.isValid (span/get-span-context)))
    ,,,))
Is this expected? I assume I am somehow outside of clj-otel's "safe zone"? Is there a better / correct way to do this with clj-otel built-in functions?

steffan15:12:26

with-span! and similar create a new context containing the span. Running the following with the OpenTelemetry agent with default propagators (which include the W3C Trace Context propagator) shows the headers to include when propagating the context:

(span/with-span! {:name "Testing"}
  (println (context/->headers)))
Gives output like:
{traceparent 00-8ab99ecb31257e6bf05fe2f820c3d228-b403f6b75fabbd5f-01}
Remember that clj-otel-api will default to a no-op implementation if your test is run without an implementation of the OpenTelemetry API.

thanks2 1