-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support HTTP based Azure SDK service tracing by Spring Sleuth implementation #24192
Support HTTP based Azure SDK service tracing by Spring Sleuth implementation #24192
Conversation
This pull request is protected by Check Enforcer. What is Check Enforcer?Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass. Why am I getting this message?You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged. What should I do now?If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows: What if I am onboarding a new service?Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment: |
/azp run java - spring - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
private final Propagator propagator; | ||
|
||
// standard attributes with http call information | ||
private static final String HTTP_USER_AGENT = "http.user_agent"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you also take a look of this doc, let's make the tracing id aligned with the doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, which stage will this policy be added into pipeline, before or after retry? will retry requests be tracked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this policy will be placed after a HttpPipelinePosition.PER_RETRY by default, it uses the default pipeline position,
Line 37 in ed7d893
return HttpPipelinePosition.PER_RETRY; |
|
||
public final class HttpTraceUtil { | ||
|
||
private static final String STATUS_100 = "Continue"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to define these stuff by youslef, how about using something existing, like org.springframework.http.HttpStatus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, the dependency org.springframework:spring-web
will be added.
* </ul> | ||
*/ | ||
@Immutable | ||
public final class SpanId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is no such class within spring-cloud-sleuth project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, not found a suitable class.
/azp run java - spring - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run java - spring - tests |
2af1c96
to
0ec6837
Compare
sdk/spring/pom.xml
Outdated
@@ -194,6 +200,7 @@ | |||
<module>spring-cloud-azure-starter-stream-servicebus-queue</module> | |||
<module>spring-cloud-azure-stream-binder-servicebus-topic</module> | |||
<module>spring-cloud-azure-starter-stream-servicebus-topic</module> | |||
<module>spring-cloud-azure-trace-sleuth</module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move this after spring-cloud-azure-stream-binder-test
sdk/spring/pom.xml
Outdated
@@ -239,6 +246,7 @@ | |||
<module>spring-cloud-azure-starter-stream-servicebus-queue</module> | |||
<module>spring-cloud-azure-stream-binder-servicebus-topic</module> | |||
<module>spring-cloud-azure-starter-stream-servicebus-topic</module> | |||
<module>spring-cloud-azure-trace-sleuth</module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
/** | ||
* Auto-configuration for an Azure SDK Sleuth {@link Tracer}. | ||
*/ | ||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought there would be the following confusing log:
trationDelegate$BeanPostProcessorChecker : Bean 'com.azure.spring.cloud.autoconfigure.trace.sleuth.AzureSleuthAutoConfiguration' of type [com.azure.spring.cloud.autoconfigure.trace.sleuth.AzureSleuthAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying).
After added this @ROLE, it looks good.
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-sleuth-autoconfigure</artifactId> | ||
<version>3.0.3</version> <!-- {x-version-update;org.springframework.cloud:spring-cloud-sleuth-autoconfigure;external_dependency} --> | ||
<optional>true</optional> | ||
</dependency> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a @ConditionOnClass org.springframework.cloud.sleuth.autoconfig.SleuthTracerProperties
in AzureSleuthAutoConfiguration
.
*/ | ||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) | ||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnClass({ SleuthHttpPolicy.class, Tracer.class, SleuthTracerProperties.class }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to depend on the auto-configure of sleuth? Or is it enough if we find a Tracer bean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it's not required, the sleuth API Tracer class is enough.
@Override | ||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||
if (beanFactory != null && bean instanceof AbstractAzureHttpClientBuilderFactory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will the beanfactory be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to @nullable, it can be remove too.
<groupId>com.azure</groupId> | ||
<artifactId>azure-storage-blob</artifactId> | ||
<version>12.14.1</version> <!-- {x-version-update;com.azure:azure-storage-blob;dependency} --> | ||
<scope>test</scope> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding this storage blob dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for test blob service builder
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.1.2</version> <!-- {x-version-update;org.apache.maven.plugins:maven-jar-plugin;external_dependency} --> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied it from the core module, will remove it.
@Override | ||
public int getOrder() { | ||
return Ordered.LOWEST_PRECEDENCE; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding this Ordered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this bean should be the low precedence to register, after testing, it can be removed.
if ((boolean) context.getData(DISABLE_TRACING_KEY).orElse(false)) { | ||
return next.process(); | ||
} | ||
// tracer.getBaggage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this comment?
/azp run java - spring - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
…re-sdk-for-java into feature/azure-trace-sleuth-implementation
/azp run java - spring - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
Hey @moarychan and @saragluna I'm doing some changes in #25012 related to Tracer. I believe you can ignore the rest of that PR, as it's OTel-specific, but the important difference is on What I propose: let's use the same wider name (e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks fine, I left some minor comments.
The only blocker I see is docs: It's important to highlight that Sleuth integration is a solution that applies to existing Sleuth users and has limited functionality (i.e. HTTP requests tracing only). Microsoft supports OpenTelemetry company-wide and we should point users in this direction to provide a better long-term experience to users and avoid any reputational damage.
// run the next policy and handle success and error | ||
return next.process() | ||
.doOnEach(SleuthHttpPolicy::handleResponse) | ||
.contextWrite(Context.of("TRACING_SPAN", span, "REQUEST", request)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is "REQUEST" needed?
return next.process(); | ||
} | ||
|
||
Span parentSpan = (Span) context.getData(PARENT_SPAN_KEY).orElse(tracer.currentSpan()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to move span creation to contextWrite
similarly to
Line 99 in d304bb9
.contextWrite(reactor.util.context.Context.of(REACTOR_PARENT_TRACE_CONTEXT_KEY, startSpan(context))); |
It ensures that span is created when someone really subscribes to this reactor call and not on the hot path.
request.getHeaders().getValue("User-Agent")); | ||
putTagIfNotEmptyOrNull(span, HTTP_METHOD, request.getHttpMethod().toString()); | ||
putTagIfNotEmptyOrNull(span, HTTP_URL, request.getUrl().toString()); | ||
Optional<Object> tracingNamespace = context.getData(AZ_TRACING_NAMESPACE_KEY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are Otel conventions. Brave conventions are close, but not the same: https://github.com/openzipkin/brave/blob/master/instrumentation/http/README.md
requestId = response.getHeaderValue(REQUEST_ID); | ||
} | ||
|
||
putTagIfNotEmptyOrNull(span, REQUEST_ID, requestId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has been changed slightly here to be consistent across all languages 7a5d4ab#diff-74209afca0d9d5d4a8a40b7b0e0e28b0df6529e0e2af5c4fff1b33cc54ff4b24
// Error status, try to parse the error status. | ||
HttpStatus status = HttpStatus.resolve(statusCode); | ||
if (status != null) { | ||
return span.tag("http.status_message", status.getReasonPhrase()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use http.status_code
per brave conventions https://github.com/openzipkin/brave/blob/master/instrumentation/http/README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to modify it, please help provide more specific information.
[Source code][src] | [Package (Maven)][package] | [API reference documentation][refdocs] | ||
|
||
## Getting started | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Microsoft embraces OpenTelemetry, it's important to highlight here that it's the short term solution targeting existing Sleuth users with manual instrumentation.
I would suggest putting something along the lines of:
"Spring Cloud for Azure Sleuth Trace is the solution for users who manually instrumented their applications with Sleuth and are looking to add observability into HTTP requests made by Azure SDKs.
For everyone else, we recommend using OpenTelemetry as a ubiquitous and portable observability solution for tracing, metrics, and logs supported by most APM tools with extensive integrations across Java ecosystem"
Hi @lmolkova , Thank you so much for your comments. |
no problem, you can keep PARENT_SPAN_KEY for as long as you want - it's deprecated, but stays for a while. And azure-core is backward compatible with it |
/azp run java - spring - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
You can find the feature proposal here, this PR will support the service HTTP based, the tracer is delegated to Spring Sleuth, it's available to record the service activities when enabling the Spring Sleuth function.