-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBaseApplication.kt
More file actions
94 lines (83 loc) · 3.7 KB
/
BaseApplication.kt
File metadata and controls
94 lines (83 loc) · 3.7 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.example.androidobservability
import android.app.Application
import android.widget.ImageView
import com.launchdarkly.observability.api.ObservabilityOptions
import com.launchdarkly.observability.client.TelemetryInspector
import com.launchdarkly.observability.plugin.Observability
import com.launchdarkly.observability.replay.PrivacyProfile
import com.launchdarkly.observability.replay.ReplayOptions
import com.launchdarkly.observability.replay.plugin.SessionReplay
import com.launchdarkly.observability.replay.view
import com.launchdarkly.sdk.ContextKind
import com.launchdarkly.sdk.LDContext
import com.launchdarkly.sdk.android.Components
import com.launchdarkly.sdk.android.LDAndroidLogging
import com.launchdarkly.sdk.android.LDClient
import com.launchdarkly.sdk.android.LDConfig
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.common.Attributes
open class BaseApplication : Application() {
companion object {
// TODO O11Y-376: Update this credential to be driven by env variable or gradle property
// Set LAUNCHDARKLY_MOBILE_KEY to your LaunchDarkly SDK mobile key.
const val LAUNCHDARKLY_MOBILE_KEY = "MOBILE_KEY_GOES_HERE"
}
var observabilityOptions = ObservabilityOptions(
resourceAttributes = Attributes.of(
AttributeKey.stringKey("example"), "value"
),
debug = true,
tracesApi = ObservabilityOptions.TracesApi(includeErrors = false, includeSpans = false),
metricsApi = ObservabilityOptions.MetricsApi.disabled(),
instrumentations = ObservabilityOptions.Instrumentations(
crashReporting = true, launchTime = true, activityLifecycle = false
),
logAdapter = LDAndroidLogging.adapter(),
)
var telemetryInspector: TelemetryInspector? = null
var testUrl: String? = null
open fun realInit() {
val observabilityPlugin = Observability(
application = this@BaseApplication,
mobileKey = LAUNCHDARKLY_MOBILE_KEY,
options = testUrl?.let { observabilityOptions.copy(backendUrl = it, otlpEndpoint = it) } ?: observabilityOptions
)
val sessionReplayPlugin = SessionReplay(
options = ReplayOptions(
privacyProfile = PrivacyProfile(
maskText = false,
maskViews = listOf(
view(ImageView::class.java),
view("android.widget.TextView")
),
maskXMLViewIds = listOf("smoothieTitle"))
)
)
// Set LAUNCHDARKLY_MOBILE_KEY to your LaunchDarkly mobile key found on the LaunchDarkly
// dashboard in the start guide.
// If you want to disable the Auto EnvironmentAttributes functionality.
// Use AutoEnvAttributes.Disabled as the argument to the Builder
val ldConfig = LDConfig.Builder(LDConfig.Builder.AutoEnvAttributes.Enabled)
.mobileKey(LAUNCHDARKLY_MOBILE_KEY)
.plugins(
Components.plugins().setPlugins(
listOf(
observabilityPlugin,
sessionReplayPlugin
)
)
)
.build()
// Set up the context properties. This context should appear on your LaunchDarkly context
// dashboard soon after you run the demo.
val context = LDContext.builder(ContextKind.DEFAULT, "example-user-key")
.anonymous(true)
.build()
LDClient.init(this@BaseApplication, ldConfig, context)
telemetryInspector = observabilityPlugin.getTelemetryInspector()
}
override fun onCreate() {
super.onCreate()
realInit()
}
}