Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/otel-semconv-exports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"github.com/livekit/protocol": minor
"@livekit/protocol": minor
---

Export the Weaver-generated OTEL telemetry semantic conventions. `@livekit/protocol/semconv` now exposes the TypeScript constants as a dependency-free subpath, and a new Go package `github.com/livekit/protocol/otel/gen/go` exposes the Go constants (attribute keys, enum values, events, spans, checkpoints, metrics) plus `RenamedKeys` and `RenamedValues`, the legacy-key and legacy-value alias maps derived from the registry's `renamed_from` annotations for normalizing older captures.
2 changes: 2 additions & 0 deletions .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ jobs:
run: |
node --input-type=module -e "await import('./dist/index.mjs')"
node -e "require('./dist/index.cjs')"
node --input-type=module -e "await import('./dist/semconv.mjs')"
node -e "require('./dist/semconv.cjs')"
14 changes: 14 additions & 0 deletions .github/workflows/otel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
with:
version: "0.28.0"

# The Go codegen target is generated, gofmt'd and verified (go build/test) in this workflow.
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: "go.mod"

- name: Check the registry
run: otel/check.sh

Expand All @@ -62,6 +68,14 @@ jobs:
npx --yes -p typescript@5.9.3 tsc --strict --noEmit --target es2020 otel/gen/ts/semconv.ts
python3 -I -W error otel/gen/python/semconv.py

# The Go package is part of the protocol module, so downstream Go services import it from
# github.com/livekit/protocol/otel/gen/go. gotest encodes the alias-map invariants.
- name: Generated Go compiles and passes its tests
run: |
go build ./otel/gen/go/...
go vet ./otel/gen/go/... ./otel/gotest/...
go test ./otel/gotest/...

- name: Codegen escapes literals (round-trip through rustc, tsc and python3)
run: otel/tests/codegen.sh

Expand Down
18 changes: 17 additions & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,23 @@ func Proto() error {
func Otel() error {
cmd := exec.Command("otel/generate.sh")
connectStd(cmd)
return cmd.Run()
if err := cmd.Run(); err != nil {
return err
}

// Verify the generated Go package compiles and its alias invariants hold, so a model or
// template change that breaks the Go binding fails here next to generation, not downstream.
for _, args := range [][]string{
{"build", "./otel/gen/go/..."},
{"test", "./otel/gotest/..."},
} {
cmd := exec.Command("go", args...)
connectStd(cmd)
if err := cmd.Run(); err != nil {
return err
}
}
return nil
}

// run tests
Expand Down
23 changes: 19 additions & 4 deletions otel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,29 @@ policy, storage and the app API are not conventions and live with each SDK.
| `model/agents/groups.yaml` | GenAI metrics imported from the GenAI registry, and the values Agents sends for upstream keys that the upstream definitions do not list |
| `policies/` | LiveKit rules (`lib.rego`), applied per file (`livekit.rego`, default mode) and to the resolved registry (`resolved.rego`, default and `--v2`); any finding fails `check.sh` and `generate.sh` |
| `advice/` | Non-failing advice, printed by `check.sh` |
| `templates/registry/{rust,typescript,python,markdown}/` | Codegen templates |
| `gen/` | Generated outputs, committed: `rust/semconv.rs`, `ts/semconv.ts`, `python/semconv.py`, `docs/semconv.md` |
| `templates/registry/{go,rust,typescript,python,markdown}/` | Codegen templates |
| `gen/` | Generated outputs, committed: `go/semconv.go`, `rust/semconv.rs`, `ts/semconv.ts`, `python/semconv.py`, `docs/semconv.md` |
| `gotest/` | A Go test of the generated Go package's alias-map invariants; outside `gen/`, so regeneration never deletes it |
| `live-check/` | Live-check config, advice rules and the OTLP/JSON converter |
| `tests/` | Policy negatives, live-check samples, codegen escaping |

The generated docs, [`gen/docs/semconv.md`](gen/docs/semconv.md), are the human-readable spec:
naming rules, the Resource, the attributes on every record, each event and span with its
requirement table, enum values and bindings.

The Go output, [`gen/go/semconv.go`](gen/go/semconv.go), is part of the protocol Go module, so Go
services import it directly: `semconv "github.com/livekit/protocol/otel/gen/go"`. It gives one
constant per attribute key (`AttrLkRoomId`), enum value (`LkTrackSourceSourceCamera`), event
(`EventLkRoomDisconnected`), span (`SpanLkConnect`), checkpoint and metric
(`MetricLkAgentsConnectionAcquireTime` and its `…Unit`), plus two alias maps built from the shared
keys' `renamed_from` annotations:
`RenamedKeys` (legacy key → canonical key) and `RenamedValues` (legacy key → legacy value →
canonical value, for the two enums whose values also changed). A consumer such as the collector
uses them to normalize an older capture to the canonical names. The legacy spellings are never
registered, so they appear only in these maps. `generate.sh` gofmts the file; `go tool mage otel`,
`.github/workflows/otel.yaml` and the Test workflow (`go test ./...`) build the package and run
`otel/gotest` to check the alias-map invariants.

## Ownership

Every LiveKit key carries `annotations.livekit.owner`:
Expand Down Expand Up @@ -169,17 +183,18 @@ for each LiveKit file in the not-yet-stable `definition/2` format (`client/group
```sh
otel/check.sh # registry + LiveKit policies, default and --v2, then advice
otel/tests/negatives.sh # each negative fixture fails with its named finding, both modes
go tool mage otel && git status otel/gen # regenerate (runs otel/generate.sh); no diff expected
go tool mage otel && git status otel/gen # regenerate (runs generate.sh, then go build + test); no diff expected
otel/tests/live-check.sh # smoke and sparse samples clean, legacy keys flagged, wrapper exit status
otel/tests/generate.sh # generate.sh replaces gen/ whole, and keeps it when a target fails
otel/tests/codegen.sh # a value with quotes, backslashes, newlines round-trips through rustc, tsc and python3

rustc --edition 2021 --crate-type lib -D warnings -D missing_docs otel/gen/rust/semconv.rs --out-dir /tmp
npx -p typescript@5.9.3 tsc --strict --noEmit --target es2020 otel/gen/ts/semconv.ts
python3 -I -W error otel/gen/python/semconv.py
go build ./otel/gen/go/... && go test ./otel/gotest/... # the generated Go package and its alias-map invariants
```

The generated Rust and Python also carry an `upstream` section: every OTel key a LiveKit signal
The generated Rust, Python and Go also carry an `upstream` section: every OTel key a LiveKit signal
references (`error.type`, `gen_ai.request.model`, `rpc.method`, …), defined by a dependency and
never here, so a producer names them from one place. TypeScript does not yet. Three mechanisms
add to it:
Expand Down
Loading
Loading