Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Add OpenFeign integration docs. #3996

Merged
merged 7 commits into from
Aug 19, 2021
100 changes: 100 additions & 0 deletions src/platforms/java/performance/instrumentation/open-feign.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: OpenFeign Integration
sidebar_order: 20
description: "Learn how to capture the performance of OpenFeign-based HTTP clients."
---

<Note>

Capturing transactions requires that you first <PlatformLink to="/performance/">set up performance monitoring</PlatformLink> if you haven't already.

</Note>

Sentry OpenFeign integration provides the `SentryFeignClient`, which creates a span for each outgoing HTTP request executed with a [Feign](https://github.com/OpenFeign/feign)-based HTTP client.

### Install

```xml {tabTitle:Maven}
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-openfeign</artifactId>
<version>{{ packages.version('sentry.java.openfeign', '5.1.0') }}</version>
</dependency>
```

```groovy {tabTitle:Gradle}
implementation 'io.sentry:sentry-openfeign:{{ packages.version('sentry.java.openfeign', '5.1.0') }}'
```

```scala {tabTitle: SBT}
libraryDependencies += "io.sentry" % "sentry-openfeign" % "{{ packages.version('sentry.java.openfeign', '5.1.0') }}"
```

For other dependency managers see the [central Maven repository](https://search.maven.org/artifact/io.sentry/sentry-openfeign).
marandaneto marked this conversation as resolved.
Show resolved Hide resolved

## Configure

Add `SentryCapability` to Feign builder:

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

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

```kotlin
import feign.Feign
import io.sentry.openfeign.SentryCapability

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

## Modify or Drop Spans

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

```java
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/");
```

```kotlin
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? ->
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
// 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/")
```