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

Fixes apireview for sleuth #27621

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.propagation.Propagator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
Expand All @@ -30,13 +29,12 @@ public class AzureSleuthAutoConfiguration {
/**
* Autoconfigure the {@link HttpPipelinePolicy} for sleuth usage.
* @param tracer the sleuth {@link Tracer}.
* @param propagator the sleuth {@link Propagator}
* @return the http pipeline policy
*/
@Bean(name = DEFAULT_SLEUTH_HTTP_POLICY_BEAN_NAME)
@ConditionalOnMissingBean(name = DEFAULT_SLEUTH_HTTP_POLICY_BEAN_NAME)
public HttpPipelinePolicy azureSleuthHttpPolicy(Tracer tracer, Propagator propagator) {
return new SleuthHttpPolicy(tracer, propagator);
public HttpPipelinePolicy azureSleuthHttpPolicy(Tracer tracer) {
return new SleuthHttpPolicy(tracer);
}

@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
Expand Down
6 changes: 6 additions & 0 deletions sdk/spring/spring-cloud-azure-trace-sleuth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
<version>4.0.0</version><!-- {x-version-update;org.mockito:mockito-core;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-test</artifactId>
<version>1.7.8</version> <!-- {x-version-update;com.azure:azure-core-test;dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import com.azure.core.util.UrlBuilder;
import com.azure.spring.cloud.trace.sleuth.implementation.HttpTraceUtil;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.TraceContext;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.propagation.Propagator;
import org.springframework.util.Assert;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Signal;
Expand All @@ -28,7 +26,6 @@
import static com.azure.core.util.tracing.Tracer.AZ_TRACING_NAMESPACE_KEY;
import static com.azure.core.util.tracing.Tracer.DISABLE_TRACING_KEY;
import static com.azure.core.util.tracing.Tracer.PARENT_TRACE_CONTEXT_KEY;
import static com.azure.spring.cloud.trace.sleuth.implementation.TraceContextUtil.isValid;

/**
* Pipeline policy that creates a Sleuth span which traces the service request,
Expand All @@ -38,7 +35,6 @@ public class SleuthHttpPolicy implements HttpPipelinePolicy {

// Singleton Sleuth tracer capable of starting and exporting spans.
private final Tracer tracer;
private final Propagator propagator;

// standard attributes with http call information
private static final String HTTP_USER_AGENT = "http.user_agent";
Expand All @@ -51,13 +47,10 @@ public class SleuthHttpPolicy implements HttpPipelinePolicy {
/**
* Creates a new instance of {@link SleuthHttpPolicy}.
* @param tracer the tracer
* @param propagator the propagator
*/
public SleuthHttpPolicy(Tracer tracer, Propagator propagator) {
public SleuthHttpPolicy(Tracer tracer) {
Assert.notNull(tracer, "tracer must not be null!");
Assert.notNull(propagator, "propagator must not be null!");
this.tracer = tracer;
this.propagator = propagator;
}

@Override
Expand All @@ -71,9 +64,10 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN

// Build new child span representing this outgoing request.
final UrlBuilder urlBuilder = UrlBuilder.parse(context.getHttpRequest().getUrl());

Span.Builder spanBuilder = tracer.spanBuilder().name(urlBuilder.getPath())
.setParent(parentSpan.context());
Span.Builder spanBuilder = tracer.spanBuilder().name(urlBuilder.getPath());
if (parentSpan != null) {
spanBuilder.setParent(parentSpan.context());
}

// A span's kind can be SERVER (incoming request) or CLIENT (outgoing request);
spanBuilder.kind(Span.Kind.CLIENT);
Expand All @@ -86,12 +80,6 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
addSpanRequestAttributes(span, request, context); // Adds HTTP method, URL, & user-agent
}

// For no-op tracer, SpanContext is INVALID; inject valid span headers onto outgoing request
TraceContext traceContext = span.context();
if (isValid(traceContext)) {
propagator.inject(traceContext, request, contextSetter);
}

// run the next policy and handle success and error
return next.process()
.doOnEach(SleuthHttpPolicy::handleResponse)
Expand Down Expand Up @@ -175,8 +163,4 @@ private static void spanEnd(Span span, HttpResponse response, Throwable error) {
// Ending the span schedules it for export if sampled in or just ignores it if sampled out.
span.end();
}

// lambda that actually injects arbitrary header into the request
private final Propagator.Setter<HttpRequest> contextSetter =
(request, key, value) -> request.getHeaders().set(key, value);
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading