Skip to content

feat(typescript): generate typed attributes and metrics on the OpenTelemetry JavaScript API - #60

Merged
yordis merged 8 commits into
mainfrom
yordis/feat-typescript-metrics-template
Oct 31, 2026
Merged

yordis merged 8 commits into
mainfrom
yordis/feat-typescript-metrics-template

Conversation

@yordis

@yordis yordis commented Oct 30, 2026

Copy link
Copy Markdown
Member
  • Applications on the plain OpenTelemetry JavaScript API have no package that renders a registry into typed attributes and instruments without adopting Effect, so they keep hand-typing metric names, units and attribute keys that drift from the registry.
  • Spans, events and entities are left for a later version so the metrics surface can land and be consumed first.

…lemetry JavaScript API

Applications that use the plain OpenTelemetry API had no package that renders a registry into typed attributes and instruments without adopting Effect.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@cursor

cursor Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
New codegen path directly shapes OpenTelemetry metric recording APIs; risk is mitigated by extensive fixtures and CI, but mistakes would affect downstream instrumentation that adopts the template.

Overview
Adds a new Weaver template package (templates/code/typescript) that emits schema.ts, attributes.ts, and metrics.ts for vanilla @opentelemetry/api—typed attribute constants/unions, branded getMeter, per-metric classes (plus observable variants), histogram bucket advice, and refinements sharing base instruments.

Validation and CI: buildscripts/check_typescript_output.sh copies fixture expected output into a temp workspace, runs strict tsc, node --test consumer tests against pinned OTel JS SDK (createRecorder in buildscripts/typescript/support.ts), and an esbuild pass that fails if unused modules retain side effects. mise run weaver:test:typescript and the Checks workflow run this alongside existing template tests. Docs list the package and how to write consumer.test.ts fixtures.

The suite includes broad golden expected/ trees and many expected-error.txt cases (collisions, aggregation, filtering, prototype keys, etc.).

Reviewed by Cursor Bugbot for commit 31d2831. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 191 files, which is 91 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6848efaf-9554-4165-a20b-f86d37bb89f5
Commits

Reviewing files that changed from the base of the PR and between 2b5f430 and 31d2831.

Files ignored due to path filters: 1
  • buildscripts/typescript/package-lock.json is excluded by !**/package-lock.json
Files selected for processing: 191
  • .config/mise/tasks/weaver/test/_default
  • .config/mise/tasks/weaver/test/typescript
  • .github/workflows/checks.yml
  • AGENTS.md
  • CONTRIBUTING.md
  • README.md
  • buildscripts/check_typescript_output.sh
  • buildscripts/typescript/package.json
  • buildscripts/typescript/support.ts
  • buildscripts/typescript/tsconfig.json
  • templates/code/typescript/README.md
  • templates/code/typescript/attributes.ts.j2
  • templates/code/typescript/macros.j2
  • templates/code/typescript/metrics.ts.j2
  • templates/code/typescript/schema.ts.j2
  • templates/code/typescript/tests/attribute_names/consumer.test.ts
  • templates/code/typescript/tests/attribute_names/expected/attributes.ts
  • templates/code/typescript/tests/attribute_names/expected/metrics.ts
  • templates/code/typescript/tests/attribute_names/expected/schema.ts
  • templates/code/typescript/tests/attribute_names/registry/manifest.yaml
  • templates/code/typescript/tests/attribute_names/registry/model.yaml
  • templates/code/typescript/tests/attribute_types/consumer.test.ts
  • templates/code/typescript/tests/attribute_types/expected/attributes.ts
  • templates/code/typescript/tests/attribute_types/expected/metrics.ts
  • templates/code/typescript/tests/attribute_types/expected/schema.ts
  • templates/code/typescript/tests/attribute_types/registry/manifest.yaml
  • templates/code/typescript/tests/attribute_types/registry/model.yaml
  • templates/code/typescript/tests/custom_boundaries/consumer.test.ts
  • templates/code/typescript/tests/custom_boundaries/expected/metrics.ts
  • templates/code/typescript/tests/custom_boundaries/expected/schema.ts
  • templates/code/typescript/tests/custom_boundaries/params.yaml
  • templates/code/typescript/tests/custom_boundaries/registry/manifest.yaml
  • templates/code/typescript/tests/custom_boundaries/registry/model.yaml
  • templates/code/typescript/tests/empty/expected/schema.ts
  • templates/code/typescript/tests/empty/registry/manifest.yaml
  • templates/code/typescript/tests/empty/registry/model.yaml
  • templates/code/typescript/tests/error_aggregation_counter/expected-error.txt
  • templates/code/typescript/tests/error_aggregation_counter/registry/manifest.yaml
  • templates/code/typescript/tests/error_aggregation_counter/registry/model.yaml
  • templates/code/typescript/tests/error_aggregation_fields/expected-error.txt
  • templates/code/typescript/tests/error_aggregation_fields/registry/manifest.yaml
  • templates/code/typescript/tests/error_aggregation_fields/registry/model.yaml
  • templates/code/typescript/tests/error_aggregation_method/expected-error.txt
  • templates/code/typescript/tests/error_aggregation_method/registry/manifest.yaml
  • templates/code/typescript/tests/error_aggregation_method/registry/model.yaml
  • templates/code/typescript/tests/error_attribute_field_collision/expected-error.txt
  • templates/code/typescript/tests/error_attribute_field_collision/registry/manifest.yaml
  • templates/code/typescript/tests/error_attribute_field_collision/registry/model.yaml
  • templates/code/typescript/tests/error_attribute_identifier/expected-error.txt
  • templates/code/typescript/tests/error_attribute_identifier/registry/manifest.yaml
  • templates/code/typescript/tests/error_attribute_identifier/registry/model.yaml
  • templates/code/typescript/tests/error_attribute_object/expected-error.txt
  • templates/code/typescript/tests/error_attribute_object/registry/manifest.yaml
  • templates/code/typescript/tests/error_attribute_object/registry/model.yaml
  • templates/code/typescript/tests/error_boundaries_empty/expected-error.txt
  • templates/code/typescript/tests/error_boundaries_empty/params.yaml
  • templates/code/typescript/tests/error_boundaries_empty/registry/manifest.yaml
  • templates/code/typescript/tests/error_boundaries_empty/registry/model.yaml
  • templates/code/typescript/tests/error_boundaries_nonfinite/expected-error.txt
  • templates/code/typescript/tests/error_boundaries_nonfinite/params.yaml
  • templates/code/typescript/tests/error_boundaries_nonfinite/registry/manifest.yaml
  • templates/code/typescript/tests/error_boundaries_nonfinite/registry/model.yaml
  • templates/code/typescript/tests/error_boundaries_order/expected-error.txt
  • templates/code/typescript/tests/error_boundaries_order/registry/manifest.yaml
  • templates/code/typescript/tests/error_boundaries_order/registry/model.yaml
  • templates/code/typescript/tests/error_boundaries_type/expected-error.txt
  • templates/code/typescript/tests/error_boundaries_type/params.yaml
  • templates/code/typescript/tests/error_boundaries_type/registry/manifest.yaml
  • templates/code/typescript/tests/error_boundaries_type/registry/model.yaml
  • templates/code/typescript/tests/error_collision/expected-error.txt
  • templates/code/typescript/tests/error_collision/registry/manifest.yaml
  • templates/code/typescript/tests/error_collision/registry/model.yaml
  • templates/code/typescript/tests/error_enum_member_collision/expected-error.txt
  • templates/code/typescript/tests/error_enum_member_collision/registry/manifest.yaml
  • templates/code/typescript/tests/error_enum_member_collision/registry/model.yaml
  • templates/code/typescript/tests/error_enum_member_identifier/expected-error.txt
  • templates/code/typescript/tests/error_enum_member_identifier/registry/manifest.yaml
  • templates/code/typescript/tests/error_enum_member_identifier/registry/model.yaml
  • templates/code/typescript/tests/error_enum_mixed_types/expected-error.txt
  • templates/code/typescript/tests/error_enum_mixed_types/registry/manifest.yaml
  • templates/code/typescript/tests/error_enum_mixed_types/registry/model.yaml
  • templates/code/typescript/tests/error_enum_symbol_collision/expected-error.txt
  • templates/code/typescript/tests/error_enum_symbol_collision/registry/manifest.yaml
  • templates/code/typescript/tests/error_enum_symbol_collision/registry/model.yaml
  • templates/code/typescript/tests/error_filtered_enum/expected-error.txt
  • templates/code/typescript/tests/error_filtered_enum/params.yaml
  • templates/code/typescript/tests/error_filtered_enum/registry/manifest.yaml
  • templates/code/typescript/tests/error_filtered_enum/registry/model.yaml
  • templates/code/typescript/tests/error_filtered_required/expected-error.txt
  • templates/code/typescript/tests/error_filtered_required/params.yaml
  • templates/code/typescript/tests/error_filtered_required/registry/manifest.yaml
  • templates/code/typescript/tests/error_filtered_required/registry/model.yaml
  • templates/code/typescript/tests/error_identifier/expected-error.txt
  • templates/code/typescript/tests/error_identifier/registry/manifest.yaml
  • templates/code/typescript/tests/error_identifier/registry/model.yaml
  • templates/code/typescript/tests/error_instrumentation_name/expected-error.txt
  • templates/code/typescript/tests/error_instrumentation_name/params.yaml
  • templates/code/typescript/tests/error_instrumentation_name/registry/manifest.yaml
  • templates/code/typescript/tests/error_instrumentation_name/registry/model.yaml
  • templates/code/typescript/tests/error_optional_prototype/expected-error.txt
  • templates/code/typescript/tests/error_optional_prototype/registry/manifest.yaml
  • templates/code/typescript/tests/error_optional_prototype/registry/model.yaml
  • templates/code/typescript/tests/error_prototype_field/expected-error.txt
  • templates/code/typescript/tests/error_prototype_field/registry/manifest.yaml
  • templates/code/typescript/tests/error_prototype_field/registry/model.yaml
  • templates/code/typescript/tests/error_prototype_key/expected-error.txt
  • templates/code/typescript/tests/error_prototype_key/registry/manifest.yaml
  • templates/code/typescript/tests/error_prototype_key/registry/model.yaml
  • templates/code/typescript/tests/error_refinement_value_type/expected-error.txt
  • templates/code/typescript/tests/error_refinement_value_type/registry/manifest.yaml
  • templates/code/typescript/tests/error_refinement_value_type/registry/model.yaml
  • templates/code/typescript/tests/error_reserved_meter/expected-error.txt
  • templates/code/typescript/tests/error_reserved_meter/registry/manifest.yaml
  • templates/code/typescript/tests/error_reserved_meter/registry/model.yaml
  • templates/code/typescript/tests/error_unsupported_attribute_type/expected-error.txt
  • templates/code/typescript/tests/error_unsupported_attribute_type/registry/manifest.yaml
  • templates/code/typescript/tests/error_unsupported_attribute_type/registry/model.yaml
  • templates/code/typescript/tests/error_unversioned_schema/expected-error.txt
  • templates/code/typescript/tests/error_unversioned_schema/registry/manifest.yaml
  • templates/code/typescript/tests/error_unversioned_schema/registry/model.yaml
  • templates/code/typescript/tests/error_value_type/expected-error.txt
  • templates/code/typescript/tests/error_value_type/registry/manifest.yaml
  • templates/code/typescript/tests/error_value_type/registry/model.yaml
  • templates/code/typescript/tests/error_vendor_prefixes/expected-error.txt
  • templates/code/typescript/tests/error_vendor_prefixes/params.yaml
  • templates/code/typescript/tests/error_vendor_prefixes/registry/manifest.yaml
  • templates/code/typescript/tests/error_vendor_prefixes/registry/model.yaml
  • templates/code/typescript/tests/exclude_deprecated/consumer.test.ts
  • templates/code/typescript/tests/exclude_deprecated/expected/attributes.ts
  • templates/code/typescript/tests/exclude_deprecated/expected/metrics.ts
  • templates/code/typescript/tests/exclude_deprecated/expected/schema.ts
  • templates/code/typescript/tests/exclude_deprecated/params.yaml
  • templates/code/typescript/tests/exclude_deprecated/registry/manifest.yaml
  • templates/code/typescript/tests/exclude_deprecated/registry/model.yaml
  • templates/code/typescript/tests/filtering/expected/attributes.ts
  • templates/code/typescript/tests/filtering/expected/metrics.ts
  • templates/code/typescript/tests/filtering/expected/schema.ts
  • templates/code/typescript/tests/filtering/params.yaml
  • templates/code/typescript/tests/filtering/registry/manifest.yaml
  • templates/code/typescript/tests/filtering/registry/model.yaml
  • templates/code/typescript/tests/header/consumer.test.ts
  • templates/code/typescript/tests/header/expected/attributes.ts
  • templates/code/typescript/tests/header/expected/metrics.ts
  • templates/code/typescript/tests/header/expected/schema.ts
  • templates/code/typescript/tests/header/params.yaml
  • templates/code/typescript/tests/header/registry/manifest.yaml
  • templates/code/typescript/tests/header/registry/model.yaml
  • templates/code/typescript/tests/histogram_boundaries/consumer.test.ts
  • templates/code/typescript/tests/histogram_boundaries/expected/attributes.ts
  • templates/code/typescript/tests/histogram_boundaries/expected/metrics.ts
  • templates/code/typescript/tests/histogram_boundaries/expected/schema.ts
  • templates/code/typescript/tests/histogram_boundaries/registry/manifest.yaml
  • templates/code/typescript/tests/histogram_boundaries/registry/myapp.yaml
  • templates/code/typescript/tests/imported/consumer.test.ts
  • templates/code/typescript/tests/imported/dependency/manifest.yaml
  • templates/code/typescript/tests/imported/dependency/model.yaml
  • templates/code/typescript/tests/imported/expected/metrics.ts
  • templates/code/typescript/tests/imported/expected/schema.ts
  • templates/code/typescript/tests/imported/registry/manifest.yaml
  • templates/code/typescript/tests/imported/registry/model.yaml
  • templates/code/typescript/tests/metrics/consumer.test.ts
  • templates/code/typescript/tests/metrics/expected/attributes.ts
  • templates/code/typescript/tests/metrics/expected/metrics.ts
  • templates/code/typescript/tests/metrics/expected/schema.ts
  • templates/code/typescript/tests/metrics/registry/manifest.yaml
  • templates/code/typescript/tests/metrics/registry/model.yaml
  • templates/code/typescript/tests/refinements/consumer.test.ts
  • templates/code/typescript/tests/refinements/expected/attributes.ts
  • templates/code/typescript/tests/refinements/expected/metrics.ts
  • templates/code/typescript/tests/refinements/expected/schema.ts
  • templates/code/typescript/tests/refinements/registry/manifest.yaml
  • templates/code/typescript/tests/refinements/registry/model.yaml
  • templates/code/typescript/tests/stable_only/consumer.test.ts
  • templates/code/typescript/tests/stable_only/expected/attributes.ts
  • templates/code/typescript/tests/stable_only/expected/metrics.ts
  • templates/code/typescript/tests/stable_only/expected/schema.ts
  • templates/code/typescript/tests/stable_only/params.yaml
  • templates/code/typescript/tests/stable_only/registry/manifest.yaml
  • templates/code/typescript/tests/stable_only/registry/model.yaml
  • templates/code/typescript/tests/unsupported_signals/expected/attributes.ts
  • templates/code/typescript/tests/unsupported_signals/expected/schema.ts
  • templates/code/typescript/tests/unsupported_signals/registry/manifest.yaml
  • templates/code/typescript/tests/unsupported_signals/registry/model.yaml
  • templates/code/typescript/tests/vendor_prefix/consumer.test.ts
  • templates/code/typescript/tests/vendor_prefix/expected/attributes.ts
  • templates/code/typescript/tests/vendor_prefix/expected/metrics.ts
  • templates/code/typescript/tests/vendor_prefix/expected/schema.ts
  • templates/code/typescript/tests/vendor_prefix/params.yaml
  • templates/code/typescript/tests/vendor_prefix/registry/manifest.yaml
  • templates/code/typescript/tests/vendor_prefix/registry/model.yaml
  • templates/code/typescript/weaver.yaml

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Unit and description stay inside the instrument, as the Go and Rust packages keep them, so callers have one registry constant to depend on.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
esbuild kept every generated class whenever an application imported one metric, and a build for a release before ES2022 paid a WeakMap lookup on every recording.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…rated metrics

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 50b637b. Configure here.

Comment thread templates/code/typescript/weaver.yaml Resolved
Code that needs only a metric name, such as an SDK view, should not bundle the instrument class.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…only

as const already rejects reassignment, so freezing every constant at load added runtime work without adding safety.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
YAML .inf and .nan passed as numbers, so generation failed later with an opaque error or emitted bucket boundaries the SDK cannot use.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis merged commit 1160f2e into main Oct 31, 2026
7 checks passed
@yordis
yordis deleted the yordis/feat-typescript-metrics-template branch October 31, 2026 14:46
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