Skip to content

Commit 06b3c70

Browse files
Conditional on Brave's code for multiple tracer analysis; fixes gh-40
1 parent 585b3e8 commit 06b3c70

File tree

8 files changed

+164
-14
lines changed

8 files changed

+164
-14
lines changed

spring-cloud-sleuth-otel-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/otel/MultipleTracerAutoConfigurationsDetector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
* @author Jonatan Ivanov
3030
* @since 1.0.0
3131
*/
32-
@Configuration
33-
@ConditionalOnClass(name = "org.springframework.cloud.sleuth.autoconfig.brave.BraveAutoConfiguration")
32+
@Configuration(proxyBeanMethods = false)
33+
@ConditionalOnClass(name = "brave.Tracer")
3434
@ConditionalOnProperty(
3535
value = { "spring.sleuth.enabled", "spring.sleuth.otel.multiple-tracer-configs-detector-enabled" },
3636
matchIfMissing = true)
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,11 @@
2424

2525
import static org.assertj.core.api.Assertions.assertThat;
2626

27-
class MultipleTracerAutoConfigurationsDetectorTest {
28-
29-
@Test
30-
void should_fail_when_brave_and_otel_autoconfig_is_on_the_classpath() {
31-
new ApplicationContextRunner()
32-
.withConfiguration(AutoConfigurations.of(MultipleTracerAutoConfigurationsDetector.class))
33-
.run(context -> assertThat(context.getStartupFailure()).hasRootCauseInstanceOf(
34-
MultipleTracerAutoConfigurationsDetector.MultipleTracersFoundException.class));
35-
}
27+
class MultipleTracerAutoConfigurationsDetectorTests {
3628

3729
@Test
3830
void should_not_fail_when_brave_autoconfig_is_not_on_the_classpath() {
39-
new ApplicationContextRunner()
40-
.withClassLoader(new FilteredClassLoader(
41-
"org.springframework.cloud.sleuth.autoconfig.brave.BraveAutoConfiguration"))
31+
new ApplicationContextRunner().withClassLoader(new FilteredClassLoader("brave.Tracer"))
4232
.withConfiguration(AutoConfigurations.of(MultipleTracerAutoConfigurationsDetector.class))
4333
.run(context -> assertThat(context).hasNotFailed());
4434
}

tests/otel/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<module>spring-cloud-sleuth-instrumentation-rxjava-tests</module>
4949
<module>spring-cloud-sleuth-instrumentation-scheduling-tests</module>
5050
<module>spring-cloud-sleuth-instrumentation-webflux-tests</module>
51+
<module>spring-cloud-sleuth-multiple-tracers-otel-tests</module>
5152
<module>spring-cloud-sleuth-zipkin-tests</module>
5253
</modules>
5354

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2013-2020 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
~
18+
-->
19+
20+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns="http://maven.apache.org/POM/4.0.0"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<artifactId>spring-cloud-sleuth-multiple-tracers-otel-tests</artifactId>
26+
<packaging>jar</packaging>
27+
<name>Spring Cloud Sleuth OTel Multiple Tracers Tests</name>
28+
<description>Spring Cloud Sleuth OTel Multiple Tracers Tests</description>
29+
30+
<parent>
31+
<groupId>org.springframework.cloud</groupId>
32+
<artifactId>spring-cloud-sleuth-otel-tests</artifactId>
33+
<version>1.0.0-SNAPSHOT</version>
34+
<relativePath>..</relativePath>
35+
</parent>
36+
37+
<properties>
38+
<sonar.skip>true</sonar.skip>
39+
</properties>
40+
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<!--skip deploy -->
45+
<artifactId>maven-deploy-plugin</artifactId>
46+
<configuration>
47+
<skip>true</skip>
48+
</configuration>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
53+
<dependencies>
54+
<!-- Includes Brave! -->
55+
<dependency>
56+
<groupId>org.springframework.cloud</groupId>
57+
<artifactId>spring-cloud-starter-sleuth</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.springframework.cloud</groupId>
61+
<artifactId>spring-cloud-sleuth-otel-autoconfigure</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter-test</artifactId>
66+
</dependency>
67+
</dependencies>
68+
69+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.sleuth.autoconfig.otel;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
22+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
public class MultipleTracersTests {
28+
29+
@Test
30+
void should_fail_when_brave_and_otel_autoconfig_is_on_the_classpath() {
31+
new ApplicationContextRunner().withUserConfiguration(Config.class)
32+
.run(context -> assertThat(context.getStartupFailure()).hasRootCauseInstanceOf(
33+
MultipleTracerAutoConfigurationsDetector.MultipleTracersFoundException.class));
34+
}
35+
36+
@Configuration(proxyBeanMethods = false)
37+
@EnableAutoConfiguration
38+
static class Config {
39+
40+
}
41+
42+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
spring:
2+
application:
3+
name: service1
4+
sleuth:
5+
propagation:
6+
type:
7+
- b3
8+
baggage:
9+
remote-fields:
10+
- baggage
11+
- key
12+
otel:
13+
config:
14+
trace-id-ratio-based: 1.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.sleuth.otel.multiple-tracer-configs-detector-enabled: false
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2013-2018 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<configuration>
19+
<include resource="org/springframework/boot/logging/logback/base.xml"/>
20+
<logger name="feign" level="DEBUG"/>
21+
<logger name="com.netflix.discovery.InstanceInfoReplicator" level="ERROR"/>
22+
<logger name="org.springframework" level="INFO"/>
23+
<logger name="org.springframework.cloud.sleuth" level="TRACE"/>
24+
<logger name="org.springframework.boot.autoconfigure.logging" level="INFO"/>
25+
<logger name="org.springframework.cloud.sleuth.log" level="DEBUG"/>
26+
<logger name="org.springframework.cloud.sleuth.trace" level="DEBUG"/>
27+
<logger name="org.springframework.cloud.sleuth.instrument.rxjava" level="DEBUG"/>
28+
<logger name="org.springframework.cloud.sleuth.instrument.reactor" level="TRACE"/>
29+
<root level="INFO">
30+
<appender-ref ref="CONSOLE"/>
31+
<appender-ref ref="FILE"/>
32+
</root>
33+
</configuration>

0 commit comments

Comments
 (0)