feat: forward LD context keys to errors, logs, and custom spans#530
Merged
Merged
Conversation
Spread the _ldContextKeys bag (set via LDObserve.setLDContextKeyAttributes)
into all OTel data types where it makes semantic sense, not just metrics:
- startSpan wrapper now applies contextKeys to every span before invoking
the caller, so user-created custom spans inherit pathTemplate / owner /
account / route attributes automatically. Caller setAttributes calls win
on key collisions because OTel merges with last-write-wins semantics.
- _recordLog spreads contextKeys into the addEvent('log', ...) payload so
log events carry the same dimensions as their containing span.
- _recordErrorMessage no longer needs an explicit spread because the
startSpan wrapper handles it; comment added at the call site.
Previously contextKeys only flowed onto recordCount / recordGauge /
recordHistogram / recordUpDownCounter, so error / log / span queries
could not group by team or route. Closes the remaining gap relative to
Datadog RUM dashboards.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mayberryzane
approved these changes
May 6, 2026
Merged
Vadman97
pushed a commit
that referenced
this pull request
May 6, 2026
🤖 I have created a release *beep* *boop* --- <details><summary>observability: 1.1.8</summary> ## [1.1.8](observability-1.1.7...observability-1.1.8) (2026-05-06) ### Dependencies * The following workspace dependencies were updated * dependencies * highlight.run bumped to 10.3.0 </details> <details><summary>session-replay: 1.1.8</summary> ## [1.1.8](session-replay-1.1.7...session-replay-1.1.8) (2026-05-06) ### Dependencies * The following workspace dependencies were updated * dependencies * highlight.run bumped to 10.3.0 </details> <details><summary>highlight.run: 10.3.0</summary> ## [10.3.0](highlight.run-10.2.0...highlight.run-10.3.0) (2026-05-06) ### Features * forward LD context keys to errors, logs, and custom spans ([#530](#530)) ([5a6d164](5a6d164)) </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** > Automated version/changelog updates and a dependency bump; low risk beyond any behavioral changes introduced by `highlight.run@10.3.0` in downstream consumers. > > **Overview** > This release PR bumps `@launchdarkly/observability` and `@launchdarkly/session-replay` from `1.1.7` to `1.1.8`, and updates the workspace manifest accordingly. > > It also releases `highlight.run` `10.3.0` (from `10.2.0`) and records the change in changelogs; the notable behavior change called out is forwarding LD context keys to errors, logs, and custom spans. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 29d2ca0. 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
_ldContextKeys(set viaLDObserve.setLDContextKeyAttributes) into all OTel data types where it makes semantic sense, not just metrics.startSpanwrapper now applies contextKeys to every span before invoking the caller, so user-created custom spans inheritpathTemplate/owner/account/ route attributes automatically. CallersetAttributescalls win on key collisions (OTel merges with last-write-wins)._recordLogspreads contextKeys into theaddEvent('log', …)payload so log events carry the same dimensions as their containing span._recordErrorMessageno longer needs an explicit spread because thestartSpanwrapper handles it; comment added at the call site.Why
Previously
_ldContextKeysonly flowed intorecordCount/recordGauge/recordHistogram/recordUpDownCounter(#510 / commite49d4812f), so error, log, and custom-span queries could not group by team or route. This meant LD Observability dashboards couldn't replicate Datadog RUM's per-team and per-route error and log breakdowns. After this change, queries likeerrors group_by context.contextKeys.pathTemplateandlogs group_by context.contextKeys.ownerproduce real values, closing the last big gap relative to the Datadog frontend-errors dashboard.Coverage matrix
recordError/_recordErrorMessage)startSpanwrapper)_recordLogaddEvent)startSpanTest plan
yarn vitest run src/__tests__/sdk.test.ts— 14/14 passing locallyyarn turbo run build --filter '@launchdarkly/observability'— clean buildyarn format-check— passeserrors/logsgrouped bycontext.contextKeys.pathTemplate/owner/accountIdpopulate after a gonfalon SDK bump🤖 Generated with Claude Code
Note
Medium Risk
Touches core tracing/logging/error instrumentation by injecting
_ldContextKeysintostartSpanand log events, which could change span attributes and override behavior across all spans.Overview
LD context keys set via
setLDContextKeyAttributesare now forwarded beyond metrics:startSpaninjects them onto every created span (including user custom spans), and_recordLogincludes them inaddEvent('log', ...)attributes.Error recording relies on the
startSpanwrapper for context key attachment (instead of explicitly spreading them in_recordErrorMessage), and new Vitest coverage asserts propagation plus last-write-wins override semantics and the no-context-keys no-op case.Reviewed by Cursor Bugbot for commit 642f16d. Bugbot is set up for automated code reviews on this repo. Configure here.