sdk/metric: wire experimental WithBinding for Sum instruments #9590
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #9590"
general
weight: 0.35
dashpole
Part of #8759
Adds experimental
sdkmetricx.WithBinding()togo.opentelemetry.io/otel/sdk/metric/xand wires bound-instrument support forInt64Counter,Float64Counter,Int64UpDownCounter, andFloat64UpDownCounterusing the internalBoundSumaggregation merged in #9278.Summary
sdk/metric/x.WithBinding()): Uses the existing structuralexperimentalOptionseam (BindingEnabled() bool) so regularsdk/metric.NewMeterProvider()instruments do not expose experimentalBindermethods and incur zero hot-path overhead.sdk/metric/experimental_bind.go): Decorates opted-in meters for the four counter and up-down counter types using the sharedforEachStreampipeline resolver.AggregationSumstreams bind viaBuilder.BoundSum(resolving filters, cardinality limits, and exemplar reservoirs atBind()time); other compatible aggregations (such as Histogram views or reader selectors) fall back to recording with the pre-bound attributes.- Attribute-free
Addcalls (including empty attribute options) invoke pre-resolvedBoundMeasureclosures with zero map lookups and zero allocations.- Record-time attributes merge on top of bound attributes (record-time wins on duplicate keys) and fan out across all resolved streams.
- Caller slices passed to
Bind()are cloned and normalized (attrnorm.SetDedup) so caller storage is never mutated or retained.- Bound and unbound calls to the same attribute set share the same
BoundSumseries and cardinality slot.ExampleWithBinding, unit/concurrency tests covering both temporalities, views, composable views, opt-in views, cardinality evaluation at bind time, exemplars, andBenchmarkInt64CounterBind.Alternatives Considered
sdk/metric/internal/bindpackage (mirroringsdk/metric/internal/finish): Unlikefinish.Lifecycle,sdk/metric/internal/aggregatedoes not need to import binding wrappers becauseaggregate.Binder[N]andaggregate.BoundMeasure[N]already live inaggregate. Keeping the meter and instrument wrappers insdk/metric/experimental_bind.go(matchingexperimental_configurator_.go) avoids an extra internal package and redundant factory interface while keepingsdk/metricproduction code free ofmetric/ximports.WithBinding()andWithFinish()in this PR: Deferred per the SIG agreement on #8962 until combined lifecycle + bound support is requested. Passing both options logs a warning viaglobal.Warn, withWithBinding()taking precedence on overlapping counter instruments.Benchmarks (
benchstat,-count=6 -benchtime=100ms)Bound
Int64Counter.Addcuts recording latency by ~87% for Cumulative and ~79% for Delta with0 B/op,0 allocs/op. Unbound recording on an opted-in provider stays within ~1-3% of stable, and all existingsdk/metric/xbenchmarks show0allocation changes (sdk/metric/instrument.go,sum.go, andatomic.goare unchanged).