Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ targets:
maven:io.sentry:sentry-android-fragment:
maven:io.sentry:sentry-bom:
maven:io.sentry:sentry-openfeign:
#maven:io.sentry:sentry-openfeature:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: OpenFeature module commented out in release registry

The sentry-openfeature entry is commented out in the craft registry configuration while the module is fully implemented and integrated. This will prevent the artifact from being published to Maven Central during releases, making it unavailable to users despite being documented and built.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: OpenFeature module commented out in release registry

The sentry-openfeature entry is commented out in the craft registry while the module is fully implemented and integrated. This will prevent the artifact from being published to Maven Central during releases, making it unavailable to users despite being documented and built.

Fix in Cursor Fix in Web

maven:io.sentry:sentry-opentelemetry-agent:
maven:io.sentry:sentry-opentelemetry-agentcustomization:
maven:io.sentry:sentry-opentelemetry-agentless:
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ body:
- sentry-graphql-22
- sentry-quartz
- sentry-openfeign
- sentry-openfeature
- sentry-apache-http-client-5
- sentry-okhttp
- sentry-reactor
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features

- Implement OpenFeature Integration that tracks Feature Flag evaluations ([#4910](https://github.com/getsentry/sentry-java/pull/4910))
- To make use of it, add the `sentry-openfeature` dependency and register the the hook using: `openFeatureApiInstance.addHooks(new SentryOpenFeatureHook());`
- Detect oversized events and reduce their size ([#4903](https://github.com/getsentry/sentry-java/pull/4903))
- You can opt into this new behaviour by setting `enableEventSizeLimiting` to `true` (`sentry.enable-event-size-limiting=true` for Spring Boot `application.properties`)
- You may optionally register an `onOversizedEvent` callback to implement custom logic that is executed in case an oversized event is detected
Expand Down
93 changes: 47 additions & 46 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ object Config {
val SENTRY_GRAPHQL22_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.graphql22"
val SENTRY_QUARTZ_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.quartz"
val SENTRY_JDBC_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.jdbc"
val SENTRY_OPENFEATURE_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.openfeature"
val SENTRY_SERVLET_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.servlet"
val SENTRY_SERVLET_JAKARTA_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.servlet.jakarta"
val SENTRY_COMPOSE_HELPER_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.compose.helper"
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ minSdk = "21"
spotless = "7.0.4"
gummyBears = "0.12.0"
camerax = "1.3.0"
openfeature = "1.18.2"

[plugins]
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Expand Down Expand Up @@ -124,6 +125,7 @@ nopen-annotations = { module = "com.jakewharton.nopen:nopen-annotations", versio
nopen-checker = { module = "com.jakewharton.nopen:nopen-checker", version.ref = "nopen" }
nullaway = { module = "com.uber.nullaway:nullaway", version = "0.9.5" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
openfeature = { module = "dev.openfeature:sdk", version.ref = "openfeature" }
otel = { module = "io.opentelemetry:opentelemetry-sdk", version.ref = "otel" }
otel-extension-autoconfigure = { module = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure", version.ref = "otel" }
otel-extension-autoconfigure-spi = { module = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi", version.ref = "otel" }
Expand Down
10 changes: 10 additions & 0 deletions sentry-openfeature/api/sentry-openfeature.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public final class io/sentry/openfeature/BuildConfig {
public static final field SENTRY_OPENFEATURE_SDK_NAME Ljava/lang/String;
public static final field VERSION_NAME Ljava/lang/String;
}

public final class io/sentry/openfeature/SentryOpenFeatureHook : dev/openfeature/sdk/BooleanHook {
public fun <init> ()V
public fun after (Ldev/openfeature/sdk/HookContext;Ldev/openfeature/sdk/FlagEvaluationDetails;Ljava/util/Map;)V
}

91 changes: 91 additions & 0 deletions sentry-openfeature/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import net.ltgt.gradle.errorprone.errorprone
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`java-library`
id("io.sentry.javadoc")
alias(libs.plugins.kotlin.jvm)
jacoco
alias(libs.plugins.errorprone)
alias(libs.plugins.gradle.versions)
alias(libs.plugins.buildconfig)
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
compilerOptions.languageVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9
compilerOptions.apiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9
}

dependencies {
api(projects.sentry)

compileOnly(libs.openfeature)

compileOnly(libs.jetbrains.annotations)
compileOnly(libs.nopen.annotations)
errorprone(libs.errorprone.core)
errorprone(libs.nopen.checker)
errorprone(libs.nullaway)

// tests
testImplementation(projects.sentry)
testImplementation(projects.sentryTestSupport)
testImplementation(kotlin(Config.kotlinStdLib))
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.mockito.inline)
testImplementation(libs.openfeature)
}

configure<SourceSetContainer> { test { java.srcDir("src/test/java") } }

jacoco { toolVersion = libs.versions.jacoco.get() }

tasks.jacocoTestReport {
reports {
xml.required.set(true)
html.required.set(false)
}
}

tasks {
jacocoTestCoverageVerification {
violationRules { rule { limit { minimum = Config.QualityPlugins.Jacoco.minimumCoverage } } }
}
check {
dependsOn(jacocoTestCoverageVerification)
dependsOn(jacocoTestReport)
}
}

tasks.withType<JavaCompile>().configureEach {
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "io.sentry")
}
}

buildConfig {
useJavaOutput()
packageName("io.sentry.openfeature")
buildConfigField(
"String",
"SENTRY_OPENFEATURE_SDK_NAME",
"\"${Config.Sentry.SENTRY_OPENFEATURE_SDK_NAME}\"",
)
buildConfigField("String", "VERSION_NAME", "\"${project.version}\"")
}

tasks.jar {
manifest {
attributes(
"Sentry-Version-Name" to project.version,
"Sentry-SDK-Name" to Config.Sentry.SENTRY_OPENFEATURE_SDK_NAME,
"Sentry-SDK-Package-Name" to "maven:io.sentry:sentry-openfeature",
"Implementation-Vendor" to "Sentry",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.sentry.openfeature;

import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion;

import dev.openfeature.sdk.BooleanHook;
import dev.openfeature.sdk.FlagEvaluationDetails;
import dev.openfeature.sdk.FlagValueType;
import dev.openfeature.sdk.HookContext;
import io.sentry.IScopes;
import io.sentry.ScopesAdapter;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryLevel;
import java.util.Map;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

public final class SentryOpenFeatureHook implements BooleanHook {
private final IScopes scopes;

static {
SentryIntegrationPackageStorage.getInstance()
.addPackage("maven:io.sentry:sentry-openfeature", BuildConfig.VERSION_NAME);
}

public SentryOpenFeatureHook() {
this(ScopesAdapter.getInstance());
addPackageAndIntegrationInfo();
}

private void addPackageAndIntegrationInfo() {
addIntegrationToSdkVersion("OpenFeature");
}

@VisibleForTesting
SentryOpenFeatureHook(@NotNull IScopes scopes) {
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
}

@Override
public void after(
final @Nullable HookContext<Boolean> context,
final @Nullable FlagEvaluationDetails<Boolean> details,
final @Nullable Map<String, Object> hints) {
if (context == null || details == null) {
return;
}
try {
final @Nullable String flagKey = details.getFlagKey();
final @Nullable FlagValueType type = context.getType();
final @Nullable Object value = details.getValue();

if (flagKey == null || type == null || value == null) {
return;
}

if (!FlagValueType.BOOLEAN.equals(type)) {
return;
}

if (!(value instanceof Boolean)) {
return;
}
final @NotNull Boolean flagValue = (Boolean) value;

scopes.addFeatureFlag(flagKey, flagValue);
} catch (Exception e) {
scopes
.getOptions()
.getLogger()
.log(SentryLevel.ERROR, "Failed to capture feature flag evaluation", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ dependencies {
implementation(projects.sentryGraphql22)
implementation(projects.sentryQuartz)
implementation(projects.sentryAsyncProfiler)
implementation(projects.sentryOpenfeature)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More samples + e2e tests


// OpenFeature SDK
implementation(libs.openfeature)

// database query tracing
implementation(projects.sentryJdbc)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.sentry.samples.spring.boot.jakarta;

import dev.openfeature.sdk.Client;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.OpenFeatureAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/feature-flag/")
public class FeatureFlagController {
private static final Logger LOGGER = LoggerFactory.getLogger(FeatureFlagController.class);
private final OpenFeatureAPI openFeatureAPI;

public FeatureFlagController(OpenFeatureAPI openFeatureAPI) {
this.openFeatureAPI = openFeatureAPI;
}

@GetMapping("check/{flagKey}")
public FeatureFlagResponse checkFlag(@PathVariable String flagKey) {
Client client = openFeatureAPI.getClient();

// Evaluate boolean feature flag
// This will trigger the SentryOpenFeatureHook which tracks the evaluation
boolean flagValue =
client.getBooleanValue(flagKey, false, new ImmutableContext("example-context-key"));

LOGGER.info("Feature flag '{}' evaluated to: {}", flagKey, flagValue);

return new FeatureFlagResponse(flagKey, flagValue);
}

@GetMapping("error/{flagKey}")
public String errorWithFeatureFlag(@PathVariable String flagKey) {
Client client = openFeatureAPI.getClient();

// Evaluate feature flag before throwing error
// The feature flag will be included in the Sentry event
boolean flagValue =
client.getBooleanValue(flagKey, false, new ImmutableContext("example-context-key"));

LOGGER.info("Feature flag '{}' evaluated to: {} before error", flagKey, flagValue);

throw new RuntimeException("Error occurred with feature flag: " + flagKey + " = " + flagValue);
}

public static class FeatureFlagResponse {
private final String flagKey;
private final boolean value;

public FeatureFlagResponse(String flagKey, boolean value) {
this.flagKey = flagKey;
this.value = value;
}

public String getFlagKey() {
return flagKey;
}

public boolean isValue() {
return value;
}
}
}
Loading
Loading