Java sdk passing spring sleuth traces

Hi

Im a temporal n00b. Im liking what temporal gives. So currently we are trying to integrate temporal into an already existing application. So far so good.

We use springboot a lot including Spring sleuth and brave zipkin.

Has anyone managed to integrate Spring sleuth with temporal workflow and activities?

We are using spring sleuth 2, so the use case is from a RestController it starts the temporal workflow. The temporal activity will then call a grpc microservices. I would like to be able to pass and log the traceId, parentTraceId across all other micro services.

I am thinking of using interceptors, but where im struggling to figure out is how do i get these things i pass in the interceptor from within activity methods

Thanks for the help!!

Hi!

Sleuth can be set up and used over OpenTracing to pass Spans: Spring Cloud Sleuth

Temporal also supports OpenTracing:

This module helps Temporal to propagate and pass OpenTracing spans between client, workflow, and activities.

So, if you set up everything in the following manner:

things should just work.

Thanks. I will give this a try.
In any case, Is there a way for an activity method to access headers (i assume these are http headers)
Thanks again

No, there is no direct way to access headers from an activity code.
Activities should be oblivious of the transport layer and should be focused on business logic. So, there is no way to access HTTP, gRPC, or Temporal Headers and it’s like that by design.

Temporal has its own concept of headers and exactly that Temporal headers are used to implement opentracing/opentelemetry or how Temporal passes org.slf4j.MDC values around.

You have access to Temporal Headers in two ways:

  1. Interceptors give direct access to them. This is a very powerful, but pretty nuanced and complicated route. I don’t recommend going there if you are new and don’t have a solid understanding of how things are wired together yet. Interceptors exist mostly for framework development for integrations and extension points. We don’t intend users to use Interceptors directly in most cases.
  2. ContextPropagator is a user-facing abstraction over Temporal Headers. See the ContextPropagator Javadoc or this thread for example: Usage of ContextPropagator in Java SDK - #3 by sdwr98 ContextPropagator can be used to serialize-deserialize and pass a context between client->workflow->activity.

We don’t recommend touching HTTP or gRPC headers from any Temporal code, because both HTTP and gRPC are transport layer implementation details. That’s why we provide a concept of Temporal Headers to abstract it out and ContextPropagators to give even higher-level abstraction.

Feel free to reach out on Temporal Slack (@Dmitry) if you prefer to have a call to discuss your specific use-case.

Sorry for the late response.

Thanks @spikhalskiy for giving a detailed explanation. I ended up using the ContextPropagator as you said a higher level of abstraction over interceptor.

I tried the OpenTracingInterceptor, but for sone reason i couldn’t make it work. I didn’t try hard enough tho.

I patterned the sample you have on how to use the ContextPropagator with MDC. It is looking good.
Thanks again.