Java sdk passing spring sleuth traces

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.