Skip to content

Commit

Permalink
Java: Add OpenFeign integration docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak committed Aug 9, 2021
1 parent ecc2735 commit a1c4f3b
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions src/platforms/java/performance/instrumentation/open-feign.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: OpenFeign Integration
sidebar_order: 20
description: "Learn how to capture OpenFeign based HTTP clients performance"
---

<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 `SentryFeignClient` that 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).

## 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 io.sentry.openfeign.SentryCapability

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(TodoApi::class.java, "https://jsonplaceholder.typicode.com/")
```

0 comments on commit a1c4f3b

Please sign in to comment.