Skip to content

Add automatic tracing propagation in RestClient (traceId, spanId) #34472

@mouadELOmari

Description

@mouadELOmari

Unlike WebClient, the new RestClient does not propagate tracing headers (e.g., traceId, spanId) automatically when using Micrometer Tracing.

Expected Behavior

When Spring Boot Observability (Micrometer Tracing) is enabled, RestClient should automatically inject the tracing headers, just like WebClient.
Currently, developers must manually add tracing headers to every request, either by:

  1. Manually adding headers to each request:
    RestClient restClient = RestClient.create();
    restClient.get()
        .uri("https://api.example.com")
        .header("traceparent", "12345")
        .header("x-span-id", "67890")
        .retrieve()
        .body(String.class);
  2. Using a custom ClientHttpRequestInterceptor, which requires additional setup.

Motivation

Many Spring developers are migrating from RestTemplate to RestClient because it is its official replacement. However, RestTemplate users often expect automatic observability/tracing, which is currently missing in RestClient.

WebClient provides this functionality out-of-the-box when Micrometer Tracing is enabled. RestClient should offer similar behavior to maintain consistency across Spring's HTTP clients.

Proposal

  • Automatically inject tracing headers (traceparent, x-span-id, etc.) when Spring Boot Observability (Micrometer Tracing) is enabled.
  • Provide a way to customize or disable this feature if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions