1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Add support for the development attributes advisory parameter (#8135)

From [the
spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument-advisory-parameter-attributes):

> ##### Instrument advisory parameter: `Attributes`

> **Status**: [Development](../document-status.md)

> Applies to all instrument types.

> `Attributes` (a list of [attribute
keys](../common/README.md#attribute)) is
the recommended set of attribute keys to be used for the resulting
metrics.

We already have `WithAttributes` options, so i've opted to name this
`WithDefaultAttributes` to avoid naming collisions. We could also
consider `WithAttributeKeys`, or `WithDefaultAttributeKeys`

Follows the pattern for experimental options introduced in
https://github.com/open-telemetry/opentelemetry-go/pull/8111

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
David Ashpole
2026-04-10 14:38:44 -04:00
committed by GitHub
parent 56cd7ab86f
commit d96b420138
29 changed files with 612 additions and 54 deletions
+5
View File
@@ -0,0 +1,5 @@
# Experimental Metric Options
This package contains experimental options for the OpenTelemetry metric package.
These options are currently under development and not part of the stable API.
They may be changed in backwards-incompatible ways, or removed entirely.
+16
View File
@@ -0,0 +1,16 @@
module go.opentelemetry.io/otel/metric/x
go 1.25.0
require (
go.opentelemetry.io/otel v1.43.0
go.opentelemetry.io/otel/metric v1.43.0
)
require github.com/cespare/xxhash/v2 v2.3.0 // indirect
replace go.opentelemetry.io/otel/metric => ../../metric
replace go.opentelemetry.io/otel/trace => ../../trace
replace go.opentelemetry.io/otel => ../..
+18
View File
@@ -0,0 +1,18 @@
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+29
View File
@@ -0,0 +1,29 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// Package x contains experimental metric options.
package x // import "go.opentelemetry.io/otel/metric/x"
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)
type defaultAttributesOption struct {
metric.InstrumentOption
keys []attribute.Key
}
// Experimental prevents the API from panicking when the option is used.
func (defaultAttributesOption) Experimental() {}
func (o defaultAttributesOption) AllowedKeys() []attribute.Key {
return o.keys
}
// WithDefaultAttributes returns a metric.InstrumentOption that specifies default attribute keys.
// The implementation should treat keys that are not included in the passed keys as opt-in, and they should be filtered out by default.
// Users of [go.opentelemetry.io/otel/sdk/metric] can enable these attributes by using the AttributeFilter of a View to include them.
func WithDefaultAttributes(keys ...attribute.Key) metric.InstrumentOption {
return defaultAttributesOption{keys: keys}
}