Files
Dmitry AnoshinandGitHub d4b868ef34 [xextension] Add deprecated type alias support for extensions (#14405)
Add support for deprecated component type aliases to extensions,
following the implementation started in #14349

The new `xextension.WithDeprecatedTypeAlias` factory option allows
extension authors to register deprecated type aliases using:

  ```go
  xextension.NewFactory(
      newType,
      createDefaultConfig,
      createExtension,
      component.StabilityLevelAlpha,
      xextension.WithDeprecatedTypeAlias(oldType),
  )
2026-01-12 15:56:46 +00:00

52 lines
1.2 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package xextension // import "go.opentelemetry.io/collector/extension/xextension"
import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/internal/componentalias"
)
type Factory interface {
extension.Factory
}
type FactoryOption interface {
applyOption(o *factory)
}
type factoryOptionFunc func(*factory)
func (f factoryOptionFunc) applyOption(o *factory) {
f(o)
}
type factory struct {
extension.Factory
componentalias.TypeAliasHolder
}
func WithDeprecatedTypeAlias(alias component.Type) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.SetDeprecatedAlias(alias)
})
}
func NewFactory(
cfgType component.Type,
createDefaultConfig component.CreateDefaultConfigFunc,
createServiceExtension extension.CreateFunc,
sl component.StabilityLevel,
options ...FactoryOption,
) Factory {
f := &factory{TypeAliasHolder: componentalias.NewTypeAliasHolder()}
for _, opt := range options {
opt.applyOption(f)
}
f.Factory = extension.NewFactory(cfgType, createDefaultConfig, createServiceExtension, sl)
f.Factory.(componentalias.TypeAliasHolder).SetDeprecatedAlias(f.DeprecatedAlias())
return f
}