-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] Remove use of alias types in service/telemetry (#11182)
This PR moves internal definitions that were aliased publicly to the public package, and makes sure that hides any other type so that the API surface is the same. Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com> Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
- Loading branch information
1 parent
07c3e17
commit 7253ab8
Showing
7 changed files
with
165 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package telemetry // import "go.opentelemetry.io/collector/service/telemetry" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/otel/metric" | ||
metricnoop "go.opentelemetry.io/otel/metric/noop" | ||
"go.opentelemetry.io/otel/trace" | ||
tracenoop "go.opentelemetry.io/otel/trace/noop" | ||
"go.uber.org/zap" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
// factoryOption apply changes to Factory. | ||
type factoryOption interface { | ||
// applyTelemetryFactoryOption applies the option. | ||
applyTelemetryFactoryOption(o *factory) | ||
} | ||
|
||
var _ factoryOption = (*factoryOptionFunc)(nil) | ||
|
||
// factoryOptionFunc is an factoryOption created through a function. | ||
type factoryOptionFunc func(*factory) | ||
|
||
func (f factoryOptionFunc) applyTelemetryFactoryOption(o *factory) { | ||
f(o) | ||
} | ||
|
||
var _ Factory = (*factory)(nil) | ||
|
||
// Factory is the implementation of Factory. | ||
type factory struct { | ||
createDefaultConfig component.CreateDefaultConfigFunc | ||
createLoggerFunc | ||
createTracerProviderFunc | ||
createMeterProviderFunc | ||
} | ||
|
||
func (f *factory) CreateDefaultConfig() component.Config { | ||
return f.createDefaultConfig() | ||
} | ||
|
||
// createLoggerFunc is the equivalent of Factory.CreateLogger. | ||
type createLoggerFunc func(context.Context, Settings, component.Config) (*zap.Logger, error) | ||
|
||
// withLogger overrides the default no-op logger. | ||
func withLogger(createLogger createLoggerFunc) factoryOption { | ||
return factoryOptionFunc(func(o *factory) { | ||
o.createLoggerFunc = createLogger | ||
}) | ||
} | ||
|
||
func (f *factory) CreateLogger(ctx context.Context, set Settings, cfg component.Config) (*zap.Logger, error) { | ||
if f.createLoggerFunc == nil { | ||
return zap.NewNop(), nil | ||
} | ||
return f.createLoggerFunc(ctx, set, cfg) | ||
} | ||
|
||
// createTracerProviderFunc is the equivalent of Factory.CreateTracerProvider. | ||
type createTracerProviderFunc func(context.Context, Settings, component.Config) (trace.TracerProvider, error) | ||
|
||
// withTracerProvider overrides the default no-op tracer provider. | ||
func withTracerProvider(createTracerProvider createTracerProviderFunc) factoryOption { | ||
return factoryOptionFunc(func(o *factory) { | ||
o.createTracerProviderFunc = createTracerProvider | ||
}) | ||
} | ||
|
||
func (f *factory) CreateTracerProvider(ctx context.Context, set Settings, cfg component.Config) (trace.TracerProvider, error) { | ||
if f.createTracerProviderFunc == nil { | ||
return tracenoop.NewTracerProvider(), nil | ||
} | ||
return f.createTracerProviderFunc(ctx, set, cfg) | ||
} | ||
|
||
// createMeterProviderFunc is the equivalent of Factory.CreateMeterProvider. | ||
type createMeterProviderFunc func(context.Context, Settings, component.Config) (metric.MeterProvider, error) | ||
|
||
// withMeterProvider overrides the default no-op meter provider. | ||
func withMeterProvider(createMeterProvider createMeterProviderFunc) factoryOption { | ||
return factoryOptionFunc(func(o *factory) { | ||
o.createMeterProviderFunc = createMeterProvider | ||
}) | ||
} | ||
|
||
func (f *factory) CreateMeterProvider(ctx context.Context, set Settings, cfg component.Config) (metric.MeterProvider, error) { | ||
if f.createMeterProviderFunc == nil { | ||
return metricnoop.NewMeterProvider(), nil | ||
} | ||
return f.createMeterProviderFunc(ctx, set, cfg) | ||
} | ||
|
||
func (f *factory) unexportedFactoryFunc() {} | ||
|
||
// newFactory returns a new Factory. | ||
func newFactory(createDefaultConfig component.CreateDefaultConfigFunc, options ...factoryOption) Factory { | ||
f := &factory{ | ||
createDefaultConfig: createDefaultConfig, | ||
} | ||
for _, op := range options { | ||
op.applyTelemetryFactoryOption(f) | ||
} | ||
return f | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.