Skip to content

Commit 78ee2ec

Browse files
authored
fix: O11Y-725 - Return no-op span when not initialized (#283)
## Summary Instead of throwing an `IllegalStateException` when the observability plugin is not initialized, `startSpan` now returns an invalid span. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Return an invalid no-op span from `startSpan` when not initialized, plus minor KDoc and formatting updates. > > - **Core behavior**: > - `companion object` no-op `startSpan` now returns `Span.getInvalid()` when Observability isn’t initialized. > - **Docs**: > - KDoc updated to reference `com.launchdarkly.observability.plugin.Observability` and streamlined wording. > - **Cleanup**: > - Minor formatting/style adjustments in `LDObserve.kt`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 9548adf. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 03f01ed commit 78ee2ec

File tree

1 file changed

+6
-7
lines changed
  • sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/sdk

1 file changed

+6
-7
lines changed

sdk/@launchdarkly/observability-android/lib/src/main/kotlin/com/launchdarkly/observability/sdk/LDObserve.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import io.opentelemetry.api.logs.Severity
88
import io.opentelemetry.api.trace.Span
99

1010
/**
11-
* LDObserve is the singleton entry point for recording observability data such as
12-
* metrics, logs, errors, and traces. It is recommended to use the [Observability] plugin
13-
* with the LaunchDarkly Android Client SDK, as that will automatically initialize the
14-
* [LDObserve] singleton instance.
11+
* LDObserve is the singleton entry point for recording observability data such as
12+
* metrics, logs, errors, and traces. It is recommended to use the [com.launchdarkly.observability.plugin.Observability] plugin
13+
* with the LaunchDarkly Android Client SDK, as that will automatically initialize the [LDObserve] singleton instance.
1514
*
1615
* @constructor Creates an LDObserve instance with the provided [Observe].
1716
* @param client The [Observe] to which observability data will be forwarded.
1817
*/
1918
class LDObserve(private val client: Observe) : Observe {
19+
2020
override fun recordMetric(metric: Metric) {
2121
client.recordMetric(metric)
2222
}
@@ -53,7 +53,7 @@ class LDObserve(private val client: Observe) : Observe {
5353
return client.flush()
5454
}
5555

56-
companion object : Observe{
56+
companion object : Observe {
5757
// initially a no-op delegate
5858
// volatile annotation guarantees multiple threads see the same value after init and none continue using the no-op implementation
5959
@Volatile
@@ -66,8 +66,7 @@ class LDObserve(private val client: Observe) : Observe {
6666
override fun recordError(error: Error, attributes: Attributes) {}
6767
override fun recordLog(message: String, severity: Severity, attributes: Attributes) {}
6868
override fun startSpan(name: String, attributes: Attributes): Span {
69-
// TODO: figure out if a no-op span implementation exists in the otel library
70-
throw IllegalStateException("Observability plugin was not initialized before being used.")
69+
return Span.getInvalid() // Observability plugin was not initialized before being used.
7170
}
7271
override fun flush(): Boolean {
7372
return false // No-op, return false to indicate flush was not successful

0 commit comments

Comments
 (0)