-
-
Notifications
You must be signed in to change notification settings - Fork 463
feat(flags): Implement LaunchDarkly Integrations #4917
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
134996c
Implement OpenFeature Integration
adinauer 92753c7
use evaluation context
adinauer 1efe8bd
Format code
getsentry-bot 9b9b025
add missing mentions
adinauer 58f4219
api; register as integration and package
adinauer 509c675
changelog
adinauer 33023d2
Merge branch 'main' into feat/openfeature-integration
adinauer 1d8442a
replace hard coded dependency
adinauer c6720ef
Add launchdarkly integrations
adinauer fbc578c
Merge branch 'main' into feat/launchdarkly
adinauer da4f526
changelog
adinauer 6189f26
issue templates and readme
adinauer 290a79d
remove comments from build gradle files
adinauer 7c626d7
convert to java
adinauer 43721c2
Merge branch 'main' into feat/launchdarkly
adinauer 6f4d088
remove kotlin from build.gradle
adinauer 6f2d7b0
add tests
adinauer bb5a023
Format code
getsentry-bot 0874d7a
Merge branch 'main' into feat/launchdarkly
adinauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
sentry-launchdarkly-android/api/sentry-launchdarkly-android.api
This file contains hidden or 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,15 @@ | ||
| public final class io/sentry/launchdarkly/android/BuildConfig { | ||
| public static final field BUILD_TYPE Ljava/lang/String; | ||
| public static final field DEBUG Z | ||
| public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String; | ||
| public static final field SENTRY_LAUNCHDARKLY_ANDROID_SDK_NAME Ljava/lang/String; | ||
| public static final field VERSION_NAME Ljava/lang/String; | ||
| public fun <init> ()V | ||
| } | ||
|
|
||
| public final class io/sentry/launchdarkly/android/SentryLaunchDarklyAndroidHook : com/launchdarkly/sdk/android/integrations/Hook { | ||
| public fun <init> ()V | ||
| public fun <init> (Lio/sentry/IScopes;)V | ||
| public fun afterEvaluation (Lcom/launchdarkly/sdk/android/integrations/EvaluationSeriesContext;Ljava/util/Map;Lcom/launchdarkly/sdk/EvaluationDetail;)Ljava/util/Map; | ||
| } | ||
|
|
This file contains hidden or 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,90 @@ | ||
| import io.gitlab.arturbosch.detekt.Detekt | ||
|
|
||
| plugins { | ||
| id("com.android.library") | ||
| alias(libs.plugins.kotlin.android) | ||
| jacoco | ||
| alias(libs.plugins.jacoco.android) | ||
| alias(libs.plugins.gradle.versions) | ||
| alias(libs.plugins.detekt) | ||
| } | ||
|
|
||
| android { | ||
| compileSdk = libs.versions.compileSdk.get().toInt() | ||
| namespace = "io.sentry.launchdarkly.android" | ||
|
|
||
| defaultConfig { | ||
| minSdk = libs.versions.minSdk.get().toInt() | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
|
|
||
| // for AGP 4.1 | ||
| buildConfigField("String", "VERSION_NAME", "\"${project.version}\"") | ||
| buildConfigField( | ||
| "String", | ||
| "SENTRY_LAUNCHDARKLY_ANDROID_SDK_NAME", | ||
| "\"${Config.Sentry.SENTRY_LAUNCHDARKLY_ANDROID_SDK_NAME}\"", | ||
| ) | ||
| } | ||
|
|
||
| buildTypes { | ||
| getByName("debug") { consumerProguardFiles("proguard-rules.pro") } | ||
| getByName("release") { consumerProguardFiles("proguard-rules.pro") } | ||
| } | ||
|
|
||
| kotlin { | ||
| 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 | ||
| } | ||
|
|
||
| testOptions { | ||
| animationsDisabled = true | ||
| unitTests.apply { | ||
| isReturnDefaultValues = true | ||
| isIncludeAndroidResources = true | ||
| } | ||
| } | ||
|
|
||
| lint { | ||
| warningsAsErrors = true | ||
| checkDependencies = true | ||
|
|
||
| // We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks. | ||
| checkReleaseBuilds = false | ||
| } | ||
|
|
||
| buildFeatures { buildConfig = true } | ||
|
|
||
| androidComponents.beforeVariants { | ||
| it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType) | ||
| } | ||
| } | ||
|
|
||
| kotlin { explicitApi() } | ||
|
|
||
| dependencies { | ||
| api(projects.sentry) | ||
|
|
||
| // LaunchDarkly Android Client SDK | ||
| // Note: This is for Android client-side applications | ||
| compileOnly(libs.launchdarkly.android) | ||
|
|
||
| implementation(kotlin(Config.kotlinStdLib, Config.kotlinStdLibVersionAndroid)) | ||
|
|
||
| // tests | ||
| testImplementation(projects.sentry) | ||
| testImplementation(projects.sentryTestSupport) | ||
| testImplementation(kotlin(Config.kotlinStdLib)) | ||
| testImplementation(libs.kotlin.test.junit) | ||
| testImplementation(libs.androidx.test.ext.junit) | ||
| testImplementation(libs.mockito.kotlin) | ||
| testImplementation(libs.mockito.inline) | ||
| // LaunchDarkly Android Client SDK for tests | ||
| testImplementation(libs.launchdarkly.android) | ||
| } | ||
|
|
||
| tasks.withType<Detekt>().configureEach { | ||
| // Target version of the generated JVM bytecode. It is used for type resolution. | ||
| jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
| } |
This file contains hidden or 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,8 @@ | ||
| ##---------------Begin: proguard configuration for LaunchDarkly Android ---------- | ||
|
|
||
| # To ensure that stack traces is unambiguous | ||
| # https://developer.android.com/studio/build/shrink-code#decode-stack-trace | ||
| -keepattributes LineNumberTable,SourceFile | ||
|
|
||
| ##---------------End: proguard configuration for LaunchDarkly Android ---------- | ||
|
|
55 changes: 55 additions & 0 deletions
55
...kly-android/src/main/java/io/sentry/launchdarkly/android/SentryLaunchDarklyAndroidHook.kt
This file contains hidden or 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,55 @@ | ||
| package io.sentry.launchdarkly.android | ||
|
|
||
| import com.launchdarkly.sdk.EvaluationDetail | ||
| import com.launchdarkly.sdk.LDValue | ||
| import com.launchdarkly.sdk.LDValueType | ||
| import com.launchdarkly.sdk.android.integrations.EvaluationSeriesContext | ||
| import com.launchdarkly.sdk.android.integrations.Hook | ||
| import io.sentry.IScopes | ||
| import io.sentry.ScopesAdapter | ||
| import io.sentry.SentryIntegrationPackageStorage | ||
| import io.sentry.SentryLevel | ||
| import io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion | ||
|
|
||
| public class SentryLaunchDarklyAndroidHook : Hook { | ||
| private val scopes: IScopes | ||
|
|
||
| private companion object { | ||
| init { | ||
| SentryIntegrationPackageStorage.getInstance() | ||
| .addPackage("maven:io.sentry:sentry-launchdarkly-android", BuildConfig.VERSION_NAME) | ||
| } | ||
| } | ||
|
|
||
| public constructor() : this(ScopesAdapter.getInstance()) | ||
|
|
||
| public constructor(scopes: IScopes) : super("SentryLaunchDarklyAndroidHook") { | ||
| this.scopes = scopes | ||
| addPackageAndIntegrationInfo() | ||
| } | ||
|
|
||
| private fun addPackageAndIntegrationInfo() { | ||
| addIntegrationToSdkVersion("LaunchDarkly-Android") | ||
| } | ||
|
|
||
| @Suppress("TooGenericExceptionCaught") | ||
| override fun afterEvaluation( | ||
| seriesContext: EvaluationSeriesContext?, | ||
| seriesData: Map<String, Any>?, | ||
| evaluationDetail: EvaluationDetail<LDValue>?, | ||
| ): Map<String, Any>? { | ||
| try { | ||
| val flagKey: String? = seriesContext?.flagKey | ||
| val value: LDValue? = evaluationDetail?.value | ||
|
|
||
| if (flagKey != null && value != null && LDValueType.BOOLEAN == value.type) { | ||
| val flagValue: Boolean = value.booleanValue() | ||
| scopes.addFeatureFlag(flagKey, flagValue) | ||
| } | ||
| } catch (e: Throwable) { | ||
| scopes.options.logger.log(SentryLevel.ERROR, "Failed to capture feature flag evaluation", e) | ||
| } | ||
|
|
||
| return seriesData | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
sentry-launchdarkly-server/api/sentry-launchdarkly-server.api
This file contains hidden or 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,10 @@ | ||
| public final class io/sentry/launchdarkly/server/BuildConfig { | ||
| public static final field SENTRY_LAUNCHDARKLY_SERVER_SDK_NAME Ljava/lang/String; | ||
| public static final field VERSION_NAME Ljava/lang/String; | ||
| } | ||
|
|
||
| public final class io/sentry/launchdarkly/server/SentryLaunchDarklyServerHook : com/launchdarkly/sdk/server/integrations/Hook { | ||
| public fun <init> ()V | ||
| public fun afterEvaluation (Lcom/launchdarkly/sdk/server/integrations/EvaluationSeriesContext;Ljava/util/Map;Lcom/launchdarkly/sdk/EvaluationDetail;)Ljava/util/Map; | ||
| } | ||
|
|
This file contains hidden or 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,95 @@ | ||
| 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) | ||
|
|
||
| // LaunchDarkly Java Server SDK (for JVM/server-side applications) | ||
| // Note: For Android applications, use sentry-launchdarkly-android module with | ||
| // com.launchdarkly:launchdarkly-android-client-sdk instead | ||
| compileOnly(libs.launchdarkly.server) | ||
|
|
||
| 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) | ||
| // LaunchDarkly Java Server SDK for tests | ||
| testImplementation(libs.launchdarkly.server) | ||
| } | ||
|
|
||
| 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.launchdarkly.server") | ||
| buildConfigField( | ||
| "String", | ||
| "SENTRY_LAUNCHDARKLY_SERVER_SDK_NAME", | ||
| "\"${Config.Sentry.SENTRY_LAUNCHDARKLY_SERVER_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_LAUNCHDARKLY_SERVER_SDK_NAME, | ||
| "Sentry-SDK-Package-Name" to "maven:io.sentry:sentry-launchdarkly-server", | ||
| "Implementation-Vendor" to "Sentry", | ||
| "Implementation-Title" to project.name, | ||
| "Implementation-Version" to project.version, | ||
| ) | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
...rkly-server/src/main/java/io/sentry/launchdarkly/server/SentryLaunchDarklyServerHook.java
This file contains hidden or 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,73 @@ | ||
| package io.sentry.launchdarkly.server; | ||
|
|
||
| import static io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion; | ||
|
|
||
| import com.launchdarkly.sdk.EvaluationDetail; | ||
| import com.launchdarkly.sdk.LDValue; | ||
| import com.launchdarkly.sdk.LDValueType; | ||
| import com.launchdarkly.sdk.server.integrations.EvaluationSeriesContext; | ||
| import com.launchdarkly.sdk.server.integrations.Hook; | ||
| 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 SentryLaunchDarklyServerHook extends Hook { | ||
| private final IScopes scopes; | ||
|
|
||
| static { | ||
| SentryIntegrationPackageStorage.getInstance() | ||
| .addPackage("maven:io.sentry:sentry-launchdarkly-server", BuildConfig.VERSION_NAME); | ||
| } | ||
|
|
||
| public SentryLaunchDarklyServerHook() { | ||
| this(ScopesAdapter.getInstance()); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| SentryLaunchDarklyServerHook(@NotNull IScopes scopes) { | ||
| super("SentryLaunchDarklyServerHook"); | ||
| this.scopes = Objects.requireNonNull(scopes, "Scopes are required"); | ||
| addPackageAndIntegrationInfo(); | ||
| } | ||
|
|
||
| private void addPackageAndIntegrationInfo() { | ||
| addIntegrationToSdkVersion("LaunchDarkly-Server"); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, Object> afterEvaluation( | ||
| EvaluationSeriesContext seriesContext, | ||
| Map<String, Object> seriesData, | ||
| EvaluationDetail<LDValue> evaluationDetail) { | ||
| if (evaluationDetail == null || seriesContext == null) { | ||
| return seriesData; | ||
| } | ||
|
|
||
| try { | ||
| final @Nullable String flagKey = seriesContext.flagKey; | ||
| final @Nullable LDValue value = evaluationDetail.getValue(); | ||
|
|
||
| if (flagKey == null || value == null) { | ||
| return seriesData; | ||
| } | ||
|
|
||
| if (LDValueType.BOOLEAN.equals(value.getType())) { | ||
| final boolean flagValue = value.booleanValue(); | ||
| scopes.addFeatureFlag(flagKey, flagValue); | ||
| } | ||
| } catch (Exception e) { | ||
| scopes | ||
| .getOptions() | ||
| .getLogger() | ||
| .log(SentryLevel.ERROR, "Failed to capture feature flag evaluation", e); | ||
| } | ||
|
|
||
| return seriesData; | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.