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

Spring Webclient Header Propagation #149

Closed
cantaylancapraz opened this issue Jan 20, 2023 · 11 comments
Closed

Spring Webclient Header Propagation #149

cantaylancapraz opened this issue Jan 20, 2023 · 11 comments
Labels
question Further information is requested

Comments

@cantaylancapraz
Copy link

Hi,

Until this time, I was using spring cloud sleuth for propagation. I was using b3 propagation. However, after upgrading to spring 3.0 I removed sleuth, switched to micrometer tracing. I started not being able to propagate b3 headers.

I am using Spring 3.0 + Webflux + Webclient.

To be more specific, my request is:
When I call an endpoint that calls the external source via WebClient, headers such as X-B3-SpanId should be added if there is not, and propagate if there exists.

I did a lot of research, tried many ways, but couldn't solve my problem. I couldn't find any documentation or sample project that provides how to do it. Nothing I've tried has worked either.

I need the guidance of community.

Best regards

@marcingrzejszczak
Copy link
Contributor

Please check this sample for reference https://github.com/micrometer-metrics/micrometer-samples/tree/main/webflux

@cantaylancapraz
Copy link
Author

Thanks

I've actually seen this. But I believe it is very inefficient to apply this to many points in the code.
Maybe we can think about how we can make this work more practical.

@jonatan-ivanov
Copy link
Member

I think I might miss something but your issue is that B3 headers are not propagated when you receive a request with webflux and in the controller you want to send another with webclient?
Do you see the W3C header being propagated (traceparent)?

@cantaylancapraz
Copy link
Author

Yes.

When I don't set management.tracing.propagation.type as B3, traceparent header is propagated.

@cantaylancapraz
Copy link
Author

By the way, now I now able to pass a single b3 header. I will create a sample project and share it here.

However, following headers are still not propagated.
x-b3-parentspanid, x-b3-sampled, x-b3-spanid, x-b3-traceid

@jneate
Copy link

jneate commented Jan 25, 2023

@cantaylancapraz is a B3 header being propagated?

The issue we have is that after the upgrade it's defaulting to a single B3 header instead of the multiple X-B3 headers.
If we supply our own Propagation.Factory via

@Bean
Propagation.Factory get() {
    return B3Propagation.newFactoryBuilder().injectFormat(B3Propagation.Format.MULTI).build();
}

we gain the X-B3 multi headers but lose the propagation of remote baggage headers so that might fix your issue but it raises another one for us.

Not sure if there is a better/working way of forcing the propagation to use Multi headers instead of single?

(Related remote baggage fix micrometer-metrics/micrometer#3564)

@marcingrzejszczak
Copy link
Contributor

You're close @jneate , just create your beans like this

@Bean
		BaggagePropagation.FactoryBuilder myPropagationFactoryBuilder(
				ObjectProvider<BaggagePropagationCustomizer> baggagePropagationCustomizers) {
			Factory delegate = B3Propagation.newFactoryBuilder().injectFormat(B3Propagation.Format.MULTI).build();
			FactoryBuilder builder = BaggagePropagation.newFactoryBuilder(delegate);
			baggagePropagationCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
			return builder;
		}

@artemptushkin
Copy link

artemptushkin commented May 23, 2023

@marcingrzejszczak Hi, I bumped into this issue

it's defaulting to a single B3 header instead of the multiple X-B3 headers

I wonder why is it single b3 now and not multi? Is it documented somewhere? (I can not find) It's actually a breaking change that we could bypass, IMO

Can we expose it as a property to make it customizable on the consumer side?

Related to this code

@shakuzen
Copy link
Member

@artemptushkin see spring-projects/spring-boot#35096. We're working on improving the situation to improve flexibility and backward compatibility.

@artemptushkin
Copy link

@shakuzen this is different that you post, I'm asking about multi header approach

We had 3 headers with sb 2.7, e.g. x-b3-traceid and others
but now by default, it's just one header: b3

Please see this code https://github.com/spring-projects/spring-boot/blob/157b71b333473c2633b17362df1be83d6f9eaaed/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfiguration.java#L183

@shakuzen
Copy link
Member

shakuzen commented Jun 5, 2023

My apologies that things weren't reflected on the issue I linked or the pull request linked from there at the time I made my comment (I also didn't explicitly mention the linked pull request). We had already discussed internally about the requests here and elsewhere for b3 multi header support, and it was subsequently added to the pull request. Please see spring-projects/spring-boot#35611. That will add support for configuring b3 multi via properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants