Skip to content

Commit

Permalink
Bump to Jaeger Client 1.3.2 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand authored Feb 1, 2021
1 parent fbb64c8 commit b4a8f74
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018-2020 The OpenTracing Authors
* 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
Expand Down Expand Up @@ -32,6 +32,7 @@
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.ExpandExceptionLogsTracerBuilderCustomizer;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.HigherBitTracerBuilderCustomizer;

import io.opentracing.contrib.java.spring.jaeger.starter.customizers.TraceContextCodecTracerBuilderCustomizer;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -214,6 +215,16 @@ public TracerBuilderCustomizer b3CodecJaegerTracerCustomizer() {
}
}

@Configuration
@ConditionalOnProperty(value = "opentracing.jaeger.enable-w3c-propagation")
public static class TraceContextCodecConfiguration {

@Bean
public TracerBuilderCustomizer traceContextCodecJaegerTracerCustomizer() {
return new TraceContextCodecTracerBuilderCustomizer();
}
}

@Configuration
@ConditionalOnProperty(value = "opentracing.jaeger.enable-128-bit-traces")
public static class HigherBitTraceConfiguration {
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018-2020 The OpenTracing Authors
* 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
Expand All @@ -21,31 +21,30 @@
import io.jaegertracing.spi.Reporter;
import org.assertj.core.api.Condition;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.api.InstanceOfAssertFactory;

public abstract class AbstractSenderSpringTest extends AbstractTracerSpringTest {

protected void assertSenderClass(Class senderClass) {
assertThat(getTracer())
.extracting("reporter")
.extracting("class", as(InstanceOfAssertFactories.CLASS))
.isEqualTo(CompositeReporter.class);
.extracting("reporter")
.extracting("class", as(InstanceOfAssertFactories.CLASS))
.isEqualTo(CompositeReporter.class);

assertThat(getTracer())
.extracting("reporter").isInstanceOfSatisfying(CompositeReporter.class, c -> {
assertThat(c)
.extracting("reporters", as(InstanceOfAssertFactories.list(Reporter.class)))
.filteredOn(new Condition<Object>() {
@Override
public boolean matches(Object value) {
return value.getClass().equals(RemoteReporter.class);
}
}).allSatisfy(rr -> {
assertThat(rr)
.extracting("reporter").isInstanceOfSatisfying(CompositeReporter.class, c -> {
assertThat(c)
.extracting("reporters", as(InstanceOfAssertFactories.list(Reporter.class)))
.filteredOn(new Condition<Object>() {
@Override
public boolean matches(Object value) {
return value.getClass().equals(RemoteReporter.class);
}
}).allSatisfy(rr -> {
assertThat(rr)
.extracting("sender")
.extracting("class", as(InstanceOfAssertFactories.CLASS))
.isEqualTo(senderClass);
});
});
});
});
}
}
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);
}
}
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);
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018-2020 The OpenTracing Authors
* 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
Expand All @@ -23,6 +23,7 @@
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.ExpandExceptionLogsTracerBuilderCustomizer;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.HigherBitTracerBuilderCustomizer;

import io.opentracing.contrib.java.spring.jaeger.starter.customizers.TraceContextCodecTracerBuilderCustomizer;
import java.util.List;

import org.junit.Test;
Expand All @@ -41,6 +42,7 @@
"spring.main.banner-mode=off",
"opentracing.jaeger.expand-exception-logs=true",
"opentracing.jaeger.enable-b3-propagation=true",
"opentracing.jaeger.enable-w3c-propagation=true",
"opentracing.jaeger.enable-128-bit-traces=true"
}
)
Expand All @@ -57,6 +59,7 @@ public void testCustomizersShouldContainB3Customizer() {
.containsExactlyInAnyOrder(
ExpandExceptionLogsTracerBuilderCustomizer.class,
B3CodecTracerBuilderCustomizer.class,
TraceContextCodecTracerBuilderCustomizer.class,
HigherBitTracerBuilderCustomizer.class,
MockTracerBuilderCustomizer.class);
}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2018-2020 The OpenTracing Authors
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
Expand Down Expand Up @@ -67,7 +67,7 @@
<version.io.opentracing.contrib-opentracing-spring-tracer>0.4.0</version.io.opentracing.contrib-opentracing-spring-tracer>
<version.io.opentracing.contrib-opentracing-spring-web-starter>4.0.0</version.io.opentracing.contrib-opentracing-spring-web-starter>
<version.org.springframework.boot>2.3.4.RELEASE</version.org.springframework.boot>
<version.jaeger>1.1.0</version.jaeger>
<version.jaeger>1.3.2</version.jaeger>
<version.org.awaitility-awaitility>3.0.0</version.org.awaitility-awaitility>
<version.test-containers>1.7.3</version.test-containers>

Expand Down

0 comments on commit b4a8f74

Please sign in to comment.