-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
247 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...trib/java/spring/jaeger/starter/customizers/TraceContextCodecTracerBuilderCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2018-2021 The OpenTracing Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package io.opentracing.contrib.java.spring.jaeger.starter.customizers; | ||
|
||
import io.jaegertracing.internal.JaegerTracer.Builder; | ||
import io.jaegertracing.internal.propagation.TraceContextCodec; | ||
import io.opentracing.contrib.java.spring.jaeger.starter.TracerBuilderCustomizer; | ||
import io.opentracing.propagation.Format; | ||
|
||
public class TraceContextCodecTracerBuilderCustomizer implements TracerBuilderCustomizer { | ||
|
||
@Override | ||
public void customize(Builder builder) { | ||
TraceContextCodec injector = new TraceContextCodec.Builder().build(); | ||
|
||
builder.registerInjector(Format.Builtin.HTTP_HEADERS, injector) | ||
.registerExtractor(Format.Builtin.HTTP_HEADERS, injector); | ||
|
||
builder.registerInjector(Format.Builtin.TEXT_MAP, injector) | ||
.registerExtractor(Format.Builtin.TEXT_MAP, injector); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ing/jaeger/starter/customizer/JaegerTracerTraceContextCustomerizerDisabledSpringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2018-2021 The OpenTracing Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.opentracing.contrib.java.spring.jaeger.starter.customizer; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentracing.contrib.java.spring.jaeger.starter.AbstractTracerSpringTest; | ||
import io.opentracing.contrib.java.spring.jaeger.starter.TracerBuilderCustomizer; | ||
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.TraceContextCodecTracerBuilderCustomizer; | ||
import java.util.List; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
@TestPropertySource( | ||
properties = { | ||
"spring.main.banner-mode=off", | ||
"opentracing.jaeger.enable-w3c-propagation=false" | ||
} | ||
) | ||
public class JaegerTracerTraceContextCustomerizerDisabledSpringTest extends AbstractTracerSpringTest { | ||
|
||
@Autowired(required = false) | ||
private List<TracerBuilderCustomizer> customizers; | ||
|
||
@Test | ||
public void testCustomizersShouldContainTraceContextCustomizer() { | ||
if (customizers == null) { | ||
return; | ||
} | ||
|
||
assertThat(customizers) | ||
.extracting("class").doesNotContain(TraceContextCodecTracerBuilderCustomizer.class); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ring/jaeger/starter/customizer/JaegerTracerTraceContextCustomerizerEnabledSpringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2018-2021 The OpenTracing Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.opentracing.contrib.java.spring.jaeger.starter.customizer; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.opentracing.contrib.java.spring.jaeger.starter.AbstractTracerSpringTest; | ||
import io.opentracing.contrib.java.spring.jaeger.starter.TracerBuilderCustomizer; | ||
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.TraceContextCodecTracerBuilderCustomizer; | ||
import java.util.List; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
@TestPropertySource( | ||
properties = { | ||
"spring.main.banner-mode=off", | ||
"opentracing.jaeger.enable-w3c-propagation=true" | ||
} | ||
) | ||
public class JaegerTracerTraceContextCustomerizerEnabledSpringTest extends AbstractTracerSpringTest { | ||
|
||
@Autowired | ||
private List<TracerBuilderCustomizer> customizers; | ||
|
||
@Test | ||
public void testCustomizersShouldContainTraceContextCustomizer() { | ||
assertThat(customizers) | ||
.isNotEmpty() | ||
.extracting("class").contains(TraceContextCodecTracerBuilderCustomizer.class); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
.../spring/jaeger/starter/customizer/JaegerTracerTraceContextCustomizerCustomSpringTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright 2018-2021 The OpenTracing Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.opentracing.contrib.java.spring.jaeger.starter.customizer; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.jaegertracing.internal.JaegerSpanContext; | ||
import io.opentracing.Tracer; | ||
import io.opentracing.contrib.java.spring.jaeger.starter.AbstractTracerSpringTest; | ||
import io.opentracing.contrib.java.spring.jaeger.starter.TracerBuilderCustomizer; | ||
import io.opentracing.propagation.Format; | ||
import io.opentracing.propagation.TextMap; | ||
import io.opentracing.propagation.TextMapAdapter; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
|
||
@TestPropertySource( | ||
properties = { | ||
"spring.main.banner-mode=off", | ||
"opentracing.jaeger.enable-w3c-propagation=true" | ||
} | ||
) | ||
@Import(JaegerTracerTraceContextCustomizerCustomSpringTest.TestConfiguration.class) | ||
public class JaegerTracerTraceContextCustomizerCustomSpringTest extends AbstractTracerSpringTest { | ||
|
||
@Autowired | ||
private Tracer tracer; | ||
|
||
public static class TestConfiguration { | ||
@Bean | ||
public TracerBuilderCustomizer myCustomizer() { | ||
// Noop | ||
return builder -> { | ||
}; | ||
} | ||
} | ||
|
||
@Test | ||
public void testCustomizersHttpHeadersShouldContainTraceContext() { | ||
TextMap textMap = createTextMap(); | ||
|
||
JaegerSpanContext context = (JaegerSpanContext) tracer.extract(Format.Builtin.HTTP_HEADERS, textMap); | ||
|
||
assertOnTraceContextHeaders(context); | ||
} | ||
|
||
@Test | ||
public void testCustomizersTextMapShouldContainTraceContext() { | ||
TextMap textMap = createTextMap(); | ||
|
||
JaegerSpanContext context = (JaegerSpanContext) tracer.extract(Format.Builtin.TEXT_MAP, textMap); | ||
|
||
assertOnTraceContextHeaders(context); | ||
} | ||
|
||
private TextMapAdapter createTextMap() { | ||
Map<String, String> carrier = new HashMap<>(); | ||
carrier.put("traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"); | ||
carrier.put("tracestate", "congo=t61rcWkgMzE"); | ||
|
||
return new TextMapAdapter(carrier); | ||
} | ||
|
||
private void assertOnTraceContextHeaders(JaegerSpanContext context) { | ||
// Note: This test ensures that W3C Trace Context codec actually works | ||
// If it would not, values would never be extracted from B3 headers and context will be null | ||
assertThat(context).isNotNull(); | ||
assertThat(context.getTraceId()).isEqualTo("4bf92f3577b34da6a3ce929d0e0e4736"); | ||
assertThat(context.getSpanId()).isEqualTo(67667974448284343L); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters