Skip to content

fix: preserve configured metric attributes - #92

Open
skarm wants to merge 7 commits into
exaring:mainfrom
skarm:metric-attribute-ownership
Open

skarm wants to merge 7 commits into
exaring:mainfrom
skarm:metric-attribute-ownership

Conversation

@skarm

@skarm skarm commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Building precomputed operation attributes can lose labels supplied through WithMeterAttributes. When appending to t.meterAttrs reuses its backing array, attribute.NewSet sorts and deduplicates the shared input in place, corrupting configuration used by later sets and operation-name metrics.

Build each precomputed set from a copy of the configured attributes. Document the existing precedence: later user values win, instrumentation sets pgx.operation.type, and a non-empty computed operation name overrides a configured db.operation.name. An empty callback result preserves an explicitly configured name.

Validation:

  • Regression tests in the existing tracer_test.go fail on main and pass with the fix. ManualReader assertions cover duration and error metrics for all six operation kinds, empty attributes, repeated option calls, unsorted keys, duplicates and operation naming. Separate cases check key collisions and empty name results.
  • make test and go mod tidy -diff pass on Go 1.25.0 and 1.26.9; make lint passes with golangci-lint 2.12.2.
  • go test -race ./... passes on Go 1.25.0 and 1.27.2.

No public API or dependency changes. Restoring previously lost labels can change the identity of affected metric series.

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.

2 participants