|
7 | 7 |
|
8 | 8 | import static org.assertj.core.api.Assertions.assertThat;
|
9 | 9 |
|
| 10 | +import io.opentelemetry.api.GlobalOpenTelemetry; |
| 11 | +import io.opentelemetry.api.OpenTelemetry; |
10 | 12 | import io.opentelemetry.api.trace.Span;
|
11 | 13 | import io.opentelemetry.api.trace.SpanContext;
|
12 | 14 | import io.opentelemetry.context.Context;
|
| 15 | +import io.opentelemetry.context.propagation.ContextPropagators; |
| 16 | +import io.opentelemetry.extension.trace.propagation.JaegerPropagator; |
| 17 | +import java.net.URI; |
13 | 18 | import java.util.Collections;
|
14 | 19 | import java.util.Map;
|
15 | 20 | import org.apache.camel.Endpoint;
|
16 | 21 | import org.apache.camel.component.aws.sqs.SqsComponent;
|
17 | 22 | import org.apache.camel.component.aws.sqs.SqsConfiguration;
|
18 | 23 | import org.apache.camel.component.aws.sqs.SqsEndpoint;
|
| 24 | +import org.apache.camel.component.http.HttpComponent; |
| 25 | +import org.apache.camel.component.http.HttpEndpoint; |
| 26 | +import org.junit.jupiter.api.BeforeAll; |
19 | 27 | import org.junit.jupiter.api.Test;
|
20 | 28 |
|
21 | 29 | public class CamelPropagationUtilTest {
|
22 | 30 |
|
| 31 | + @BeforeAll |
| 32 | + public static void setUp() { |
| 33 | + GlobalOpenTelemetry.set( |
| 34 | + OpenTelemetry.getPropagating(ContextPropagators.create(JaegerPropagator.getInstance()))); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void shouldExtractHttpParentForHttpEndpoint() throws Exception { |
| 39 | + |
| 40 | + // given |
| 41 | + Endpoint endpoint = new HttpEndpoint("", new HttpComponent(), URI.create("")); |
| 42 | + Map<String, Object> exchangeHeaders = |
| 43 | + Collections.singletonMap( |
| 44 | + "uber-trace-id", "1f7f8dab3f0043b1b9cf0a75caf57510:a13825abcb764bd3:0:1"); |
| 45 | + |
| 46 | + // when |
| 47 | + Context parent = CamelPropagationUtil.extractParent(exchangeHeaders, endpoint); |
| 48 | + |
| 49 | + // then |
| 50 | + Span parentSpan = Span.fromContext(parent); |
| 51 | + SpanContext parentSpanContext = parentSpan.getSpanContext(); |
| 52 | + assertThat(parentSpanContext.getTraceId()).isEqualTo("1f7f8dab3f0043b1b9cf0a75caf57510"); |
| 53 | + assertThat(parentSpanContext.getSpanId()).isEqualTo("a13825abcb764bd3"); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void shouldNotFailExtractingNullHttpParentForHttpEndpoint() throws Exception { |
| 58 | + |
| 59 | + // given |
| 60 | + Endpoint endpoint = new HttpEndpoint("", new HttpComponent(), URI.create("")); |
| 61 | + Map<String, Object> exchangeHeaders = Collections.singletonMap("uber-trace-id", null); |
| 62 | + |
| 63 | + // when |
| 64 | + Context parent = CamelPropagationUtil.extractParent(exchangeHeaders, endpoint); |
| 65 | + |
| 66 | + // then |
| 67 | + Span parentSpan = Span.fromContext(parent); |
| 68 | + SpanContext parentSpanContext = parentSpan.getSpanContext(); |
| 69 | + assertThat(parentSpanContext.isValid()).isEqualTo(false); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void shouldNotFailExtractingNullAwsParentForSqsEndpoint() { |
| 74 | + |
| 75 | + // given |
| 76 | + Endpoint endpoint = new SqsEndpoint("", new SqsComponent(), new SqsConfiguration()); |
| 77 | + Map<String, Object> exchangeHeaders = Collections.singletonMap("AWSTraceHeader", null); |
| 78 | + |
| 79 | + // when |
| 80 | + Context parent = CamelPropagationUtil.extractParent(exchangeHeaders, endpoint); |
| 81 | + |
| 82 | + // then |
| 83 | + Span parentSpan = Span.fromContext(parent); |
| 84 | + SpanContext parentSpanContext = parentSpan.getSpanContext(); |
| 85 | + assertThat(parentSpanContext.isValid()).isEqualTo(false); |
| 86 | + } |
| 87 | + |
23 | 88 | @Test
|
24 |
| - public void shouldExtractAwsParent() { |
| 89 | + public void shouldExtractAwsParentForSqsEndpoint() { |
25 | 90 |
|
26 | 91 | // given
|
27 | 92 | Endpoint endpoint = new SqsEndpoint("", new SqsComponent(), new SqsConfiguration());
|
|
0 commit comments