feat: include LD context keys in metric event attributes#514
Merged
Conversation
Spread _ldContextKeys (set via LDObserve.setLDContextKeyAttributes) into the OTel attribute bag for recordCount/recordGauge/recordHistogram/ recordUpDownCounter and the integration recordMetric tags. Caller attributes still take precedence; session id is always last. Previously context.contextKeys.* attributes only flowed into track/identify/spans, so gauge and histogram queries could not group by team or route.
ntiner1
reviewed
Apr 30, 2026
ntiner1
approved these changes
Apr 30, 2026
Contributor
ntiner1
left a comment
There was a problem hiding this comment.
Approve with cardinality check in mind
Merged
Vadman97
pushed a commit
that referenced
this pull request
May 1, 2026
🤖 I have created a release *beep* *boop* --- <details><summary>observability: 1.1.7</summary> ## [1.1.7](observability-1.1.6...observability-1.1.7) (2026-05-01) ### Dependencies * The following workspace dependencies were updated * dependencies * highlight.run bumped to 10.2.0 </details> <details><summary>session-replay: 1.1.7</summary> ## [1.1.7](session-replay-1.1.6...session-replay-1.1.7) (2026-05-01) ### Dependencies * The following workspace dependencies were updated * dependencies * highlight.run bumped to 10.2.0 </details> <details><summary>highlight.run: 10.2.0</summary> ## [10.2.0](highlight.run-10.1.2...highlight.run-10.2.0) (2026-05-01) ### Features * emit element-selector attribution on web-vitals metrics ([#515](#515)) ([d8288b1](d8288b1)) * include LD context keys in metric event attributes ([#514](#514)) ([edefe2c](edefe2c)) ### Bug Fixes * emit url.query_params as nested otel attributes ([#517](#517)) ([69629e1](69629e1)) </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-only changes: version bumps and changelog updates with no code logic modifications in this PR. Runtime behavior changes come only from the upgraded `highlight.run` dependency. > > **Overview** > Bumps released package versions for `@launchdarkly/observability` and `@launchdarkly/session-replay` to `1.1.7`, and updates the workspace `highlight.run` package to `10.2.0` (with corresponding changelog entries). > > Updates `.release-please-manifest.json` to reflect the new versions and documents `highlight.run` 10.2.0 feature/bugfix notes (web-vitals element selector attribution, additional LD context keys on metric attributes, and nested `url.query_params` OTEL attributes). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit cdd7820. 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 the OTel attribute bag forrecordCount,recordGauge,recordHistogram, andrecordUpDownCounterinObserveSDK. Caller-providedmetric.attributesstill win;highlight.session_idstays last.recordMetrictags inrecordGaugeso gauge data flowing to integrations carries the same dimensions.Why
Previously,
context.contextKeys.*attrs only flowed to track/identify/spans, so gauge and histogram queries (e.g. web-vital LCP/CLS/INP) could notgroupBypathTemplate,owner, oraccountId. Verified thatservice_name=gonfalon-webemits these metrics at high volume butgroupBy context.contextKeys.pathTemplatereturns empty groups today.Test plan
yarn turbo run build --filter highlight.runyarn turbo run lint --filter highlight.runyarn turbo run test --filter highlight.run(added two new unit tests insdk.test.ts; 408 tests pass)yarn enforce-size(166KB / 256KB brotli)yarn format-checkNote
Medium Risk
Changes the attribute payload for all emitted metrics, which can affect metric cardinality/cost and downstream dashboards/integrations; logic is straightforward and covered by unit tests.
Overview
LaunchDarkly context key attributes are now attached to emitted metrics.
ObserveSDKspreads_ldContextKeysinto the OpenTelemetry attribute bag forrecordCount,recordGauge,recordHistogram, andrecordUpDownCounter, while keeping caller-providedmetric.attributesas the override source and preservinghighlight.session_id.For gauges, the same merged attributes are also used when building the integration
recordMetric(category,group, andtags), so integrations receive the same dimensions. Adds unit tests to verify LD context keys are included and that caller attributes win on key collisions.Reviewed by Cursor Bugbot for commit 37a3505. Bugbot is set up for automated code reviews on this repo. Configure here.