GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
419 stars 312 forks source link

Help to Give preference to x-cloud-trace-context in context propagation spring boot 3 #2364

Open patan12 opened 11 months ago

patan12 commented 11 months ago

I have used stack driver logging in my application https://googlecloudplatform.github.io/spring-cloud-gcp/reference/html/index.html#log-via-console

From my client I am getting http requests with x-cloud-trace-context, so in gcp cloud run request log it is considering x-cloud-trace-context as traceid. Inside my application x-b3-traceid is working as traceid. So under one request there are two traces

  1. one at gcl cloud run req log level
  2. second at my application level

How can I give preference to x-cloud-trace-context in my application so all logs will be under one trace.

https://googlecloudplatform.github.io/spring-cloud-gcp/reference/html/index.html#cloud-logging:~:text=If%20you%20need%20different%20propagation%20behavior%20(e.g.%20relying%20primarily%20on%20x%2Dcloud%2Dtrace%2Dcontext%20in%20a%20mixed%20Spring%20/%20non%2DSpring%20application%20environment)%2C%20Micrometer%20allows%20such%20customization%20through%20the%20CUSTOM%20propagation%20type.

Any code samples would be of great help

Dependencies used:

com.google.cloud:spring-cloud-gcp-dependencies:4.7.2 org.springframework.boot:spring-boot-dependencies:3.1.5

diegomarquezp commented 11 months ago

Hi @patan12, thanks for raising this concern. It looks like we can expand the documentation to clarify this. Would you mind sharing a reproducible example to look into how to prioritize an arbitrary tracing key via "CUSTOM propagation type"?

Also, if you have a support plan, feel free to reach out to our support hub for faster response times.

Thanks!

patan12 commented 11 months ago

@diegomarquezp Thank you for checking this. I am not able to find any code snippet mathching my requirement. my requirement is simple, if there is x-cloud-trace-context, form the trace by that id. else fall back to x-b3-traceid. Any custom spring component can be written with micrometer that will solve my issue.it will be great