From 3e391bc2c8c0fafb007ecac724bdf764113d399e Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Tue, 4 Feb 2025 20:45:16 -0800 Subject: [PATCH] Alternative Logger option Signed-off-by: Bogdan Drutu --- component/telemetry.go | 10 ++++++++++ receiver/otlpreceiver/otlp.go | 2 ++ 2 files changed, 12 insertions(+) diff --git a/component/telemetry.go b/component/telemetry.go index 994064d9dfeb..21a0bb66ab56 100644 --- a/component/telemetry.go +++ b/component/telemetry.go @@ -7,6 +7,7 @@ import ( "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" "go.uber.org/zap" + "go.uber.org/zap/zapcore" "go.opentelemetry.io/collector/pdata/pcommon" ) @@ -26,3 +27,12 @@ type TelemetrySettings struct { // Resource contains the resource attributes for the collector's telemetry. Resource pcommon.Resource } + +func (ts *TelemetrySettings) LoggerWithout(fields ...string) *zap.Logger { + return ts.Logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core { + wc := core.(interface { + Without(fields ...string) zapcore.Core + }) + return wc.Without(fields...) + })) +} diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 0f8d3c663785..eb69997bbe5d 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -52,6 +52,8 @@ type otlpReceiver struct { // responsibility to invoke the respective Start*Reception methods as well // as the various Stop*Reception methods to end it. func newOtlpReceiver(cfg *Config, set *receiver.Settings) (*otlpReceiver, error) { + set.Logger = set.TelemetrySettings.LoggerWithout(componentattribute.SignalKey) + set.Logger.Debug("created signal-agnostic logger") r := &otlpReceiver{ cfg: cfg, nextTraces: nil,