Skip to content

Commit

Permalink
Update variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
antonjim-te committed Sep 7, 2023
1 parent 37fcef7 commit 70f05d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
12 changes: 6 additions & 6 deletions component/componenttest/nop_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
// NewNopTelemetrySettings returns a new nop telemetry settings for Create* functions.
func NewNopTelemetrySettings() component.TelemetrySettings {
return component.TelemetrySettings{
Logger: zap.NewNop(),
GetSampledLoggerFunction: zap.NewNop,
TracerProvider: trace.NewNoopTracerProvider(),
MeterProvider: noop.NewMeterProvider(),
MetricsLevel: configtelemetry.LevelNone,
Resource: pcommon.NewResource(),
Logger: zap.NewNop(),
SampledLogger: zap.NewNop,
TracerProvider: trace.NewNoopTracerProvider(),
MeterProvider: noop.NewMeterProvider(),
MetricsLevel: configtelemetry.LevelNone,
Resource: pcommon.NewResource(),
}
}
13 changes: 4 additions & 9 deletions component/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ type TelemetrySettings struct {
// component to be used later as well.
Logger *zap.Logger

// GetSampledLoggerFunction is a function to get the sampled Logger
GetSampledLoggerFunction func() *zap.Logger
// SampledLogger is built from the logger. It is passed to the created component.
// It will be used to avoid flooding the logs with messages that are repeated frequently.
// It will be built the first time used.
SampledLogger func() *zap.Logger

// TracerProvider that the factory can pass to other instrumented third-party libraries.
TracerProvider trace.TracerProvider
Expand All @@ -33,10 +35,3 @@ type TelemetrySettings struct {
// Resource contains the resource attributes for the collector's telemetry.
Resource pcommon.Resource
}

// SampledLogger is built from the logger. It is passed to the created component.
// It will be used to avoid flooding the logs with messages that are repeated frequently.
// It will be built the first time used.
func (t *TelemetrySettings) SampledLogger() *zap.Logger {
return t.GetSampledLoggerFunction()
}
10 changes: 5 additions & 5 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) {
pcommonRes := pdataFromSdk(res)

srv.telemetrySettings = component.TelemetrySettings{
Logger: srv.telemetry.Logger(),
GetSampledLoggerFunction: srv.telemetry.SampledLogger(),
TracerProvider: srv.telemetry.TracerProvider(),
MeterProvider: noop.NewMeterProvider(),
MetricsLevel: cfg.Telemetry.Metrics.Level,
Logger: srv.telemetry.Logger(),
SampledLogger: srv.telemetry.SampledLogger(),
TracerProvider: srv.telemetry.TracerProvider(),
MeterProvider: noop.NewMeterProvider(),
MetricsLevel: cfg.Telemetry.Metrics.Level,

// Construct telemetry attributes from build info and config's resource attributes.
Resource: pcommonRes,
Expand Down
4 changes: 1 addition & 3 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,8 @@ func TestServiceTelemetryLoggers(t *testing.T) {
assert.NoError(t, srv.Shutdown(context.Background()))
})
assert.NotNil(t, srv.telemetrySettings.Logger)
assert.NotNil(t, srv.telemetrySettings.GetSampledLoggerFunction)
assert.NotNil(t, srv.telemetrySettings.SampledLogger())
assert.NotEqual(t, srv.telemetrySettings.Logger, srv.telemetrySettings.SampledLogger())
sampledLogger := srv.telemetrySettings.GetSampledLoggerFunction()
assert.Equal(t, sampledLogger, srv.telemetrySettings.SampledLogger())
}

func assertResourceLabels(t *testing.T, res pcommon.Resource, expectedLabels map[string]labelValue) {
Expand Down

0 comments on commit 70f05d8

Please sign in to comment.