GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp

Support For W3C Trace Propagation

Open
#2,921 0 comments 7 reactions 0 assignees View on GitHub
priority: p2 type: enhancement
Dominant language
Java
Stars
551
Forks
349
Avg merge
1d 13h
Merged PRs (30d)
14

Description

Please understand that my English may be awkward and I may appear rude.

## Problem
I use GCP Cloud Run and it only use w3c trace propagation spec only.
you can see the documentation about it ([link](https://cloud.google.com/run/docs/trace))

and in `com.google.cloud.spring.autoconfigure.trace.StackdriverTraceAutoConfiguration` it use b3 propagation only

```
@Bean
@ConditionalOnMissingBean
public BaggagePropagation.FactoryBuilder baggagePropagationFactoryBuilder() {
Propagation.Factory primary = B3Propagation.newFactoryBuilder().injectFormat(Format.MULTI).build();
return BaggagePropagation.newFactoryBuilder(StackdriverTracePropagation.newFactory(primary));
}
```



so the problem is when request pass many server and in log explorer,


GCP Cloud Run's trace id and spring cloud gcp's trace id is different like picture below. (in trace:)


(first one is cloud run's log and second one is spring cloud gcp's log)


gcp generate another trace id because it doesn't understand b3 header i think.



![400d1750-acbd-4300-8350-5d9f8c98f92a](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/assets/62408879/4308dc07-bcb2-4f14-8ac1-9ff1369514fe)

## My Workaround
so i wrote a code in my common lib like below and it work now, but i think it's not solid code.

```
@AutoConfiguration(before = {StackdriverTraceAutoConfiguration.class})
@ConditionalOnProperty(prefix = "temp", name = "enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(TracingPropagationProperties.class)
public class TracingPropagationConfig {

@Bean
@ConditionalOnMissingBean(BaggagePropagation.FactoryBuilder.class)
public BaggagePropagation.FactoryBuilder baggagePropagationFactoryBuilder(TracingPropagationProperties properties) {
Propagation.Factory primary = getPropagation(properties.type());
return BaggagePropagation.newFactoryBuilder(StackdriverTracePropagation.newFactory(primary));
}
private Factory getPropagation(PropagationType type) {
return switch (type) {
case W3C -> new W3CPropagation();
case B3 -> B3Propagation.newFactoryBuilder().injectFormat(Format.MULTI).build();
};
}
}
```

## Suggestion
Any plan to support w3c propagation?

Contributor guide

Open the contributing guide

Research direction

Start with com.google.cloud.spring.autoconfigure.trace.StackdriverTraceAutoConfiguration and its baggagePropagationFactoryBuilder method, then inspect how propagation is currently configured. Define how W3C propagation should coexist with the existing B3 behavior; done means Cloud Run and Spring Cloud GCP use the same trace ID across requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, java, spring
Domain
backend, cloud, observability
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.