feat: allow attach span context to logs#460
Merged
abelonogov-ld merged 5 commits intomainfrom Apr 8, 2026
Merged
Conversation
- Introduced `triggerLogWithContext` method in ViewModel to log messages with OpenTelemetry span context. - Added a button in MainActivity to trigger the new logging functionality, enhancing observability in detached threads.
Vadman97
approved these changes
Apr 7, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f55dec8. Configure here.
...servability-android/lib/src/main/kotlin/com/launchdarkly/observability/interfaces/Observe.kt
Show resolved
Hide resolved
- Cleaned up imports in `LDObserve.kt`, `ObservabilityHookExporter.kt`, `ViewModel.kt`, `ObservabilityServiceTasks.kt`, `SamplingE2ETest.kt`, and `DisablingConfigOptionsE2ETest.kt` by removing the unused `recordLog` import. - Updated `recordLog` method signature in `Observe.kt` to provide default values for attributes and spanContext, simplifying its usage.
Merged
abelonogov-ld
added a commit
that referenced
this pull request
Apr 8, 2026
* main: feat: allow attach span context to logs (#460)
abelonogov-ld
pushed a commit
that referenced
this pull request
Apr 8, 2026
🤖 I have created a release *beep* *boop* --- <details><summary>launchdarkly-observability-android: 0.36.0</summary> ## [0.36.0](launchdarkly-observability-android-0.35.0...launchdarkly-observability-android-0.36.0) (2026-04-08) ### Features * allow attach span context to logs ([#460](#460)) ([19ae071](19ae071)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk release bookkeeping only: version bumps and changelog updates with no functional code changes in this diff. > > **Overview** > Bumps `sdk/@launchdarkly/observability-android` from `0.35.0` to `0.36.0` in `.release-please-manifest.json` and the Android `gradle.properties`. > > Updates `CHANGELOG.md` with the `0.36.0` release entry (noting the new feature to attach span context to logs). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 410758e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds optional
SpanContextparameter torecordLogso log records can be correlated with traces even when OTel context propagation is lost (e.g. detached threads, cross-process boundaries, .NET MAUI bridge).Changes
SDK (
observability-android)ObserveintoMetricsApi,LogsApi,TracesApi—Observenow composes all three via interface inheritance. This enables bridge layers to depend on narrower contracts.LogsApi.recordLoggainsspanContext: SpanContext?— the old 3-arg signature is preserved as an extension function for backward compatibility.LogRecordEmitter— new shared extensionLogger.emitLog(...)that attachesSpanContextto OTel log records viaContext.root().with(Span.wrap(...)). Used by bothObservabilityServiceandKotlinLogger.KotlinLogger— new bridge-layer wrapper that accepts rawtraceId/spanIdstrings (for .NET MAUI interop), reconstructsSpanContext, and routes through either the internal OTel logger or the level-gatedLogsApi.LDObserveBridge.getKotlinLogger()— exposesKotlinLoggerto bridge consumers.ObservabilityService.getLogger()— exposes the raw OTelLoggerinstance.E2E app
ViewModel.triggerLogWithContext()— demonstrates capturingSpanContexton the originating thread, then emitting a log from a detachedThreadwhere automatic context propagation is lost.MainActivity— adds "Log with Context" button next to "Trigger Log".Note
Medium Risk
Changes the
recordLogAPI surface to accept an optionalSpanContext, which can impact downstream implementers/callers and affects trace-log correlation behavior. New bridge logger paths and context-setting logic could introduce subtle correlation or gating regressions if misused.Overview
Adds optional trace correlation to logs by extending
recordLogto accept aSpanContext?and updatingLDObserve/ObservabilityServiceto propagate it.Introduces shared OTel log emission helper (
emitLog) plus a new bridge-facingKotlinLoggerexposed viaLDObserveBridge.getKotlinLogger()to allow non-Kotlin layers to record logs with explicit trace/span IDs. The e2e app UI andViewModeladd a demo action that records a log from a detached thread using a captured span context.Reviewed by Cursor Bugbot for commit 784b97b. Bugbot is set up for automated code reviews on this repo. Configure here.