OpenFeign Integration for Spring Boot

Learn how to capture tracing information of OpenFeign-based HTTP clients.

Capturing transactions requires that you first set up tracing if you haven't already.

Sentry OpenFeign integration provides the SentryFeignClient, which creates a span for each outgoing HTTP request executed with a Feign-based HTTP client.

<dependency>
    <groupId>io.sentry</groupId>
    <artifactId>sentry-openfeign</artifactId>
    <version>8.65.0</version>
</dependency>

For other dependency managers see the central Maven repository.

Add SentryCapability to Feign builder:

import feign.Feign;
import io.sentry.openfeign.SentryCapability;

YourApi api = Feign.builder()
    .addCapability(new SentryCapability())
    ...
    .target(YourApi.class, "https://your-api-host/");

OpenFeign adds URLs to HTTP spans and breadcrumbs. Use dataCollection.urlQueryParams to filter or omit their query parameters:

import io.sentry.KeyValueCollectionBehavior;
import io.sentry.Sentry;

Sentry.init(
    options ->
        options
            .getDataCollection()
            .setUrlQueryParams(KeyValueCollectionBehavior.off()));

Configuring this field activates the Data Collection defaults for omitted fields. The base URL is still sent when query parameter collection is disabled.

Spans created around HTTP requests can be modified or dropped using SentryFeignClient.BeforeSpanCallback passed to SentryCapability:

import feign.Feign;
import io.sentry.openfeign.SentryCapability;

YourApi api = Feign.builder()
    .addCapability(
        new SentryCapability(
            (span, request, response) -> {
              // modify span or return `null` to drop
              if (request.url().endsWith("/todos")) {
                span.setTag("tag-name", "tag-value");
              }
              return span;
            }))
    ...
    .target(YourApi.class, "https://your-api-host/");
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").