Skip to content

feat(go): support typed batch observations - #65

Merged
yordis merged 1 commit into
mainfrom
yordis/feat-go-batch-observation
Nov 1, 2026
Merged

yordis merged 1 commit into
mainfrom
yordis/feat-go-batch-observation

Conversation

@yordis

@yordis yordis commented Nov 1, 2026

Copy link
Copy Markdown
Member
  • Related observable metrics need a shared snapshot for consistent collection.
  • Batch registration must preserve schema identity and typed attributes while keeping SDK handles private.
  • Existing per-instrument callbacks must remain compatible.

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

cursor Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Broad codegen output change (new types on every observable metric and a new Meter API), with behavior-sensitive ownership and callback semantics that consumers must adopt correctly.

Overview
Adds batch asynchronous metrics to the Go semantic-conventions codegen so several related observable instruments can share one collection callback and a single data snapshot, while keeping raw OpenTelemetry handles private.

Generated code now includes New<Name>BatchObservable, opaque Observable() handles, and typed Observe / ObserveSet on the batch types (histograms still have no async/batch form). The public <root>meter package re-exports Observable, Observer, Callback, and Registration, and Meter.RegisterCallback wires a typed callback through internal/scope.

internal/scope is refactored so Meter tracks ownership via shared meterState: handles must be registered on the same Meter value that created them, observations are limited to registered handles, duplicate handles are deduped, failed SDK registration is cleaned up, and individual per-instrument observables stay as they were.

Documentation, weaver.yaml identifier-collision rules for *BatchObservable names, golden expected output updates, compile-fail guards (no raw SDK types), and a batch_observables integration test suite cover mixed int/float, cross-namespace batches, concurrency, and unregister behavior.

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

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
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: 0c491074-170b-4828-a88f-d5866744a176
Commits

Reviewing files that changed from the base of the PR and between 90a9059 and c9bba66.

Files selected for processing: 69
  • templates/code/go/README.md
  • templates/code/go/meter.go.j2
  • templates/code/go/metrics.go.j2
  • templates/code/go/scope_meter.go.j2
  • templates/code/go/tests/batch_observables/compile-fail/fractional_integer.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/fractional_integer.go
  • templates/code/go/tests/batch_observables/compile-fail/histogram_observable.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/histogram_observable.go
  • templates/code/go/tests/batch_observables/compile-fail/missing_required_attribute.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/missing_required_attribute.go
  • templates/code/go/tests/batch_observables/compile-fail/native_instrument_access.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/native_instrument_access.go
  • templates/code/go/tests/batch_observables/compile-fail/native_observer_access.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/native_observer_access.go
  • templates/code/go/tests/batch_observables/compile-fail/raw_observer.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/raw_observer.go
  • templates/code/go/tests/batch_observables/compile-fail/raw_registration_handle.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/raw_registration_handle.go
  • templates/code/go/tests/batch_observables/compile-fail/raw_required_attribute.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/raw_required_attribute.go
  • templates/code/go/tests/batch_observables/compile-fail/wrong_option_type.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/wrong_option_type.go
  • templates/code/go/tests/batch_observables/compile-fail/wrong_set_type.expected-error.txt
  • templates/code/go/tests/batch_observables/compile-fail/wrong_set_type.go
  • templates/code/go/tests/batch_observables/consumer/myappmetric/batch_test.go
  • templates/code/go/tests/batch_observables/consumer/myappmetric/registration_test.go
  • templates/code/go/tests/batch_observables/expected/doc.go
  • templates/code/go/tests/batch_observables/expected/internal/scope/doc.go
  • templates/code/go/tests/batch_observables/expected/internal/scope/meter.go
  • templates/code/go/tests/batch_observables/expected/myappattr/attributes.go
  • templates/code/go/tests/batch_observables/expected/myappattr/doc.go
  • templates/code/go/tests/batch_observables/expected/myappmetric/doc.go
  • templates/code/go/tests/batch_observables/expected/myappmetric/metrics.go
  • templates/code/go/tests/batch_observables/expected/schema.go
  • templates/code/go/tests/batch_observables/expected/semconvmeter/doc.go
  • templates/code/go/tests/batch_observables/expected/semconvmeter/meter.go
  • templates/code/go/tests/batch_observables/expected/workermetric/doc.go
  • templates/code/go/tests/batch_observables/expected/workermetric/metrics.go
  • templates/code/go/tests/batch_observables/registry/manifest.yaml
  • templates/code/go/tests/batch_observables/registry/model.yaml
  • templates/code/go/tests/error_batch_constructor_collision/expected-error.txt
  • templates/code/go/tests/error_batch_constructor_collision/registry/manifest.yaml
  • templates/code/go/tests/error_batch_constructor_collision/registry/model.yaml
  • templates/code/go/tests/error_batch_observable_collision/expected-error.txt
  • templates/code/go/tests/error_batch_observable_collision/registry/manifest.yaml
  • templates/code/go/tests/error_batch_observable_collision/registry/model.yaml
  • templates/code/go/tests/histogram_boundaries_by_unit/expected/internal/scope/meter.go
  • templates/code/go/tests/histogram_boundaries_by_unit/expected/semconvmeter/meter.go
  • templates/code/go/tests/histogram_boundaries_by_unit_params/expected/internal/scope/meter.go
  • templates/code/go/tests/histogram_boundaries_by_unit_params/expected/semconvmeter/meter.go
  • templates/code/go/tests/imported/expected/internal/scope/meter.go
  • templates/code/go/tests/imported/expected/myappmetric/metrics.go
  • templates/code/go/tests/imported/expected/semconvmeter/meter.go
  • templates/code/go/tests/imported_typed/expected/internal/scope/meter.go
  • templates/code/go/tests/imported_typed/expected/myappmeter/meter.go
  • templates/code/go/tests/imported_typed/expected/myappmetric/metrics.go
  • templates/code/go/tests/metrics/expected/authmetric/metrics.go
  • templates/code/go/tests/metrics/expected/internal/scope/meter.go
  • templates/code/go/tests/metrics/expected/myappmetric/metrics.go
  • templates/code/go/tests/metrics/expected/semconvmeter/meter.go
  • templates/code/go/tests/params/expected/acmesemconvmeter/meter.go
  • templates/code/go/tests/params/expected/internal/scope/meter.go
  • templates/code/go/tests/root_package_from_import_path/expected/acmeconvmeter/meter.go
  • templates/code/go/tests/root_package_from_import_path/expected/internal/scope/meter.go
  • templates/code/go/tests/root_package_from_import_path/expected/myappmetric/metrics.go
  • templates/code/go/tests/root_package_version_segment/expected/acmeconvmeter/meter.go
  • templates/code/go/tests/root_package_version_segment/expected/internal/scope/meter.go
  • templates/code/go/tests/root_package_version_segment/expected/myappmetric/metrics.go
  • templates/code/go/weaver.yaml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The Go generator now supports batch-observable instruments and shared callback registration. Scoped handles restrict observations to registered instruments. Generated APIs include constructors and typed observation methods. The change also adds generated examples, behavior and compile-fail tests, documentation, and identifier-collision checks.

Changes

Batch observable API

Layer / File(s) Summary
Scoped callback and observation API
templates/code/go/scope_meter.go.j2, templates/code/go/meter.go.j2, templates/code/go/tests/*/expected/internal/scope/meter.go, templates/code/go/tests/*/expected/*meter/meter.go
The scoped meter adds opaque observable handles, callback registration, typed observation helpers, and safe unregistration. Generated meter packages expose the scoped types through aliases.
Generated batch metric APIs
templates/code/go/metrics.go.j2, templates/code/go/tests/*/expected/*metric/metrics.go, templates/code/go/tests/batch_observables/expected/*, templates/code/go/tests/batch_observables/registry/*, templates/code/go/README.md
Generated metric APIs add batch-observable constructors, handles, Observe, and, where attributes exist, ObserveSet. Examples cover multiple instrument types, attributes, sets, and schema-scoped meter construction.
Batch API behavior tests
templates/code/go/tests/batch_observables/consumer/myappmetric/*_test.go
Tests cover collection results, registration validation, meter ownership, callback context and errors, unregistration, zero values, and concurrent collections.
Compile and identifier validation
templates/code/go/tests/batch_observables/compile-fail/*, templates/code/go/tests/error_batch_*/*, templates/code/go/weaver.yaml
Compile-fail cases check invalid batch-observable calls and inaccessible native handles. Collision cases and generator validation include generated batch-observable names.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ScopeMeter as scope.Meter
  participant MetricMeter as metric.Meter
  participant BatchMetric as QueueDepthBatchObservable
  Caller->>ScopeMeter: RegisterCallback(callback, observable)
  ScopeMeter->>MetricMeter: RegisterCallback(native callback, instruments)
  MetricMeter->>ScopeMeter: Invoke callback with context and native observer
  ScopeMeter->>Caller: Supply scoped Observer to callback
  Caller->>BatchMetric: Observe(observer, value, attributes)
  BatchMetric->>ScopeMeter: ObserveInt64(observer, handle, value, options)
Loading

Possibly related PRs

Merge Risk: Minimal · up to c9bba

The change adds typed batch observable metrics to the Go generator while keeping existing per-instrument callbacks working. No concrete defect was identified in the supplied files. The remaining uncertainty is ordinary: the Go toolchain version for the generated consumer tests was not supplied. The change appears ready to merge after normal CI checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: adding typed batch observations for Go.
Description check Passed The description directly relates to the changeset by describing shared snapshots, batch registration, schema identity, typed attributes, private SDK handles, and callback compatibility.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 75.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 69 functions across 46 files. (23 skipped: 23 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

A rabbit records a queue’s bright glow
With one shared call, the values flow
A handle keeps each note in scope
Sets bring attributes, clear and whole
Then off I hop, with metrics in tow!

@yordis
yordis merged commit c2f0b99 into main Nov 1, 2026
7 checks passed
@yordis
yordis deleted the yordis/feat-go-batch-observation branch November 1, 2026 18:37
@sht-bot sht-bot mentioned this pull request Nov 1, 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.

1 participant