diff --git a/service/extensions/extensions.go b/service/extensions/extensions.go index 5ddc87ce239b..18d6e6d20811 100644 --- a/service/extensions/extensions.go +++ b/service/extensions/extensions.go @@ -21,7 +21,6 @@ import ( "sort" "go.uber.org/multierr" - "go.uber.org/zap" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/extension" @@ -41,7 +40,7 @@ type Extensions struct { func (bes *Extensions) Start(ctx context.Context, host component.Host) error { bes.telemetry.Logger.Info("Starting extensions...") for extID, ext := range bes.extMap { - extLogger := extensionLogger(bes.telemetry.Logger, extID) + extLogger := components.ExtensionLogger(bes.telemetry.Logger, extID) extLogger.Info("Extension is starting...") if err := ext.Start(ctx, components.NewHostWrapper(host, extLogger)); err != nil { return err @@ -148,7 +147,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Extensions, error) { TelemetrySettings: set.Telemetry, BuildInfo: set.BuildInfo, } - extSet.TelemetrySettings.Logger = extensionLogger(set.Telemetry.Logger, extID) + extSet.TelemetrySettings.Logger = components.ExtensionLogger(set.Telemetry.Logger, extID) ext, err := set.Extensions.Create(ctx, extSet) if err != nil { @@ -165,9 +164,3 @@ func New(ctx context.Context, set Settings, cfg Config) (*Extensions, error) { return exts, nil } - -func extensionLogger(logger *zap.Logger, id component.ID) *zap.Logger { - return logger.With( - zap.String(components.ZapKindKey, components.ZapKindExtension), - zap.String(components.ZapNameKey, id.String())) -} diff --git a/service/internal/components/components.go b/service/internal/components/components.go index 093d05f54c2a..d74a3e66415c 100644 --- a/service/internal/components/components.go +++ b/service/internal/components/components.go @@ -25,8 +25,8 @@ import ( // for alpha, beta and stable. func LogStabilityLevel(logger *zap.Logger, sl component.StabilityLevel) { if sl >= component.StabilityLevelAlpha { - logger.Debug(sl.LogMessage(), zap.String(ZapStabilityKey, sl.String())) + logger.Debug(sl.LogMessage(), zap.String(zapStabilityKey, sl.String())) } else { - logger.Info(sl.LogMessage(), zap.String(ZapStabilityKey, sl.String())) + logger.Info(sl.LogMessage(), zap.String(zapStabilityKey, sl.String())) } } diff --git a/service/internal/components/constants.go b/service/internal/components/constants.go deleted file mode 100644 index b1bed541de98..000000000000 --- a/service/internal/components/constants.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package components // import "go.opentelemetry.io/collector/service/internal/components" - -const ( - ZapKindKey = "kind" - ZapKindReceiver = "receiver" - ZapKindProcessor = "processor" - ZapKindExporter = "exporter" - ZapKindExtension = "extension" - ZapKindPipeline = "pipeline" - ZapNameKey = "name" - ZapDataTypeKey = "data_type" - ZapStabilityKey = "stability" -) diff --git a/service/internal/components/loggers.go b/service/internal/components/loggers.go new file mode 100644 index 000000000000..9374396d2168 --- /dev/null +++ b/service/internal/components/loggers.go @@ -0,0 +1,60 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package components // import "go.opentelemetry.io/collector/service/internal/components" + +import ( + "go.uber.org/zap" + + "go.opentelemetry.io/collector/component" +) + +const ( + zapKindKey = "kind" + zapKindReceiver = "receiver" + zapKindProcessor = "processor" + zapKindExporter = "exporter" + zapKindExtension = "extension" + zapKindPipeline = "pipeline" + zapNameKey = "name" + zapDataTypeKey = "data_type" + zapStabilityKey = "stability" +) + +func ReceiverLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger { + return logger.With( + zap.String(zapKindKey, zapKindReceiver), + zap.String(zapNameKey, id.String()), + zap.String(zapKindPipeline, string(dt))) +} + +func ProcessorLogger(logger *zap.Logger, id component.ID, pipelineID component.ID) *zap.Logger { + return logger.With( + zap.String(zapKindKey, zapKindProcessor), + zap.String(zapNameKey, id.String()), + zap.String(zapKindPipeline, pipelineID.String())) +} + +func ExporterLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger { + return logger.With( + zap.String(zapKindKey, zapKindExporter), + zap.String(zapDataTypeKey, string(dt)), + zap.String(zapNameKey, id.String())) +} + +func ExtensionLogger(logger *zap.Logger, id component.ID) *zap.Logger { + return logger.With( + zap.String(zapKindKey, zapKindExtension), + zap.String(zapNameKey, id.String())) +} diff --git a/service/pipelines.go b/service/pipelines.go index a13cb52d71df..ca9e9270b1f1 100644 --- a/service/pipelines.go +++ b/service/pipelines.go @@ -21,7 +21,6 @@ import ( "sort" "go.uber.org/multierr" - "go.uber.org/zap" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" @@ -77,7 +76,7 @@ func (bps *builtPipelines) StartAll(ctx context.Context, host component.Host) er bps.telemetry.Logger.Info("Starting exporters...") for dt, expByID := range bps.allExporters { for expID, exp := range expByID { - expLogger := exporterLogger(bps.telemetry.Logger, expID, dt) + expLogger := components.ExporterLogger(bps.telemetry.Logger, expID, dt) expLogger.Info("Exporter is starting...") if err := exp.Start(ctx, components.NewHostWrapper(host, expLogger)); err != nil { return err @@ -89,7 +88,7 @@ func (bps *builtPipelines) StartAll(ctx context.Context, host component.Host) er bps.telemetry.Logger.Info("Starting processors...") for pipelineID, bp := range bps.pipelines { for i := len(bp.processors) - 1; i >= 0; i-- { - procLogger := processorLogger(bps.telemetry.Logger, bp.processors[i].id, pipelineID) + procLogger := components.ProcessorLogger(bps.telemetry.Logger, bp.processors[i].id, pipelineID) procLogger.Info("Processor is starting...") if err := bp.processors[i].comp.Start(ctx, components.NewHostWrapper(host, procLogger)); err != nil { return err @@ -101,7 +100,7 @@ func (bps *builtPipelines) StartAll(ctx context.Context, host component.Host) er bps.telemetry.Logger.Info("Starting receivers...") for dt, recvByID := range bps.allReceivers { for recvID, recv := range recvByID { - recvLogger := receiverLogger(bps.telemetry.Logger, recvID, dt) + recvLogger := components.ReceiverLogger(bps.telemetry.Logger, recvID, dt) recvLogger.Info("Receiver is starting...") if err := recv.Start(ctx, components.NewHostWrapper(host, recvLogger)); err != nil { return err @@ -234,7 +233,7 @@ func buildPipelines(ctx context.Context, set pipelinesSettings) (*builtPipelines TelemetrySettings: set.Telemetry, BuildInfo: set.BuildInfo, } - cSet.TelemetrySettings.Logger = exporterLogger(set.Telemetry.Logger, expID, pipelineID.Type()) + cSet.TelemetrySettings.Logger = components.ExporterLogger(set.Telemetry.Logger, expID, pipelineID.Type()) exp, err := buildExporter(ctx, cSet, set.Exporters, pipelineID) if err != nil { return nil, err @@ -268,7 +267,7 @@ func buildPipelines(ctx context.Context, set pipelinesSettings) (*builtPipelines TelemetrySettings: set.Telemetry, BuildInfo: set.BuildInfo, } - cSet.TelemetrySettings.Logger = processorLogger(set.Telemetry.Logger, procID, pipelineID) + cSet.TelemetrySettings.Logger = components.ProcessorLogger(set.Telemetry.Logger, procID, pipelineID) proc, err := buildProcessor(ctx, cSet, set.Processors, pipelineID, bp.lastConsumer) if err != nil { return nil, err @@ -325,7 +324,7 @@ func buildPipelines(ctx context.Context, set pipelinesSettings) (*builtPipelines TelemetrySettings: set.Telemetry, BuildInfo: set.BuildInfo, } - cSet.TelemetrySettings.Logger = receiverLogger(set.Telemetry.Logger, recvID, pipelineID.Type()) + cSet.TelemetrySettings.Logger = components.ReceiverLogger(set.Telemetry.Logger, recvID, pipelineID.Type()) recv, err := buildReceiver(ctx, cSet, set.Receivers, pipelineID, receiversConsumers[pipelineID.Type()][recvID]) if err != nil { return nil, err @@ -387,13 +386,6 @@ func buildFanOutExportersLogsConsumer(exporters []builtComponent) consumer.Logs return fanoutconsumer.NewLogs(consumers) } -func exporterLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger { - return logger.With( - zap.String(components.ZapKindKey, components.ZapKindExporter), - zap.String(components.ZapDataTypeKey, string(dt)), - zap.String(components.ZapNameKey, id.String())) -} - func buildProcessor(ctx context.Context, set processor.CreateSettings, builder *processor.Builder, @@ -416,13 +408,6 @@ func buildProcessor(ctx context.Context, return proc, nil } -func processorLogger(logger *zap.Logger, procID component.ID, pipelineID component.ID) *zap.Logger { - return logger.With( - zap.String(components.ZapKindKey, components.ZapKindProcessor), - zap.String(components.ZapNameKey, procID.String()), - zap.String(components.ZapKindPipeline, pipelineID.String())) -} - func buildReceiver(ctx context.Context, set receiver.CreateSettings, builder *receiver.Builder, @@ -457,13 +442,6 @@ func buildReceiver(ctx context.Context, return recv, nil } -func receiverLogger(logger *zap.Logger, id component.ID, dt component.DataType) *zap.Logger { - return logger.With( - zap.String(components.ZapKindKey, components.ZapKindReceiver), - zap.String(components.ZapNameKey, id.String()), - zap.String(components.ZapKindPipeline, string(dt))) -} - func (bps *builtPipelines) getPipelinesSummaryTableData() zpages.SummaryPipelinesTableData { sumData := zpages.SummaryPipelinesTableData{} sumData.Rows = make([]zpages.SummaryPipelinesTableRowData, 0, len(bps.pipelines))