@Test void baggageCanaryActiveSpan() { logger.info(">>> START TEST: baggageCanaryActiveSpan"); final var tracer = io.helidon.tracing.Tracer.global(); final var span = tracer.spanBuilder("SpanCurrentTest::baggageCanaryActiveSpan").start(); boolean ended = false; try (final var ignored = span.activate()) { // Make 'span' logically Span.current() // Set baggage and confirm that it's known in the span span.baggage("first", "1"); assertEquals("1", span.baggage("first").orElseThrow(() -> new IllegalStateException("baggage not retrievable in creating span!"))); span.baggage("second", "2"); assertEquals("2", span.baggage("second").orElseThrow(() -> new IllegalStateException("baggage not retrievable in creating span!"))); span.baggage("third", "3"); assertEquals("3", span.baggage("third").orElseThrow(() -> new IllegalStateException("baggage not retrievable in creating span!"))); // Inject the span (context) into the consumer using a "newly created" OpenTracingSpan // This causes the SpanContext to be updated in OpenTracingSpan. final var consumer = HeaderConsumer .create(new TreeMap<>(String.CASE_INSENSITIVE_ORDER)); tracer.inject(io.helidon.tracing.Span.current().orElseThrow(() -> new IllegalStateException("Span::current empty after activate!")) .context(), HeaderProvider.empty(), consumer); // Confirm that baggage was propagated (workaround the bug with Span::current) // Fixed in Helidon v3.2.2 by https://github.com/helidon-io/helidon/issues/6970 (or 7018)! final var allItems = StreamSupport.stream(consumer.keys().spliterator(), false) .map(k -> k+"="+consumer.getAll(k)).collect(Collectors.joining(", ")); assertTrue(allItems.contains("first") && allItems.contains("second") && allItems.contains("third") , () -> "All baggage items (first,second,third) not found propagated in: "+allItems); } catch (final Exception x) { span.end(x); ended = true; } finally { if (!ended) span.end(); logger.info(">>> END TEST: baggageCanaryActiveSpan"); } }