From a1c4f3bed94e5f6215c22b238a93e8b37074f9f8 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Mon, 9 Aug 2021 21:59:22 +0200 Subject: [PATCH] Java: Add OpenFeign integration docs. Fixes #3971 --- .../instrumentation/open-feign.mdx | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/platforms/java/performance/instrumentation/open-feign.mdx diff --git a/src/platforms/java/performance/instrumentation/open-feign.mdx b/src/platforms/java/performance/instrumentation/open-feign.mdx new file mode 100644 index 0000000000000..271635d1c72ea --- /dev/null +++ b/src/platforms/java/performance/instrumentation/open-feign.mdx @@ -0,0 +1,96 @@ +--- +title: OpenFeign Integration +sidebar_order: 20 +description: "Learn how to capture OpenFeign based HTTP clients performance" +--- + + + +Capturing transactions requires that you first set up performance monitoring if you haven't already. + + + +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} + + io.sentry + sentry-openfeign + {{ packages.version('sentry.java.openfeign', '5.1.0') }} + +``` + +```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/") +```