-
-
Notifications
You must be signed in to change notification settings - Fork 464
feat(flags): Implement OpenFeature Integration #4910
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
Changes from all commits
134996c
92753c7
1efe8bd
9b9b025
58f4219
509c675
33023d2
1d8442a
e260f55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: OpenFeature module commented out in release registryThe |
||
| maven:io.sentry:sentry-opentelemetry-agent: | ||
| maven:io.sentry:sentry-opentelemetry-agentcustomization: | ||
| maven:io.sentry:sentry-opentelemetry-agentless: | ||
|
|
||
Large diffs are not rendered by default.
| 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 | ||
| } | ||
|
|
| 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); | ||
adinauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } 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 |
|---|---|---|
|
|
@@ -53,6 +53,10 @@ dependencies { | |
| implementation(projects.sentryGraphql22) | ||
| implementation(projects.sentryQuartz) | ||
| implementation(projects.sentryAsyncProfiler) | ||
| implementation(projects.sentryOpenfeature) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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-openfeatureentry 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.