-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathViewModel.kt
More file actions
45 lines (37 loc) · 1.25 KB
/
ViewModel.kt
File metadata and controls
45 lines (37 loc) · 1.25 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
package com.example.androidobservability
import androidx.lifecycle.ViewModel
import com.launchdarkly.observability.interfaces.Metric
import com.launchdarkly.observability.sdk.LDObserve
import com.launchdarkly.sdk.android.LDClient
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.trace.Span
class ViewModel : ViewModel() {
private var lastSpan: Span? = null
fun triggerMetric() {
LDObserve.recordMetric(Metric("test", 50.0))
}
fun triggerError() {
LDObserve.recordError(
Error("Manual error womp womp", Error("The error that caused the other error.")),
Attributes.of(AttributeKey.stringKey("FakeAttribute"), "FakeVal")
)
}
fun triggerLog() {
LDObserve.recordLog(
"Test Log",
"debug",
Attributes.of(AttributeKey.stringKey("FakeAttribute"), "FakeVal")
)
}
fun triggerStartSpan() {
val newSpan = LDObserve.startSpan("FakeSpan", Attributes.empty())
newSpan.makeCurrent()
lastSpan = newSpan
LDClient.get().boolVariation("my-boolean-flag", false)
}
fun triggerStopSpan() {
lastSpan?.end()
lastSpan = null
}
}