-
-
Notifications
You must be signed in to change notification settings - Fork 469
Expand file tree
/
Copy pathSentryLaunchDarklyAndroidHook.java
More file actions
70 lines (59 loc) · 2.17 KB
/
SentryLaunchDarklyAndroidHook.java
File metadata and controls
70 lines (59 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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;
import java.util.Map;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class SentryLaunchDarklyAndroidHook extends Hook {
private final IScopes scopes;
static {
SentryIntegrationPackageStorage.getInstance()
.addPackage("maven:io.sentry:sentry-launchdarkly-android", BuildConfig.VERSION_NAME);
}
public SentryLaunchDarklyAndroidHook() {
this(ScopesAdapter.getInstance());
}
public SentryLaunchDarklyAndroidHook(final @NotNull IScopes scopes) {
super("SentryLaunchDarklyAndroidHook");
this.scopes = Objects.requireNonNull(scopes, "Scopes are required");
addPackageAndIntegrationInfo();
}
private void addPackageAndIntegrationInfo() {
IntegrationUtils.addIntegrationToSdkVersion("LaunchDarkly-Android");
}
@Override
public Map<String, Object> afterEvaluation(
final EvaluationSeriesContext seriesContext,
final Map<String, Object> seriesData,
final 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 (final Exception e) {
scopes
.getOptions()
.getLogger()
.log(SentryLevel.ERROR, "Failed to capture feature flag evaluation", e);
}
return seriesData;
}
}