Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract tracer implementations via an API #1757

Merged
merged 46 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f14ac04
Code almost compiles
marcingrzejszczak Sep 24, 2020
6bd88c4
It compiles
marcingrzejszczak Sep 24, 2020
8e7b5a2
Polish
marcingrzejszczak Sep 24, 2020
313e0e8
Passing tests
marcingrzejszczak Sep 24, 2020
00c4e49
WIP on tests
marcingrzejszczak Sep 25, 2020
917c911
Tests are passing
marcingrzejszczak Sep 28, 2020
c5d86a0
Moved properties around, added modules, added otel module
marcingrzejszczak Sep 29, 2020
55bfac1
OTel test
marcingrzejszczak Sep 30, 2020
e790432
BRave works
marcingrzejszczak Oct 1, 2020
b9802c6
Compiles
marcingrzejszczak Oct 2, 2020
8c0431f
All tests but one are working
marcingrzejszczak Oct 2, 2020
a526ad4
Fixed inet address resolution
marcingrzejszczak Oct 5, 2020
150c584
Passing tests
marcingrzejszczak Oct 6, 2020
3525599
Added noop impls
marcingrzejszczak Oct 6, 2020
1f4596b
Common non tracer specific tests
marcingrzejszczak Oct 6, 2020
8ad02ba
Abstracted tests
marcingrzejszczak Oct 6, 2020
059b92e
Common tests for Brave are passing
marcingrzejszczak Oct 7, 2020
978a422
Tests are passing
marcingrzejszczak Oct 8, 2020
25670e5
Annotations
marcingrzejszczak Oct 9, 2020
fa9b9b8
Opentracing
marcingrzejszczak Oct 9, 2020
61c430d
Moar tests
marcingrzejszczak Oct 9, 2020
b6f3db7
WIP
marcingrzejszczak Oct 10, 2020
bd6daa9
All tests working
marcingrzejszczak Oct 12, 2020
fe1c504
Abstracted messaging
marcingrzejszczak Oct 13, 2020
1e74a37
Refactored tests
marcingrzejszczak Oct 13, 2020
3f6303b
Moar messaging tests
marcingrzejszczak Oct 13, 2020
4f8bd4e
Added baggage
marcingrzejszczak Oct 14, 2020
67baf88
WIP on new api
marcingrzejszczak Oct 15, 2020
56bd0d4
Handling mechanism
marcingrzejszczak Oct 15, 2020
40dbe82
WIP
marcingrzejszczak Oct 15, 2020
a7040c1
Basic baggage support for OTEL via the new api
marcingrzejszczak Oct 16, 2020
5c987f5
All tests are passing
marcingrzejszczak Oct 19, 2020
e5c175e
Samples are working fine
marcingrzejszczak Oct 19, 2020
d10c1eb
Core module with javadocs
marcingrzejszczak Oct 19, 2020
c6eb665
Brave module with javadocs
marcingrzejszczak Oct 19, 2020
e7c7cc4
it works
marcingrzejszczak Oct 19, 2020
71952ac
Fixed build setup
marcingrzejszczak Oct 19, 2020
b9f9b86
Added checkstyle test for tests/common
marcingrzejszczak Oct 19, 2020
908c7f3
Added w3c propagation for otel & brave
marcingrzejszczak Oct 20, 2020
98500c5
Added JMH benchmarks for bridge
marcingrzejszczak Oct 20, 2020
90290f0
Oleg oleg oleg
marcingrzejszczak Oct 22, 2020
cba608c
Messaging is failing
marcingrzejszczak Oct 22, 2020
f38ab04
Fixed the messaaging sample
marcingrzejszczak Oct 22, 2020
ba3a087
Ignored broken Function integration
marcingrzejszczak Oct 22, 2020
a386393
Merge branch 'master' into otel_abstracted_new_api
marcingrzejszczak Oct 22, 2020
8e8d5d6
Removed commons-lang3 dependency
marcingrzejszczak Oct 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
479 changes: 61 additions & 418 deletions README.adoc

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-cloud-starter-sleuth-otel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

import javax.annotation.PreDestroy;

import brave.Span;
import brave.Tracer;
import brave.sampler.Sampler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand All @@ -41,6 +38,8 @@
import org.springframework.cloud.sleuth.annotation.ContinueSpan;
import org.springframework.cloud.sleuth.annotation.NewSpan;
import org.springframework.cloud.sleuth.annotation.SpanTag;
import org.springframework.cloud.sleuth.api.Span;
import org.springframework.cloud.sleuth.api.Tracer;
import org.springframework.cloud.sleuth.instrument.web.SkipPatternProvider;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -121,11 +120,6 @@ public void clean() {
this.pool.shutdownNow();
}

@Bean
Sampler alwaysSampler() {
return Sampler.ALWAYS_SAMPLE;
}

@Bean
AnotherClass anotherClass() {
return new AnotherClass(this.tracer);
Expand Down Expand Up @@ -165,11 +159,11 @@ class AClass {

public String manualSpan() {
Span manual = this.tracer.nextSpan().name("span-name");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(manual.start())) {
try (Tracer.SpanInScope ws = this.tracer.withSpan(manual.start())) {
return this.anotherClass.continuedSpan();
}
finally {
manual.finish();
manual.end();
}
}

Expand All @@ -196,9 +190,9 @@ public String continuedAnnotation(@SpanTag("foo") String tagValue) {
public String continuedSpan() {
Span span = this.tracer.currentSpan();
span.tag("foo", "bar");
span.annotate("continuedspan.before");
span.event("continuedspan.before");
String response = "continued";
span.annotate("continuedspan.after");
span.event("continuedspan.after");
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import brave.Tracing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -106,16 +106,16 @@ public Function<Message<String>, Message<String>> simpleFunctionWithAround() {

@Bean(name = "myFlux")
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "simple_manual")
public Function<Message<String>, Message<String>> simpleManual(Tracing tracing) {
public Function<Message<String>, Message<String>> simpleManual(BeanFactory beanFactory) {
System.out.println("simple_manual_function");
return new SimpleManualFunction(tracing);
return new SimpleManualFunction(beanFactory);
}

@Bean(name = "myFlux")
@ConditionalOnProperty(value = "spring.sleuth.function.type", havingValue = "reactive_simple_manual")
public Function<Flux<Message<String>>, Flux<Message<String>>> reactiveSimpleManual(Tracing tracing) {
public Function<Flux<Message<String>>, Flux<Message<String>>> reactiveSimpleManual(BeanFactory beanFactory) {
System.out.println("simple_reactive_manual_function");
return new SimpleReactiveManualFunction(tracing);
return new SimpleReactiveManualFunction(beanFactory);
}

@Bean(name = "myFlux")
Expand Down Expand Up @@ -170,22 +170,22 @@ class SimpleManualFunction implements Function<Message<String>, Message<String>>

private static final Logger log = LoggerFactory.getLogger(SimpleFunction.class);

private final Tracing tracing;
private final BeanFactory beanFactory;

SimpleManualFunction(Tracing tracing) {
this.tracing = tracing;
SimpleManualFunction(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}

@Override
public Message<String> apply(Message<String> input) {
return (MessagingSleuthOperators.asFunction(this.tracing, input)
.andThen(msg -> MessagingSleuthOperators.withSpanInScope(this.tracing, msg, stringMessage -> {
return (MessagingSleuthOperators.asFunction(this.beanFactory, input)
.andThen(msg -> MessagingSleuthOperators.withSpanInScope(this.beanFactory, msg, stringMessage -> {
log.info("Hello from simple manual [{}]", stringMessage.getPayload());
return stringMessage;
})).andThen(msg -> MessagingSleuthOperators.afterMessageHandled(this.tracing, msg, null))
.andThen(msg -> MessagingSleuthOperators.handleOutputMessage(this.tracing, msg))
})).andThen(msg -> MessagingSleuthOperators.afterMessageHandled(this.beanFactory, msg, null))
.andThen(msg -> MessagingSleuthOperators.handleOutputMessage(this.beanFactory, msg))
.andThen(msg -> MessageBuilder.createMessage(msg.getPayload().toUpperCase(), msg.getHeaders()))
.andThen(msg -> MessagingSleuthOperators.afterMessageHandled(this.tracing, msg, null)).apply(input));
.andThen(msg -> MessagingSleuthOperators.afterMessageHandled(this.beanFactory, msg, null)).apply(input));
}

}
Expand All @@ -207,21 +207,21 @@ class SimpleReactiveManualFunction implements Function<Flux<Message<String>>, Fl

private static final Logger log = LoggerFactory.getLogger(SimpleReactiveFunction.class);

private final Tracing tracing;
private final BeanFactory beanFactory;

SimpleReactiveManualFunction(Tracing tracing) {
this.tracing = tracing;
SimpleReactiveManualFunction(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}

@Override
public Flux<Message<String>> apply(Flux<Message<String>> input) {
return input.map(message -> (MessagingSleuthOperators.asFunction(this.tracing, message))
.andThen(msg -> MessagingSleuthOperators.withSpanInScope(this.tracing, msg, stringMessage -> {
return input.map(message -> (MessagingSleuthOperators.asFunction(this.beanFactory, message))
.andThen(msg -> MessagingSleuthOperators.withSpanInScope(this.beanFactory, msg, stringMessage -> {
log.info("Hello from simple manual [{}]", stringMessage.getPayload());
return stringMessage;
})).andThen(msg -> MessagingSleuthOperators.afterMessageHandled(this.tracing, msg, null))
})).andThen(msg -> MessagingSleuthOperators.afterMessageHandled(this.beanFactory, msg, null))
.andThen(msg -> MessageBuilder.createMessage(msg.getPayload().toUpperCase(), msg.getHeaders()))
.andThen(msg -> MessagingSleuthOperators.handleOutputMessage(this.tracing, msg)).apply(message));
.andThen(msg -> MessagingSleuthOperators.handleOutputMessage(this.beanFactory, msg)).apply(message));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import brave.handler.SpanHandler;
import brave.propagation.TraceContext;
import brave.sampler.Sampler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
Expand All @@ -37,6 +34,7 @@
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.reactive.context.ReactiveWebServerInitializedEvent;
import org.springframework.cloud.sleuth.api.TraceContext;
import org.springframework.cloud.sleuth.instrument.web.SkipPatternProvider;
import org.springframework.cloud.sleuth.instrument.web.WebFluxSleuthOperators;
import org.springframework.context.ApplicationListener;
Expand Down Expand Up @@ -73,11 +71,6 @@ public Mono<String> foo() {
return Mono.just("foo");
}

@Bean
Sampler alwaysSampler() {
return Sampler.ALWAYS_SAMPLE;
}

@Bean
SkipPatternProvider patternProvider() {
return () -> Pattern.compile("");
Expand All @@ -89,13 +82,6 @@ NettyReactiveWebServerFactory nettyReactiveWebServerFactory(@Value("${server.por
return new NettyReactiveWebServerFactory(serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}

@Bean
public SpanHandler spanHandler() {
return new SpanHandler() {
// intentionally anonymous to prevent logging fallback on NOOP
};
}

@Override
public void onApplicationEvent(ReactiveWebServerInitializedEvent event) {
this.port = event.getWebServer().getPort();
Expand Down Expand Up @@ -135,7 +121,7 @@ public Mono<String> complex() {
log.info("Doing assertions");
TraceContext traceContext = signal.getContext().get(TraceContext.class);
Assert.notNull(traceContext, "Context must be set by Sleuth instrumentation");
Assert.state(traceContext.traceIdString().equals("4883117762eb9420"), "TraceId must be propagated");
Assert.state(traceContext.traceId().equals("4883117762eb9420"), "TraceId must be propagated");
log.info("Assertions passed");
});
}
Expand All @@ -151,7 +137,7 @@ public Mono<String> complexManual() {
WebFluxSleuthOperators.withSpanInScope(signal.getContext(), () -> log.info("Doing assertions"));
TraceContext traceContext = signal.getContext().get(TraceContext.class);
Assert.notNull(traceContext, "Context must be set by Sleuth instrumentation");
Assert.state(traceContext.traceIdString().equals("4883117762eb9420"), "TraceId must be propagated");
Assert.state(traceContext.traceId().equals("4883117762eb9420"), "TraceId must be propagated");
log.info("Assertions passed");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ protected ConfigurableApplicationContext initContext() {
protected String[] runArgs() {
List<String> strings = new ArrayList<>();
strings.addAll(Arrays.asList("--spring.jmx.enabled=false",
"--spring.autoconfigure.exclude=org.springframework.cloud.sleuth.otel.autoconfig.TraceOtelAutoConfiguration",
"--spring.application.name=defaultTraceContextForStream" + instrumentation.name()));
strings.addAll(instrumentation.entires.stream().map(s -> "--" + s).collect(Collectors.toList()));
return strings.toArray(new String[0]);
Expand Down Expand Up @@ -151,7 +152,7 @@ public enum Instrumentation {

}

@Configuration
@Configuration(proxyBeanMethods = false)
@Import(TestChannelBinderConfiguration.class)
static class TestConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2016-2019 the original author or 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
*
* https://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 org.springframework.cloud.sleuth.benchmarks.jmh;

import org.springframework.cloud.sleuth.brave.autoconfig.TraceBraveAutoConfiguration;
import org.springframework.cloud.sleuth.otel.autoconfig.TraceOtelAutoConfiguration;

public enum TracerImplementation {

otel(TraceBraveAutoConfiguration.class.getCanonicalName()), brave(
TraceOtelAutoConfiguration.class.getCanonicalName());

private String key = "spring.autoconfigure.exclude";

private String value;

TracerImplementation(String value) {
this.value = value;
}

public String property() {
return "--" + this.key + "=" + this.value;
}

@Override
public String toString() {
return this.name();
}

}
Loading