Skip to content

Commit

Permalink
Add spring support for enabling 128 bit trace id generation (#58)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonah Back <[email protected]>
  • Loading branch information
backjo authored and geoand committed Aug 23, 2019
1 parent 50c3302 commit f8f921b
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import io.opentracing.contrib.java.spring.jaeger.starter.JaegerConfigurationProperties.RemoteReporter;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.B3CodecTracerBuilderCustomizer;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.ExpandExceptionLogsTracerBuilderCustomizer;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.HigherBitTracerBuilderCustomizer;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand Down Expand Up @@ -79,8 +81,8 @@ public io.opentracing.Tracer tracer(Sampler sampler,
@ConditionalOnMissingBean
@Bean
public Reporter reporter(JaegerConfigurationProperties properties,
Metrics metrics,
@Autowired(required = false) ReporterAppender reporterAppender) {
Metrics metrics,
@Autowired(required = false) ReporterAppender reporterAppender) {

List<Reporter> reporters = new LinkedList<>();
RemoteReporter remoteReporter = properties.getRemoteReporter();
Expand All @@ -104,19 +106,19 @@ public Reporter reporter(JaegerConfigurationProperties properties,
}

private Reporter getUdpReporter(Metrics metrics,
RemoteReporter remoteReporter,
JaegerConfigurationProperties.UdpSender udpSenderProperties) {
RemoteReporter remoteReporter,
JaegerConfigurationProperties.UdpSender udpSenderProperties) {
io.jaegertracing.thrift.internal.senders.UdpSender udpSender =
new io.jaegertracing.thrift.internal.senders.UdpSender(
udpSenderProperties.getHost(), udpSenderProperties.getPort(),
udpSenderProperties.getMaxPacketSize());
udpSenderProperties.getHost(), udpSenderProperties.getPort(),
udpSenderProperties.getMaxPacketSize());

return createReporter(metrics, remoteReporter, udpSender);
}

private Reporter getHttpReporter(Metrics metrics,
RemoteReporter remoteReporter,
JaegerConfigurationProperties.HttpSender httpSenderProperties) {
RemoteReporter remoteReporter,
JaegerConfigurationProperties.HttpSender httpSenderProperties) {
io.jaegertracing.thrift.internal.senders.HttpSender.Builder builder =
new io.jaegertracing.thrift.internal.senders.HttpSender.Builder(httpSenderProperties.getUrl());
if (httpSenderProperties.getMaxPayload() != null) {
Expand All @@ -133,7 +135,7 @@ private Reporter getHttpReporter(Metrics metrics,
}

private Reporter createReporter(Metrics metrics,
RemoteReporter remoteReporter, Sender udpSender) {
RemoteReporter remoteReporter, Sender udpSender) {
io.jaegertracing.internal.reporters.RemoteReporter.Builder builder =
new io.jaegertracing.internal.reporters.RemoteReporter.Builder()
.withSender(udpSender)
Expand Down Expand Up @@ -212,6 +214,15 @@ public TracerBuilderCustomizer b3CodecJaegerTracerCustomizer() {
}
}

@Configuration
@ConditionalOnProperty(value = "opentracing.jaeger.enable-128-bit-traces")
public static class HigherBitTraceConfiguration {
@Bean
public TracerBuilderCustomizer higherBitJaegerTracerCustomizer() {
return new HigherBitTracerBuilderCustomizer();
}
}

@Configuration
@ConditionalOnProperty(value = "opentracing.jaeger.expand-exception-logs")
public static class ExpandExceptionLogsConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public class JaegerConfigurationProperties {
*/
private boolean enableB3Propagation = false;

/**
* Enable the generation of 128 bit trace ids. Default is 64 bit.
*/
private boolean enable128BitTraces = false;

private boolean expandExceptionLogs = false;

private Map<String, String> tags = new HashMap<>();
Expand Down Expand Up @@ -96,6 +101,14 @@ public void setEnableB3Propagation(boolean enableB3Propagation) {
this.enableB3Propagation = enableB3Propagation;
}

public boolean isEnable128BitTraces() {
return enable128BitTraces;
}

public void setEnable128BitTraces(boolean enable128BitTraces) {
this.enable128BitTraces = enable128BitTraces;
}

public boolean isExpandExceptionLogs() {
return expandExceptionLogs;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2018-2019 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;
import io.opentracing.contrib.java.spring.jaeger.starter.TracerBuilderCustomizer;

public class HigherBitTracerBuilderCustomizer implements TracerBuilderCustomizer {
@Override
public void customize(JaegerTracer.Builder builder) {
builder.withTraceId128Bit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2018-2019 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.TracerBuilderCustomizer;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.HigherBitTracerBuilderCustomizer;
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-128-bit-traces=false"
}
)
public class JaegerTracerHigherBitCustomizerDisabledSpringTest {
@Autowired(required = false)
private List<TracerBuilderCustomizer> customizers;

@Test
public void testCustomizersShouldContainB3Customizer() {
if (customizers == null) {
return;
}

assertThat(customizers)
.extracting("class").doesNotContain(HigherBitTracerBuilderCustomizer.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2018-2019 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.HigherBitTracerBuilderCustomizer;
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-128-bit-traces=true"
}
)
public class JaegerTracerHigherBitCustomizerEnabledSpringTest extends AbstractTracerSpringTest {

@Autowired
private List<TracerBuilderCustomizer> customizers;

@Test
public void testCustomizersShouldContainB3Customizer() {
assertThat(customizers)
.isNotEmpty()
.extracting("class").contains(HigherBitTracerBuilderCustomizer.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2018 The OpenTracing Authors
* Copyright 2018-2019 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 @@ -11,7 +11,6 @@
* 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;
Expand All @@ -22,7 +21,10 @@
import io.opentracing.contrib.java.spring.jaeger.starter.TracerBuilderCustomizer;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.B3CodecTracerBuilderCustomizer;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.ExpandExceptionLogsTracerBuilderCustomizer;
import io.opentracing.contrib.java.spring.jaeger.starter.customizers.HigherBitTracerBuilderCustomizer;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -38,7 +40,8 @@
properties = {
"spring.main.banner-mode=off",
"opentracing.jaeger.expand-exception-logs=true",
"opentracing.jaeger.enable-b3-propagation=true"
"opentracing.jaeger.enable-b3-propagation=true",
"opentracing.jaeger.enable-128-bit-traces=true"
}
)
public class MultipleCustomizersEnabledSpringTest extends AbstractTracerSpringTest {
Expand All @@ -52,9 +55,10 @@ public void testCustomizersShouldContainB3Customizer() {
.isNotEmpty()
.extracting("class")
.containsExactlyInAnyOrder(
ExpandExceptionLogsTracerBuilderCustomizer.class,
B3CodecTracerBuilderCustomizer.class,
MockTracerBuilderCustomizer.class);
ExpandExceptionLogsTracerBuilderCustomizer.class,
B3CodecTracerBuilderCustomizer.class,
HigherBitTracerBuilderCustomizer.class,
MockTracerBuilderCustomizer.class);
}

@Configuration
Expand All @@ -69,6 +73,7 @@ public TracerBuilderCustomizer mockCustomizer() {
public static class MockTracerBuilderCustomizer implements TracerBuilderCustomizer {

@Override
public void customize(Builder builder) {}
public void customize(Builder builder) {
}
}
}

0 comments on commit f8f921b

Please sign in to comment.