Files
Dmitry AnoshinandGitHub 6ed11d9842 Add support for deprecated component type aliases (#14349)
Related to
https://github.com/open-telemetry/opentelemetry-collector/issues/14208

This change allows component authors to register one optional deprecated
alias per component type, enabling smooth migrations when renaming
components. When an alias is used in configuration, the collector will
automatically resolve it to the original component and log a deprecation
warning.

Changes:
- Add `WithDeprecatedTypeAlias` factory option to experimental modules
(xreceiver, xexporter, xprocessor, xconnector)
- Generate alias expansion code in builder template that:
  - Populates factory maps with aliases pointing to original factories
  - Updates module information maps for aliased types
  - Validates that aliases don't conflict with existing component types
- Add deprecation warnings that log when an alias is used: "Using
deprecated alias <alias>; use <original> instead"

Extensions are left aside for now.
2026-01-08 00:01:09 +00:00

43 lines
1.3 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package builders // import "go.opentelemetry.io/collector/service/internal/builders"
import (
"errors"
"fmt"
"go.uber.org/zap"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/internal/componentalias"
)
var (
errNilNextConsumer = errors.New("nil next Consumer")
NopType = component.MustNewType("nop")
)
// logStabilityLevel logs the stability level of a component. The log level is set to info for
// undefined, unmaintained, deprecated and development. The log level is set to debug
// for alpha, beta and stable.
func logStabilityLevel(logger *zap.Logger, sl component.StabilityLevel) {
if sl >= component.StabilityLevelAlpha {
logger.Debug(sl.LogMessage())
} else {
logger.Info(sl.LogMessage())
}
}
// logDeprecatedTypeAlias checks if the provided type is a deprecated alias and logs a warning if so.
func logDeprecatedTypeAlias(logger *zap.Logger, factory component.Factory, usedType component.Type) {
tah, ok := factory.(componentalias.TypeAliasHolder)
if !ok {
return
}
alias := tah.DeprecatedAlias()
if alias.String() != "" && usedType == alias {
logger.Warn(fmt.Sprintf("%q alias is deprecated; use %q instead", alias.String(), factory.Type().String()))
}
}