Skip to content

feat(otel): centralize legacy OTEL key aliases and reader helpers - #2021

Open
ocupe wants to merge 6 commits into
mainfrom
js/ocd-3830-centralize-legacy-otel-key-aliases-3a6a
Open

ocupe wants to merge 6 commits into
mainfrom
js/ocd-3830-centralize-legacy-otel-key-aliases-3a6a

Conversation

@ocupe

@ocupe ocupe commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Establishes a single, centralized way in livekit/protocol/otel (Weaver) to represent and resolve legacy telemetry key aliases, with matching reader helpers in Go and TypeScript. Readers migrating to canonical lk.* keys (cloud-observability, cloud-api-server, livekit/web) now share one source of truth instead of reinventing ad-hoc fallback lists during dual-emit.

Resolves OCD-3830.

What changed

Registry schema (otel/model/shared/registry.yaml)

  • Extended the renamed_from annotation on the shared keys with a sibling aliases list for the legacy spellings beyond the single OTLP dotted rename — the pre-#7973 Agents span names (lk.room_sid, lk.track_sid, …) and the Go logger / collector spellings (roomID, room_id, participantID, participantIdentity, …).
  • renamed_from.key stays the OTLP dotted rename that live-check reads, so live-check remains OTLP-only (it never flags camelCase Go-logger spellings). Legacy spellings are never registered keys; they live only in the generated alias maps.
  • lk.job_id is intentionally left a binding-only key (job_id), per the existing README stance that job renaming is out of scope. Keys with no canonical lk.* key yet (e.g. nodeID) are deferred to their owning surface, as agreed.

Policy (otel/policies/resolved.rego, otel/tests/negatives/)

  • livekit_shared_rename now forbids defining the dotted rename or any alias as a key.
  • New livekit_alias_collision hard-fails a legacy spelling that maps to more than one canonical key, so the helpers stay unambiguous.
  • Both run in default and --v2 modes, with new negative fixtures alias-defined.yaml and alias-collision.yaml; findings table updated in the README.

Codegen

  • Go (otel/gen/go/semconv.go): RenamedKeys now covers every alias; new KeyAliases (canonical → legacy spellings); new helpers NormalizeKey, NormalizeValue, AliasesFor — pure, zero external deps.
  • TypeScript (otel/gen/ts/semconv.ts, exported from @livekit/protocol/semconv): matching RENAMED_KEYS, RENAMED_VALUES, KEY_ALIASES, normalizeKey, normalizeValue, aliasesFor — no @bufbuild/protobuf dependency.
  • Markdown "Old spellings" table lists the aliases; README documents the dual-emit → ingest-normalize / query-expand → retire lifecycle.

Tests

  • otel/gotest/semconv_test.go: relaxed the hard-coded 8-entry RenamedKeys check to a subset + structural invariants, and added TestKeyAliases, TestNormalizeKey, TestAliasesFor, TestNormalizeValue.

Follow-ups folded in from the #2019 review (incl. pblazej's threads)

  • Pre-#7973 Agents keys (lk.room_sid, room_id, lk.track_sid, …) are now in RenamedKeys / renamed_from.aliases, so the collector map actually normalizes older captures.
  • Pre-existing YAML bug: quoted the checkpoint brief in otel/model/agents/signals.yaml whose unquoted comma truncated it (events cannot be referenced → full sentence). Fuller brief now flows into the generated Rust/Python/Markdown.
  • mage otel snapshots otel/gen and restores it if generation, the Go build or gotest fails, so the Generate workflow never commits a broken partial result.
  • tests/codegen.sh now round-trips the escape value through the Go toolchain alongside rustc, tsc and python3.
  • Unitless metric doc comments in semconv.go.j2 no longer render an empty Unit: clause (was Instrument: counter, unit: ``.).
  • generate.sh runs the go.mod toolchain's gofmt instead of a bare gofmt from PATH.
  • TestRenamedKeys no longer hard-codes 8 renames (subset + invariants).
  • packages/javascript adds a node10 types fallback (typesVersions) for the ./semconv subpath, for consumers on classic module resolution that don't read exports.
  • Flat Go namespace guard: generate.sh rejects a duplicate top-level constant in the generated Go with the offending name (Rust/Python keep these nested in modules/classes, so only Go can collide), ahead of a cryptic redeclared compile error.

Verification

All run locally with weaver 0.28.0 (the pinned CI version):

  • otel/check.sh — clean (only the pre-existing livekit_client_namespace advice)
  • otel/tests/negatives.sh — all fixtures fail with their named finding in both modes, including the two new alias fixtures
  • otel/generate.sh + git diff --cached otel/gen — no diff (generated outputs current)
  • go build ./otel/gen/go/..., go vet, go test ./otel/gotest/... — pass
  • tsc --strict --noEmit --target es2020 otel/gen/ts/semconv.ts — pass
  • otel/tests/codegen.sh (now incl. Go), otel/tests/generate.sh, otel/tests/live-check.sh — pass
  • rustc -D warnings -D missing_docs, python3 -I -W error on generated outputs — pass
  • pnpm --filter @livekit/protocol build — pass
Open in Web Open in Cursor 

cursoragent and others added 4 commits November 27, 2026 12:56
The gen_ai.client.inference.operation.details checkpoint brief in
agents/signals.yaml sat in a YAML flow mapping, so the comma inside it
started a new (invalid) mapping entry and truncated the brief at
'events cannot be referenced'. Quote the value so the whole sentence
survives into the generated Rust, Python and Markdown docs.

Co-authored-by: Jonas Schell <jonas@livekit.io>
Readers migrating to canonical lk.* keys need one source of truth for the
legacy spellings each canonical key replaces, and simple helpers to
normalize an ingest and expand a query, rather than ad-hoc fallback lists
per consumer (cloud-observability, cloud-api-server, livekit/web).

Model: extend renamed_from on the shared keys with a sibling 'aliases'
list for the legacy spellings beyond the single OTLP dotted rename (the
pre-#7973 Agents span names and the Go logger / collector spellings such
as roomID, room_id). renamed_from.key stays the OTLP rename that
live-check reads, so live-check remains OTLP-only.

Policy: livekit_shared_rename now forbids defining the dotted rename or
any alias as a key, and a new livekit_alias_collision rejects a legacy
spelling that maps to more than one canonical key, so the helpers stay
unambiguous. Both run in default and --v2 modes, with negative fixtures.

Codegen: RenamedKeys now covers every alias; KeyAliases maps a canonical
key to its legacy spellings; and NormalizeKey, NormalizeValue and
AliasesFor (plus normalizeKey/normalizeValue/aliasesFor in TypeScript,
exported from @livekit/protocol/semconv with no @bufbuild/protobuf dep)
give readers the normalize-on-ingest and expand-on-query operations. The
Markdown 'Old spellings' table lists the aliases, and the README
documents the dual-emit -> normalize/expand -> retire lifecycle.

Also fix the Go metric doc comments to omit the empty Unit clause for
unitless metrics (was rendering 'Instrument: counter, unit: ``.').

Part of OCD-3830.

Co-authored-by: Jonas Schell <jonas@livekit.io>
- mage otel snapshots otel/gen and restores it if generation, the Go
  build or gotest fails, so the Generate workflow never commits a broken
  partial regeneration.
- generate.sh runs the go.mod toolchain's gofmt (not whatever is on
  PATH) and rejects a flat-namespace constant collision in the generated
  Go with the offending name, rather than leaving it to a cryptic
  'redeclared' compile error (Rust and Python keep these in modules and
  classes, so only Go can collide).
- tests/codegen.sh round-trips the tricky escape value through the Go
  toolchain alongside rustc, tsc and python3.
- packages/javascript adds a node10 types fallback (typesVersions) for
  the @livekit/protocol/semconv subpath, for consumers on classic module
  resolution that do not read the exports map.

Part of OCD-3830.

Co-authored-by: Jonas Schell <jonas@livekit.io>
Regenerated from the model, policy and template changes: the legacy-key
alias maps and reader helpers in Go and TypeScript, the fuller checkpoint
brief, and the cleaned unitless-metric doc comments.

Part of OCD-3830.

Co-authored-by: Jonas Schell <jonas@livekit.io>
@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 77ff20a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

generate.sh runs under 'set -euo pipefail', so the collision-guard grep
aborted the script when semconv.go had no matching const lines. The real
output always has consts, but tests/generate.sh drives generate.sh with a
stub weaver that emits a const-less 'package semconv', which tripped it
and failed the 'generated outputs are current' CI step. Append '|| true'
so no match is benign; a real duplicate still makes uniq -d emit it.

Co-authored-by: Jonas Schell <jonas@livekit.io>
@ocupe
ocupe requested review from a team and pblazej November 27, 2026 15:53
… aliases

- normalizeKey / aliasesFor / normalizeValue looked up plain object
  literals, so a key such as `constructor` or `toString` resolved to an
  Object.prototype member (normalizeKey returned a function, aliasesFor
  threw). Look up own properties only.
- New livekit_alias_duplicate policy: a renamed_from alias that repeats
  the key, renamed_from.key or another alias would be a duplicate key in
  the generated Go map and TS object (a compile error in both), and the
  collision rule's set of pairs hides it. Adds a negative fixture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VE54KsZAzb79ACbpArh9Zv
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

4 participants