Skip to content

feat(otel): export TS semconv from @livekit/protocol and add Go Weaver codegen - #2019

Merged
ocupe merged 3 commits into
mainfrom
js/ocd-3824-export-ts-semconv-go-weaver-codegen-4a48
Nov 27, 2026
Merged

ocupe merged 3 commits into
mainfrom
js/ocd-3824-export-ts-semconv-go-weaver-codegen-4a48

Conversation

@ocupe

@ocupe ocupe commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Implements a prerequisite for adopting Weaver-generated OTEL keys in livekit/web, livekit/cloud-api-server, and livekit/cloud-observability.

1. Export the TypeScript semconv from @livekit/protocol

otel/gen/ts/semconv.ts was generated by Weaver but unreachable from the published package.

  • Added a generate:semconv build step that copies otel/gen/ts/semconv.ts into src/gen/semconv.ts (gitignored, exactly like the protobuf generation), built as a separate unbuild entry, and exposed under a new ./semconv subpath in exports.
  • semconv.ts has no imports, so the subpath keeps the constants out of the protobuf barrel's bundle — importing @livekit/protocol/semconv never pulls in @bufbuild/protobuf (verified: the built dist/semconv.mjs has zero imports).
  • Stays in sync because the copy happens at build time from the committed otel/gen/ts/semconv.ts, which otel.yaml already keeps current against the model and type-checks with tsc --strict. The release/CI build compiles it via unbuild, and the JS CI job now also loads dist/semconv.{mjs,cjs}.

TS consumer import:

import { ATTR_LK_ROOM_ID, SPAN_LK_CONNECT, LkTrackSource } from "@livekit/protocol/semconv";

2. Go Weaver codegen target

New template otel/templates/registry/go/ generates otel/gen/go/semconv.go (package semconv), part of the protocol Go module, mirroring the Rust/Python outputs:

  • One constant per attribute key (AttrLkRoomId), enum value (LkTrackSourceSourceCamera), shipped value, event (EventLkRoomDisconnected), span (SpanLkConnect), checkpoint, and metric (MetricLkAgentsConnectionAcquireTime + its …Unit), plus the upstream OTel keys LiveKit references (error.type, gen_ai.*, …).
  • A generated renamed_from / alias mapping derived from the registry's renamed_from annotations, so Go consumers (the collector) can normalize legacy keys cleanly:
    • RenamedKeys — legacy key → canonical key (e.g. lk.room.sid → lk.room_id).
    • RenamedValues — legacy key → legacy value → canonical value, for the two enums whose values also changed (e.g. lk.track.source's camera → SOURCE_CAMERA).

Go consumer import:

import semconv "github.com/livekit/protocol/otel/gen/go"

key := semconv.AttrLkRoomId                 // "lk.room_id"
if canonical, ok := semconv.RenamedKeys[legacyKey]; ok { /* normalize */ }

Wiring

  • otel/generate.sh: added the go target; the output is gofmt'd so the committed file is canonical and diff-stable. otel/tests/generate.sh's stub weaver and expected-file list updated accordingly.
  • go tool mage otel: regenerates, then go build ./otel/gen/go/... and go test ./otel/gotest/....
  • otel/gotest/: a hand-written test of the alias-map invariants, kept outside otel/gen so regeneration never deletes it.
  • .github/workflows/otel.yaml: sets up Go and verifies go build / go vet / go test. The existing buildtest.yaml go test -race ./... and golangci-lint also cover the new packages (the generated file matches generated: strict and is excluded from lint).
  • .github/workflows/generate.yaml: already commits otel/gen (which now includes otel/gen/go).
  • otel/README.md: documents the Go target, import path, and alias maps.

Verification (all green locally, weaver 0.28.0)

  • otel/check.sh (default + --v2 + advice) — exit 0
  • otel/tests/negatives.sh — all fixtures fail with their named finding, both modes
  • otel/tests/generate.sh, otel/tests/codegen.sh, otel/tests/live-check.sh — PASS
  • otel/generate.sh then git diff otel/gen — only the new otel/gen/go/semconv.go (no drift)
  • Compiles: Rust (-D warnings -D missing_docs), TS (tsc --strict), Python (-W error), Go (go build ./...)
  • go test ./otel/gotest/... and golangci-lint run (v2.15.0) — PASS, 0 issues
  • pnpm --filter @livekit/protocol run build + loading dist/semconv.{mjs,cjs} — PASS

Design choices & follow-ups to review

  • Go package path otel/gen/go keeps the gen/<lang>/semconv.<ext> symmetry; package name is semconv, so consumers import it as semconv "github.com/livekit/protocol/otel/gen/go". (A directory named go is a valid path element — cf. cloud.google.com/go.)
  • Plain string constants (no named enum types, no otel SDK dependency) keep the package importable anywhere and keys directly comparable, matching the Rust/Python style.
  • gofmt in generate.sh is the one Go-specific post-step; Weaver emits unaligned const/map literals that gofmt would otherwise rewrite.
  • A changeset bumps @livekit/protocol / github.com/livekit/protocol (minor).
  • The Go package includes the upstream section (unlike the TS output, which the README notes does not carry it yet).
Open in Web Open in Cursor 

cursoragent and others added 3 commits November 27, 2026 10:52
The Weaver-generated TypeScript constants in otel/gen/ts/semconv.ts were not
reachable from the published @livekit/protocol package. Add a generate:semconv
build step that copies them into src/gen (like the protobuf generation), build
them as a separate unbuild entry, and expose them under the ./semconv subpath.

semconv.ts has no imports, so the subpath keeps the constants out of the
protobuf barrel's bundle: importing @livekit/protocol/semconv never pulls in
@bufbuild/protobuf.

Co-authored-by: Jonas Schell <jonas@livekit.io>
Generate an idiomatic Go package (github.com/livekit/protocol/otel/gen/go) from
the registry so Go services (cloud-observability, cloud-api-server, the
collector) can import canonical OTEL keys directly. It carries one constant per
attribute key, enum value, event, span, checkpoint and metric (with its unit),
and the upstream OTel keys LiveKit references, mirroring the Rust and Python
outputs.

It also generates two alias maps built from the shared keys' renamed_from
annotations: RenamedKeys (legacy key -> canonical key) and RenamedValues
(legacy key -> legacy value -> canonical value), so a consumer such as the
collector can normalize an older capture to the canonical names. The legacy
spellings are never registered, so they appear only in these maps.

otel/gotest holds a hand-written test of the alias-map invariants; it lives
outside otel/gen so regeneration never deletes it.

Co-authored-by: Jonas Schell <jonas@livekit.io>
Add the go target to otel/generate.sh (gofmt'd so the committed file is
canonical and diff-stable) and update the generate stub test accordingly. mage
otel now builds the generated Go package and runs otel/gotest after
regenerating. otel.yaml sets up Go and verifies go build/vet/test; buildtest's
go test ./... already compiles and tests the package on every PR. The JS CI job
also loads the new ./semconv entry points. Document the Go target, import path
and alias maps in otel/README.md.

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

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f8e9d2a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
github.com/livekit/protocol Minor
@livekit/protocol Minor

Not sure what this means? Click here to learn what changesets are.

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

@pblazej
pblazej requested review from a team and vadim82 November 27, 2026 11:24

@pblazej pblazej left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No blocking issues found. Two non-blocking suggestions below.

reads identically (\\ \" \r \n \t). -#}
{%- macro lit(s) -%}
"{{ s | replace("\\", "\\\\") | replace("\"", "\\\"") | replace("\r", "\\r") | replace("\n", "\\n") | replace("\t", "\\t") }}"
{%- endmacro -%}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add Go to the existing escaping tests? The new template handles string escaping separately, but those tests currently cover only Rust, TypeScript and Python.

// RenamedKeys maps a legacy attribute key to the canonical key that replaces it, from the
// `renamed_from` annotations on the shared keys. A consumer (such as the collector) uses it to
// normalize a legacy key read from an older capture to the key this registry defines. The legacy
// keys are never registered, so they appear only here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we document that these maps cover only renamed_from entries? They don’t include older Agents keys such as room_id and lk.room_sid, so collector users will need to handle those separately.

@ocupe
ocupe merged commit 245a596 into main Nov 27, 2026
13 checks passed
@ocupe
ocupe deleted the js/ocd-3824-export-ts-semconv-go-weaver-codegen-4a48 branch November 27, 2026 12:04
@github-actions github-actions Bot mentioned this pull request Nov 27, 2026
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.

3 participants