You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
Add support for experimental options in the metrics API (#8111)
Part of https://github.com/open-telemetry/opentelemetry-go/issues/8110 Related to https://github.com/open-telemetry/opentelemetry-go/issues/5882. I'm hoping to find a better way to support experimental Options types in our API packages. This is one approach to consider. This contains no public API changes. It introduces a type: `ExperimentalOption` in `/metric/internal/x`, which can be used by our experimental options defined outside of the module. Options that embed this interface are ignored by `New*Config` builder functions in the metrics API to prevent them from panicing when used. Only SDKs that explicitly support the experimental option in question will respect it. Alternative SDKs will ignore the experimental options. We would still need to treat ExperimentalOption as a stable artifact, since the SDK will indirectly depend on it. See https://github.com/open-telemetry/opentelemetry-go/compare/main...dashpole:opentelemetry-go:attributes_advisory for how this would be used to support the advisory attributes parameter.
This commit is contained in:
@@ -34,10 +34,17 @@ func (t *TracerConfig) SchemaURL() string {
|
||||
return t.schemaURL
|
||||
}
|
||||
|
||||
type experimentalOption interface {
|
||||
Experimental()
|
||||
}
|
||||
|
||||
// NewTracerConfig applies all the options to a returned TracerConfig.
|
||||
func NewTracerConfig(options ...TracerOption) TracerConfig {
|
||||
var config TracerConfig
|
||||
for _, option := range options {
|
||||
if _, ok := option.(experimentalOption); ok {
|
||||
continue
|
||||
}
|
||||
config = option.apply(config)
|
||||
}
|
||||
return config
|
||||
@@ -103,6 +110,9 @@ func (cfg *SpanConfig) SpanKind() SpanKind {
|
||||
func NewSpanStartConfig(options ...SpanStartOption) SpanConfig {
|
||||
var c SpanConfig
|
||||
for _, option := range options {
|
||||
if _, ok := option.(experimentalOption); ok {
|
||||
continue
|
||||
}
|
||||
c = option.applySpanStart(c)
|
||||
}
|
||||
return c
|
||||
@@ -115,6 +125,9 @@ func NewSpanStartConfig(options ...SpanStartOption) SpanConfig {
|
||||
func NewSpanEndConfig(options ...SpanEndOption) SpanConfig {
|
||||
var c SpanConfig
|
||||
for _, option := range options {
|
||||
if _, ok := option.(experimentalOption); ok {
|
||||
continue
|
||||
}
|
||||
c = option.applySpanEnd(c)
|
||||
}
|
||||
return c
|
||||
@@ -167,6 +180,9 @@ func (cfg *EventConfig) StackTrace() bool {
|
||||
func NewEventConfig(options ...EventOption) EventConfig {
|
||||
var c EventConfig
|
||||
for _, option := range options {
|
||||
if _, ok := option.(experimentalOption); ok {
|
||||
continue
|
||||
}
|
||||
c = option.applyEvent(c)
|
||||
}
|
||||
if c.timestamp.IsZero() {
|
||||
|
||||
@@ -544,3 +544,21 @@ func TestWithInstrumentationAttributesMerge(t *testing.T) {
|
||||
"Attributes and attribute sets should be merged together.")
|
||||
})
|
||||
}
|
||||
|
||||
type testExperimentalOption struct {
|
||||
TracerOption
|
||||
SpanStartOption
|
||||
SpanEndOption
|
||||
EventOption
|
||||
}
|
||||
|
||||
func (testExperimentalOption) Experimental() {}
|
||||
|
||||
func TestExperimentalOptionSafe(t *testing.T) {
|
||||
var opt testExperimentalOption
|
||||
|
||||
assert.NotPanics(t, func() { _ = NewTracerConfig(opt) })
|
||||
assert.NotPanics(t, func() { _ = NewSpanStartConfig(opt) })
|
||||
assert.NotPanics(t, func() { _ = NewSpanEndConfig(opt) })
|
||||
assert.NotPanics(t, func() { _ = NewEventConfig(opt) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user