From 84682995262778535bc94f24c1224175f26c9461 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 7 Sep 2021 16:59:13 -0700 Subject: [PATCH] add TelemetryCreateSettings --- component/componenttest/nop_exporter.go | 8 ++--- component/componenttest/nop_extension.go | 8 ++--- component/componenttest/nop_processor.go | 8 ++--- component/componenttest/nop_receiver.go | 8 ++--- component/componenttest/nop_telemetry.go | 30 +++++++++++++++++++ component/exporter.go | 10 +------ component/extension.go | 10 +------ component/processor.go | 10 +------ component/receiver.go | 10 +------ component/telemetry.go | 29 ++++++++++++++++++ service/internal/builder/exporters_builder.go | 8 +++-- .../internal/builder/extensions_builder.go | 12 ++++---- service/internal/builder/pipelines_builder.go | 8 +++-- service/internal/builder/receivers_builder.go | 8 +++-- 14 files changed, 93 insertions(+), 74 deletions(-) create mode 100644 component/componenttest/nop_telemetry.go create mode 100644 component/telemetry.go diff --git a/component/componenttest/nop_exporter.go b/component/componenttest/nop_exporter.go index 2a474e6b02f..405ac628e1e 100644 --- a/component/componenttest/nop_exporter.go +++ b/component/componenttest/nop_exporter.go @@ -17,9 +17,6 @@ package componenttest import ( "context" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" @@ -29,9 +26,8 @@ import ( // NewNopExporterCreateSettings returns a new nop settings for Create*Exporter functions. func NewNopExporterCreateSettings() component.ExporterCreateSettings { return component.ExporterCreateSettings{ - Logger: zap.NewNop(), - TracerProvider: trace.NewNoopTracerProvider(), - BuildInfo: component.DefaultBuildInfo(), + TelemetryCreateSettings: NewNopTelemetryCreateSettings(), + BuildInfo: component.DefaultBuildInfo(), } } diff --git a/component/componenttest/nop_extension.go b/component/componenttest/nop_extension.go index 222cb940b91..ef3d1c4f9f2 100644 --- a/component/componenttest/nop_extension.go +++ b/component/componenttest/nop_extension.go @@ -17,9 +17,6 @@ package componenttest import ( "context" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" @@ -28,9 +25,8 @@ import ( // NewNopExtensionCreateSettings returns a new nop settings for Create*Extension functions. func NewNopExtensionCreateSettings() component.ExtensionCreateSettings { return component.ExtensionCreateSettings{ - Logger: zap.NewNop(), - TracerProvider: trace.NewNoopTracerProvider(), - BuildInfo: component.DefaultBuildInfo(), + TelemetryCreateSettings: NewNopTelemetryCreateSettings(), + BuildInfo: component.DefaultBuildInfo(), } } diff --git a/component/componenttest/nop_processor.go b/component/componenttest/nop_processor.go index 0e7fd1b5f07..4925e9a4f08 100644 --- a/component/componenttest/nop_processor.go +++ b/component/componenttest/nop_processor.go @@ -17,9 +17,6 @@ package componenttest import ( "context" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" @@ -30,9 +27,8 @@ import ( // NewNopProcessorCreateSettings returns a new nop settings for Create*Processor functions. func NewNopProcessorCreateSettings() component.ProcessorCreateSettings { return component.ProcessorCreateSettings{ - Logger: zap.NewNop(), - TracerProvider: trace.NewNoopTracerProvider(), - BuildInfo: component.DefaultBuildInfo(), + TelemetryCreateSettings: NewNopTelemetryCreateSettings(), + BuildInfo: component.DefaultBuildInfo(), } } diff --git a/component/componenttest/nop_receiver.go b/component/componenttest/nop_receiver.go index 1f449e1ba0e..26ae39e99d8 100644 --- a/component/componenttest/nop_receiver.go +++ b/component/componenttest/nop_receiver.go @@ -17,9 +17,6 @@ package componenttest import ( "context" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenthelper" "go.opentelemetry.io/collector/config" @@ -29,9 +26,8 @@ import ( // NewNopReceiverCreateSettings returns a new nop settings for Create*Receiver functions. func NewNopReceiverCreateSettings() component.ReceiverCreateSettings { return component.ReceiverCreateSettings{ - Logger: zap.NewNop(), - TracerProvider: trace.NewNoopTracerProvider(), - BuildInfo: component.DefaultBuildInfo(), + TelemetryCreateSettings: NewNopTelemetryCreateSettings(), + BuildInfo: component.DefaultBuildInfo(), } } diff --git a/component/componenttest/nop_telemetry.go b/component/componenttest/nop_telemetry.go new file mode 100644 index 00000000000..7d5c6e7a0ce --- /dev/null +++ b/component/componenttest/nop_telemetry.go @@ -0,0 +1,30 @@ +// 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 componenttest + +import ( + "go.opentelemetry.io/otel/trace" + "go.uber.org/zap" + + "go.opentelemetry.io/collector/component" +) + +// NewNopTelemetryCreateSettings returns a new nop telemetry settings for Create* functions. +func NewNopTelemetryCreateSettings() component.TelemetryCreateSettings { + return component.TelemetryCreateSettings{ + Logger: zap.NewNop(), + TracerProvider: trace.NewNoopTracerProvider(), + } +} diff --git a/component/exporter.go b/component/exporter.go index 2e469350082..82c358468b4 100644 --- a/component/exporter.go +++ b/component/exporter.go @@ -17,9 +17,6 @@ package component import ( "context" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -49,12 +46,7 @@ type LogsExporter interface { // ExporterCreateSettings configures Exporter creators. type ExporterCreateSettings struct { - // Logger that the factory can use during creation and can pass to the created - // component to be used later as well. - Logger *zap.Logger - - // TracerProvider that the factory can pass to other instrumented third-party libraries. - TracerProvider trace.TracerProvider + TelemetryCreateSettings // BuildInfo can be used by components for informational purposes BuildInfo BuildInfo diff --git a/component/extension.go b/component/extension.go index 9f865c7f966..6296ee29c19 100644 --- a/component/extension.go +++ b/component/extension.go @@ -17,9 +17,6 @@ package component import ( "context" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" - "go.opentelemetry.io/collector/config" ) @@ -49,12 +46,7 @@ type PipelineWatcher interface { // ExtensionCreateSettings is passed to ExtensionFactory.Create* functions. type ExtensionCreateSettings struct { - // Logger that the factory can use during creation and can pass to the created - // component to be used later as well. - Logger *zap.Logger - - // TracerProvider that the factory can pass to other instrumented third-party libraries. - TracerProvider trace.TracerProvider + TelemetryCreateSettings // BuildInfo can be used by components for informational purposes BuildInfo BuildInfo diff --git a/component/processor.go b/component/processor.go index c6035317b8c..cfa132e3da4 100644 --- a/component/processor.go +++ b/component/processor.go @@ -17,9 +17,6 @@ package component import ( "context" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" - "go.opentelemetry.io/collector/component/componenterror" "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" @@ -51,12 +48,7 @@ type LogsProcessor interface { // ProcessorCreateSettings is passed to Create* functions in ProcessorFactory. type ProcessorCreateSettings struct { - // Logger that the factory can use during creation and can pass to the created - // component to be used later as well. - Logger *zap.Logger - - // TracerProvider that the factory can pass to other instrumented third-party libraries. - TracerProvider trace.TracerProvider + TelemetryCreateSettings // BuildInfo can be used by components for informational purposes BuildInfo BuildInfo diff --git a/component/receiver.go b/component/receiver.go index fb2c885428a..20dbd16ba7e 100644 --- a/component/receiver.go +++ b/component/receiver.go @@ -17,9 +17,6 @@ package component import ( "context" - "go.opentelemetry.io/otel/trace" - "go.uber.org/zap" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/consumer" ) @@ -58,12 +55,7 @@ type LogsReceiver interface { // ReceiverCreateSettings configures Receiver creators. type ReceiverCreateSettings struct { - // Logger that the factory can use during creation and can pass to the created - // component to be used later as well. - Logger *zap.Logger - - // TracerProvider that the factory can pass to other instrumented third-party libraries. - TracerProvider trace.TracerProvider + TelemetryCreateSettings // BuildInfo can be used by components for informational purposes. BuildInfo BuildInfo diff --git a/component/telemetry.go b/component/telemetry.go new file mode 100644 index 00000000000..9b0b785fbaa --- /dev/null +++ b/component/telemetry.go @@ -0,0 +1,29 @@ +// 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 component + +import ( + "go.opentelemetry.io/otel/trace" + "go.uber.org/zap" +) + +type TelemetryCreateSettings struct { + // Logger that the factory can use during creation and can pass to the created + // component to be used later as well. + Logger *zap.Logger + + // TracerProvider that the factory can pass to other instrumented third-party libraries. + TracerProvider trace.TracerProvider +} diff --git a/service/internal/builder/exporters_builder.go b/service/internal/builder/exporters_builder.go index b1542b24fec..1c51c0ec216 100644 --- a/service/internal/builder/exporters_builder.go +++ b/service/internal/builder/exporters_builder.go @@ -160,9 +160,11 @@ func BuildExporters( // Build exporters exporters based on configuration and required input data types. for expID, expCfg := range cfg.Exporters { set := component.ExporterCreateSettings{ - Logger: logger.With(zap.String(zapNameKey, expID.String())), - TracerProvider: tracerProvider, - BuildInfo: buildInfo, + TelemetryCreateSettings: component.TelemetryCreateSettings{ + Logger: logger.With(zap.String(zapNameKey, expID.String())), + TracerProvider: tracerProvider, + }, + BuildInfo: buildInfo, } factory, exists := factories[expID.Type()] diff --git a/service/internal/builder/extensions_builder.go b/service/internal/builder/extensions_builder.go index cf610ceee18..096677495f2 100644 --- a/service/internal/builder/extensions_builder.go +++ b/service/internal/builder/extensions_builder.go @@ -132,11 +132,13 @@ func BuildExtensions( } set := component.ExtensionCreateSettings{ - Logger: logger.With( - zap.String(zapKindKey, zapKindExtension), - zap.String(zapNameKey, extID.String())), - TracerProvider: tracerProvider, - BuildInfo: buildInfo, + TelemetryCreateSettings: component.TelemetryCreateSettings{ + Logger: logger.With( + zap.String(zapKindKey, zapKindExtension), + zap.String(zapNameKey, extID.String())), + TracerProvider: tracerProvider, + }, + BuildInfo: buildInfo, } ext, err := buildExtension(context.Background(), factory, set, extCfg) if err != nil { diff --git a/service/internal/builder/pipelines_builder.go b/service/internal/builder/pipelines_builder.go index c589b69180c..978cdb2d259 100644 --- a/service/internal/builder/pipelines_builder.go +++ b/service/internal/builder/pipelines_builder.go @@ -161,9 +161,11 @@ func (pb *pipelinesBuilder) buildPipeline(ctx context.Context, pipelineCfg *conf // which we will build in the next loop iteration). var err error set := component.ProcessorCreateSettings{ - Logger: pb.logger.With(zap.String(zapKindKey, zapKindProcessor), zap.String(zapNameKey, procID.String())), - TracerProvider: pb.tracerProvider, - BuildInfo: pb.buildInfo, + TelemetryCreateSettings: component.TelemetryCreateSettings{ + Logger: pb.logger.With(zap.String(zapKindKey, zapKindProcessor), zap.String(zapNameKey, procID.String())), + TracerProvider: pb.tracerProvider, + }, + BuildInfo: pb.buildInfo, } switch pipelineCfg.InputType { diff --git a/service/internal/builder/receivers_builder.go b/service/internal/builder/receivers_builder.go index 84f7104756e..33619d182bd 100644 --- a/service/internal/builder/receivers_builder.go +++ b/service/internal/builder/receivers_builder.go @@ -99,9 +99,11 @@ func BuildReceivers( receivers := make(Receivers) for recvID, recvCfg := range cfg.Receivers { set := component.ReceiverCreateSettings{ - Logger: logger.With(zap.String(zapKindKey, zapKindReceiver), zap.String(zapNameKey, recvID.String())), - TracerProvider: tracerProvider, - BuildInfo: buildInfo, + TelemetryCreateSettings: component.TelemetryCreateSettings{ + Logger: logger.With(zap.String(zapKindKey, zapKindReceiver), zap.String(zapNameKey, recvID.String())), + TracerProvider: tracerProvider, + }, + BuildInfo: buildInfo, } rcv, err := rb.buildReceiver(context.Background(), set, recvCfg)