You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Cloud OpenFeign集成Zipkin报500错误:original request is required

Fixing "original request is required" Error with Spring Cloud OpenFeign + Zipkin/Sleuth

Hey there, let's work through this "original request is required" error you're facing when integrating Zipkin with Spring Cloud OpenFeign. I’ve dealt with this exact issue before, so here’s a breakdown of what’s happening and how to fix it:

Why This Happens

The root cause is that Feign doesn’t automatically pass along the Sleuth-generated tracing headers (like X-B3-TraceId, X-B3-SpanId, and X-B3-Sampled) by default. When your Feign client calls a downstream service, without these headers, Sleuth can’t correlate the request to the existing trace context—hence the "original request is required" error.

Solutions

1. Use Sleuth’s Built-in Feign Interceptor (Simplest Fix)

Spring Cloud Sleuth provides a dedicated interceptor to handle tracing header propagation for Feign. You can enable it globally or per Feign client:

Global Configuration (application.yml)

Add this to your application config to apply it to all Feign clients:

feign:
  client:
    config:
      default:
        request-interceptors:
          - org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignRequestInterceptor

Java Configuration Class

If you prefer Java-based config, create a configuration bean:

@Configuration
public class FeignTracingConfig {
    @Bean
    public TraceFeignRequestInterceptor traceFeignRequestInterceptor(Tracer tracer) {
        return new TraceFeignRequestInterceptor(tracer);
    }
}

You can also annotate specific Feign clients with @FeignClient(configuration = FeignTracingConfig.class) to apply it only to that client.

2. Verify Dependencies Are Correct

Double-check you have all required dependencies, and that their versions match your Spring Cloud release train:

Maven Dependencies

<dependencies>
    <!-- Sleuth + Zipkin -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zipkin</artifactId>
    </dependency>
    <!-- OpenFeign -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
</dependencies>

Make sure your Spring Cloud version (e.g., 2022.0.x "Kilburn") is compatible with these starters.

3. Custom Feign Interceptor (For Advanced Cases)

If you need to pass additional custom headers alongside tracing ones, you can create a custom interceptor:

@Configuration
public class CustomFeignRequestInterceptor implements RequestInterceptor {
    private final Tracer tracer;

    // Inject Sleuth's Tracer via constructor
    public CustomFeignRequestInterceptor(Tracer tracer) {
        this.tracer = tracer;
    }

    @Override
    public void apply(RequestTemplate template) {
        Span currentSpan = tracer.currentSpan();
        if (currentSpan != null) {
            // Propagate Sleuth tracing headers
            template.header("X-B3-TraceId", currentSpan.context().traceId());
            template.header("X-B3-SpanId", currentSpan.context().spanId());
            template.header("X-B3-Sampled", currentSpan.context().sampled() ? "1" : "0");
        }
        // Add any other custom headers you need to pass
        // template.header("Custom-Header", "value");
    }
}

Then reference this interceptor in your Feign client or global config.

4. Validate Zipkin Connection Settings

Ensure your service is pointing to the correct Zipkin server and sampling is enabled:

spring:
  zipkin:
    base-url: http://localhost:9411/ # Match your Zipkin server address
  sleuth:
    sampler:
      probability: 1.0 # Set to 1.0 for debugging; adjust for production

Final Tips

Start with the first solution (using the built-in TraceFeignRequestInterceptor)—it’s the official, most reliable way to fix this issue. After applying it, restart your services and test the Feign calls again. The tracing headers should now be propagated correctly, and the "original request is required" error should disappear.

内容的提问来源于stack exchange,提问作者ilovespring

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:07:23