mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
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.
43 lines
1.3 KiB
Go
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()))
|
|
}
|
|
}
|