Skip to content

feat: include LD context keys in metric event attributes#514

Merged
Vadman97 merged 2 commits intomainfrom
vkorolik/ld-context-metric-attrs
May 1, 2026
Merged

feat: include LD context keys in metric event attributes#514
Vadman97 merged 2 commits intomainfrom
vkorolik/ld-context-metric-attrs

Conversation

@Vadman97
Copy link
Copy Markdown
Contributor

@Vadman97 Vadman97 commented Apr 30, 2026

Summary

  • Spread _ldContextKeys (set via LDObserve.setLDContextKeyAttributes(...)) into the OTel attribute bag for recordCount, recordGauge, recordHistogram, and recordUpDownCounter in ObserveSDK. Caller-provided metric.attributes still win; highlight.session_id stays last.
  • Same change applied to the integration recordMetric tags in recordGauge so 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 not groupBy pathTemplate, owner, or accountId. Verified that service_name=gonfalon-web emits these metrics at high volume but groupBy context.contextKeys.pathTemplate returns empty groups today.

Test plan

  • yarn turbo run build --filter highlight.run
  • yarn turbo run lint --filter highlight.run
  • yarn turbo run test --filter highlight.run (added two new unit tests in sdk.test.ts; 408 tests pass)
  • yarn enforce-size (166KB / 256KB brotli)
  • yarn format-check

Note

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. ObserveSDK spreads _ldContextKeys into the OpenTelemetry attribute bag for recordCount, recordGauge, recordHistogram, and recordUpDownCounter, while keeping caller-provided metric.attributes as the override source and preserving highlight.session_id.

For gauges, the same merged attributes are also used when building the integration recordMetric (category, group, and tags), 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.

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.
@Vadman97 Vadman97 requested a review from a team as a code owner April 30, 2026 19:31
Comment thread sdk/highlight-run/src/sdk/observe.ts
Copy link
Copy Markdown
Contributor

@ntiner1 ntiner1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with cardinality check in mind

@Vadman97 Vadman97 merged commit edefe2c into main May 1, 2026
22 checks passed
@Vadman97 Vadman97 deleted the vkorolik/ld-context-metric-attrs branch May 1, 2026 15:14
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants