Skip to content

Commit 7c626d7

Browse files
committed
convert to java
1 parent 290a79d commit 7c626d7

File tree

4 files changed

+72
-57
lines changed

4 files changed

+72
-57
lines changed

sentry-launchdarkly-android/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ dependencies {
6767
api(projects.sentry)
6868

6969
compileOnly(libs.launchdarkly.android)
70-
71-
implementation(kotlin(Config.kotlinStdLib, Config.kotlinStdLibVersionAndroid))
70+
compileOnly(libs.jetbrains.annotations)
7271

7372
// tests
7473
testImplementation(projects.sentry)

sentry-launchdarkly-android/proguard-rules.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66

77
##---------------End: proguard configuration for LaunchDarkly Android ----------
88

9+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package io.sentry.launchdarkly.android;
2+
3+
import com.launchdarkly.sdk.EvaluationDetail;
4+
import com.launchdarkly.sdk.LDValue;
5+
import com.launchdarkly.sdk.LDValueType;
6+
import com.launchdarkly.sdk.android.integrations.EvaluationSeriesContext;
7+
import com.launchdarkly.sdk.android.integrations.Hook;
8+
import io.sentry.IScopes;
9+
import io.sentry.ScopesAdapter;
10+
import io.sentry.SentryIntegrationPackageStorage;
11+
import io.sentry.SentryLevel;
12+
import io.sentry.util.IntegrationUtils;
13+
import java.util.Map;
14+
import java.util.Objects;
15+
import org.jetbrains.annotations.NotNull;
16+
import org.jetbrains.annotations.Nullable;
17+
18+
public final class SentryLaunchDarklyAndroidHook extends Hook {
19+
private final IScopes scopes;
20+
21+
static {
22+
SentryIntegrationPackageStorage.getInstance()
23+
.addPackage("maven:io.sentry:sentry-launchdarkly-android", BuildConfig.VERSION_NAME);
24+
}
25+
26+
public SentryLaunchDarklyAndroidHook() {
27+
this(ScopesAdapter.getInstance());
28+
}
29+
30+
public SentryLaunchDarklyAndroidHook(final @NotNull IScopes scopes) {
31+
super("SentryLaunchDarklyAndroidHook");
32+
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
33+
addPackageAndIntegrationInfo();
34+
}
35+
36+
private void addPackageAndIntegrationInfo() {
37+
IntegrationUtils.addIntegrationToSdkVersion("LaunchDarkly-Android");
38+
}
39+
40+
@Override
41+
public Map<String, Object> afterEvaluation(
42+
final EvaluationSeriesContext seriesContext,
43+
final Map<String, Object> seriesData,
44+
final EvaluationDetail<LDValue> evaluationDetail) {
45+
if (evaluationDetail == null || seriesContext == null) {
46+
return seriesData;
47+
}
48+
49+
try {
50+
final @Nullable String flagKey = seriesContext.flagKey;
51+
final @Nullable LDValue value = evaluationDetail.getValue();
52+
53+
if (flagKey == null || value == null) {
54+
return seriesData;
55+
}
56+
57+
if (LDValueType.BOOLEAN.equals(value.getType())) {
58+
final boolean flagValue = value.booleanValue();
59+
scopes.addFeatureFlag(flagKey, flagValue);
60+
}
61+
} catch (final Exception e) {
62+
scopes
63+
.getOptions()
64+
.getLogger()
65+
.log(SentryLevel.ERROR, "Failed to capture feature flag evaluation", e);
66+
}
67+
68+
return seriesData;
69+
}
70+
}

sentry-launchdarkly-android/src/main/java/io/sentry/launchdarkly/android/SentryLaunchDarklyAndroidHook.kt

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)