Skip to content

db.client.operation.duration histogram uses wrong default bucket boundaries (all observations fall into first bucket) #631

Closed

Description

@kitosforos

Problem

The db.client.operation.duration histogram is created without the WithExplicitBucketBoundaries advisory option. In instruments.go, newInstruments calls:

if instruments.duration, err = dbconv.NewClientOperationDuration(meter); err != nil {

and the generated dbconv.NewClientOperationDuration helper (from go.opentelemetry.io/otel/semconv/v1.40.0/dbconv) only sets the description and unit — it does not set bucket boundaries either. As a result, the histogram falls back to the OTel SDK's generic default boundaries:

0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000

These defaults were designed for millisecond-scale values, but this metric's unit is seconds. Typical MySQL/PostgreSQL operations complete in 1–50 ms (0.001–0.05 s), so essentially 100% of observations land in the very first bucket (le=5.0, i.e. ≤ 5 seconds). All cumulative buckets above it are identical, which makes the histogram useless: histogram_quantile returns the same constant value for p50, p95, and p99.

What the spec says

The OTel semantic conventions for db.client.operation.duration state:

This metric SHOULD be specified with ExplicitBucketBoundaries of [ 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10 ].

This is a known OTel-wide issue: open-telemetry/opentelemetry-specification#3525 ("Default histogram bucket boundaries don't work for seconds durations"). The OTel TC decided not to change the SDK defaults and instead expects instrumentation authors to pass the advisory bucket boundaries. The same bug was reported and fixed in the npgsql .NET driver: npgsql/npgsql#6167.

Symptom

In Prometheus/Grafana, histogram_quantile(0.5, ...), histogram_quantile(0.95, ...), and histogram_quantile(0.99, ...) over db_client_operation_duration_seconds_bucket all return the same constant value (linear interpolation inside the single populated bucket), regardless of actual query latency.

Fix

Pass the spec-recommended boundaries when creating the instrument:

if instruments.duration, err = dbconv.NewClientOperationDuration(
	meter,
	metric.WithExplicitBucketBoundaries(0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10),
); err != nil {

metric.WithExplicitBucketBoundaries is already available in go.opentelemetry.io/otel/metric — no new dependencies needed. Users who need different boundaries can still override them with metric Views.

I'm opening a PR with this fix.

Activity

  1. added this to the v0.44.0 milestone on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions