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>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-openfeign</artifactId>
<version>8.65.0</version>
</dependency>
implementation 'io.sentry:sentry-openfeign:8.65.0'
libraryDependencies += "io.sentry" % "sentry-openfeign" % "8.65.0"
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/");
import feign.Feign;
import io.sentry.openfeign.SentryCapability;
YourApi api = Feign.builder()
.addCapability(new SentryCapability())
...
.target(YourApi.class, "https://your-api-host/");
import feign.Feign
import io.sentry.openfeign.SentryCapability
val api = Feign.builder()
.addCapability(SentryCapability())
...
.target(YourApi::class.java, "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()));
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/");
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/");
import feign.Feign
import feign.Request
import feign.Response
import io.sentry.ISpan
import io.sentry.openfeign.SentryCapability
import io.sentry.openfeign.SentryFeignClient.BeforeSpanCallback
val api = Feign.builder()
.addCapability(
SentryCapability(
BeforeSpanCallback { span: ISpan, request: Request, response: Response? ->
// modify span or return `null` to drop
if (request.url().endsWith("/todos")) {
span.setTag("tag-name", "tag-value")
}
span
}))
.target(YourApi::class.java, "https://your-api-host/")
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").