Repository navigation
Use semconv-recommended bucket boundaries for db.client.operation.duration - #632
Conversation
…ation The duration histogram was created without explicit bucket boundaries, falling back to the SDK defaults (0, 5, 10, 25, ... 10000) which are meant for milliseconds. Since the metric unit is seconds, virtually all database operations land in the first bucket, making percentile queries useless. Pass the boundaries recommended by the OTel semantic conventions for db.client.operation.duration. Co-Authored-By: Claude Fable 5 <[email protected]>
1681037 to
4a17a3c
Compare
There was a problem hiding this comment.
Pull request overview
Configures database operation duration histograms with OTel-recommended boundaries for meaningful latency percentiles.
Changes:
- Adds explicit duration bucket boundaries.
- Updates metric expectations and adds a focused boundary test.
- Documents the fix in the changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
instruments.go |
Configures recommended histogram boundaries. |
instruments_test.go |
Verifies collected boundaries. |
utils_test.go |
Updates expected histogram data. |
CHANGELOG.md |
Records the corrected behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #632 +/- ##
=====================================
Coverage 85.5% 85.6%
=====================================
Files 15 15
Lines 694 697 +3
=====================================
+ Hits 594 597 +3
Misses 74 74
Partials 26 26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@kitosforos Thanks for your contribution! |
|
The changelog entry was added incorrectly in this PR. |
@gaiaz-iusipov Thanks for the notify. Time to enforce the changelog protection. |
Per #632 (comment) This PR adds a new action in CI to protect released sections in the changelog from being changed. It compares the released sections in the changelog from the base branch to the current PR. It fails if a change happens. Apply "Unlock Released Changelog" to bypass this check when doing a new release. Prior art: open-telemetry/opentelemetry-go#5560
This release is the last to support [Go 1.25]. The next release will require at least [Go 1.26]. ### Added - Support testing of [Go 1.27]. (#650) - Add `WithSpanErrorAttributesGetter` option to set additional attributes (e.g., `db.response.status_code`) on spans when an operation returns an error. (#651) - Add `SpanOptions.RowsChildOfQuery` to create `sql.rows` spans as children of the `sql.conn.query` or `sql.stmt.query` span that produced them, so concurrent queries can be correlated with their result iteration. (#652) - Support `driver.RowsColumnScanner` on [Go 1.27]. (#649) ### Changed - Replace `ErrorTypeAttributes` with `ErrorTypeAttribute` to avoid allocating an additional slice. (#643) - Upgrade OTel to `v1.46.0`. (#644) ### Fixed - `db.client.operation.duration` histogram now uses the explicit bucket boundaries recommended by the OTel Semantic Conventions (`0.001` to `10` seconds) instead of the SDK defaults, which placed virtually all database operations in the first bucket. (#632) [Go 1.26]: https://go.dev/doc/go1.26 [Go 1.25]: https://go.dev/doc/go1.25 [Go 1.27]: https://go.dev/doc/go1.27
Fixes #631
Why
The
db.client.operation.durationhistogram is created without explicit bucket boundaries, so the OTel SDK falls back to its generic defaults:These were designed for millisecond values, but this metric's unit is seconds — typical database operations (1–50 ms) all land in the first bucket (
le=5.0), sohistogram_quantilereturns the same constant value at every percentile (p50 = p95 = p99).See open-telemetry/opentelemetry-specification#3525 for the OTel-wide background: the TC decided to keep the SDK defaults and expects instrumentation libraries to pass advisory boundaries instead.
What
Pass the bucket boundaries recommended by the OTel semantic conventions for
db.client.operation.duration:Before:
After:
metric.WithExplicitBucketBoundariescomes fromgo.opentelemetry.io/otel/metric, already a dependency. Users can still override the boundaries with metric Views since these are advisory.Also adds a test asserting the collected histogram uses the recommended boundaries, and updates the expected metric data in
utils_test.go.🤖 Generated with Claude Code