forked from getsentry/sentry-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java: Add OpenFeign integration docs.
Fixes getsentry#3971
- Loading branch information
1 parent
ecc2735
commit a1c4f3b
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
src/platforms/java/performance/instrumentation/open-feign.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/") | ||
``` |