Repository navigation
feat(otel): export TS semconv from @livekit/protocol and add Go Weaver codegen - #2019
Conversation
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 detectedLatest commit: f8e9d2a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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
left a comment
There was a problem hiding this comment.
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 -%} |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
Implements a prerequisite for adopting Weaver-generated OTEL keys in
livekit/web,livekit/cloud-api-server, andlivekit/cloud-observability.1. Export the TypeScript semconv from
@livekit/protocolotel/gen/ts/semconv.tswas generated by Weaver but unreachable from the published package.generate:semconvbuild step that copiesotel/gen/ts/semconv.tsintosrc/gen/semconv.ts(gitignored, exactly like the protobuf generation), built as a separateunbuildentry, and exposed under a new./semconvsubpath inexports.semconv.tshas no imports, so the subpath keeps the constants out of the protobuf barrel's bundle — importing@livekit/protocol/semconvnever pulls in@bufbuild/protobuf(verified: the builtdist/semconv.mjshas zero imports).otel/gen/ts/semconv.ts, whichotel.yamlalready keeps current against the model and type-checks withtsc --strict. The release/CI build compiles it viaunbuild, and the JS CI job now also loadsdist/semconv.{mjs,cjs}.TS consumer import:
2. Go Weaver codegen target
New template
otel/templates/registry/go/generatesotel/gen/go/semconv.go(packagesemconv), part of the protocol Go module, mirroring the Rust/Python outputs: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.*, …).renamed_from/ alias mapping derived from the registry'srenamed_fromannotations, 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'scamera→SOURCE_CAMERA).Go consumer import:
Wiring
otel/generate.sh: added thegotarget; the output isgofmt'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, thengo build ./otel/gen/go/...andgo test ./otel/gotest/....otel/gotest/: a hand-written test of the alias-map invariants, kept outsideotel/genso regeneration never deletes it..github/workflows/otel.yaml: sets up Go and verifiesgo build/go vet/go test. The existingbuildtest.yamlgo test -race ./...and golangci-lint also cover the new packages (the generated file matchesgenerated: strictand is excluded from lint)..github/workflows/generate.yaml: already commitsotel/gen(which now includesotel/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 0otel/tests/negatives.sh— all fixtures fail with their named finding, both modesotel/tests/generate.sh,otel/tests/codegen.sh,otel/tests/live-check.sh— PASSotel/generate.shthengit diff otel/gen— only the newotel/gen/go/semconv.go(no drift)-D warnings -D missing_docs), TS (tsc --strict), Python (-W error), Go (go build ./...)go test ./otel/gotest/...andgolangci-lint run(v2.15.0) — PASS, 0 issuespnpm --filter @livekit/protocol run build+ loadingdist/semconv.{mjs,cjs}— PASSDesign choices & follow-ups to review
otel/gen/gokeeps thegen/<lang>/semconv.<ext>symmetry; package name issemconv, so consumers import it assemconv "github.com/livekit/protocol/otel/gen/go". (A directory namedgois a valid path element — cf.cloud.google.com/go.)stringconstants (no named enum types, no otel SDK dependency) keep the package importable anywhere and keys directly comparable, matching the Rust/Python style.gofmtingenerate.shis the one Go-specific post-step; Weaver emits unaligned const/map literals that gofmt would otherwise rewrite.changesetbumps@livekit/protocol/github.com/livekit/protocol(minor).upstreamsection (unlike the TS output, which the README notes does not carry it yet).