Skip to content

feat(otel): group Python attribute values under a class per attribute - #1881

Open
pblazej wants to merge 1 commit into
lukas/ts-gen-const-objfrom
blaze/otel-semconv-py-grouping
Open

pblazej wants to merge 1 commit into
lukas/ts-gen-const-objfrom
blaze/otel-semconv-py-grouping

Conversation

@pblazej

@pblazej pblazej commented Oct 21, 2026 •

Copy link
Copy Markdown

Summary

This PR groups the generated Python values the same way #1872 groups the TypeScript values. Each attribute with a fixed set of values gets one plain class, with the same name as its TypeScript object. A plain class here is an ordinary class with one string constant per value. For example, GEN_AI_PROVIDER_NAME_MISTRAL_AI becomes GenAiProviderName.MISTRAL_AI. Rust already uses one module per attribute, so all three languages now use the same shape.

What changes

  • otel/templates/registry/python/semconv.py.j2 renders one class per attribute and removes the 141 flat value constants.
  • otel/gen/python/semconv.py has the regenerated output.
  • otel/tests/codegen.sh checks the new Python form.

Every value is still a plain str. The classes do not use enum, because Agents type-checks on Python 3.10 and sends the values as strings. The key, event, span, checkpoint and metric constants do not change. The Rust, TypeScript and Markdown output do not change.

Python has seven classes that TypeScript does not have. Each one is for an upstream key that Agents uses, such as GenAiProviderName and ErrorType. Upstream keys are keys that the OpenTelemetry conventions define. The TypeScript output does not list them, and this PR does not change that.

Effect on Agents

livekit/agents#7973 used 32 of the removed names, and it now uses the class form. Every string that Agents sends stays byte-identical. This PR builds on #1872, which builds on #1866, so those two PRs merge first.

The Python constants now group each attribute's values the way the
TypeScript const objects do: a plain class per attribute, with the same
name as the TypeScript object, whose attributes are the values as plain
str, and a one-line docstring that names the key constant. For example,
LK_DEVICE_APP_STATE_FOREGROUND is now LkDeviceAppState.FOREGROUND. The
class is not an enum.Enum, so the values stay plain str. Upstream keys
in the upstream section get a class too, and shipped values render into
their key's class (GenAiProviderName.MISTRAL_AI).

The 141 flat value constants are removed, so a value has one spelling.
The key, event, span, checkpoint and metric constants do not change, and
the generated Rust, TypeScript and docs do not change. codegen.sh reads
the escaped test value as LkTestEscape.TRICKY, and the README example
uses the new spelling.
@pblazej
pblazej added this pull request to stack #1877 October 21, 2026 16:08
@pblazej
pblazej marked this pull request as ready for review October 21, 2026 16:09
@pblazej
pblazej requested a review from lukasIO October 21, 2026 16:10
@changeset-bot

changeset-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8b2aa35

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

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.

1 participant