|
17 | 17 |
|
18 | 18 | import io.micrometer.tracing.Link;
|
19 | 19 | import io.micrometer.tracing.Span;
|
| 20 | +import io.micrometer.tracing.TraceContext; |
20 | 21 | import io.opentelemetry.api.common.AttributeKey;
|
21 | 22 | import io.opentelemetry.context.propagation.ContextPropagators;
|
22 | 23 | import io.opentelemetry.extension.trace.propagation.B3Propagator;
|
@@ -47,6 +48,11 @@ class OtelSpanBuilderTests {
|
47 | 48 |
|
48 | 49 | io.opentelemetry.api.trace.Tracer otelTracer = openTelemetrySdk.getTracer("io.micrometer.micrometer-tracing");
|
49 | 50 |
|
| 51 | + OtelCurrentTraceContext otelCurrentTraceContext = new OtelCurrentTraceContext(); |
| 52 | + |
| 53 | + OtelTracer tracer = new OtelTracer(otelTracer, otelCurrentTraceContext, event -> { |
| 54 | + }); |
| 55 | + |
50 | 56 | @Test
|
51 | 57 | void should_set_child_span_when_using_builders() {
|
52 | 58 |
|
@@ -98,6 +104,21 @@ void should_set_non_string_tags() {
|
98 | 104 | then(poll.getAttributes().get(AttributeKey.booleanKey("boolean"))).isTrue();
|
99 | 105 | }
|
100 | 106 |
|
| 107 | + @Test |
| 108 | + void should_honor_parent_context_using_tracecontextbuilder() { |
| 109 | + Span foo = tracer.spanBuilder().name("foo").start(); |
| 110 | + |
| 111 | + TraceContext parentCtx = tracer.traceContextBuilder() |
| 112 | + .traceId(foo.context().traceId()) |
| 113 | + .spanId(foo.context().spanId()) |
| 114 | + .sampled(foo.context().sampled()) |
| 115 | + .build(); |
| 116 | + |
| 117 | + Span span = tracer.spanBuilder().setParent(parentCtx).name("test-span").start(); |
| 118 | + |
| 119 | + then(span.context().traceId()).isEqualTo(foo.context().traceId()); |
| 120 | + } |
| 121 | + |
101 | 122 | private Map<String, Object> tags() {
|
102 | 123 | Map<String, Object> map = new HashMap<>();
|
103 | 124 | map.put("tag1", "value1");
|
|
0 commit comments