Skip to content

Commit

Permalink
Setup the correct meter provider if telemetry.useOtelForInternalMetri…
Browse files Browse the repository at this point in the history
…cs featuregate enabled

This PR also removes the set of the global MeterProvider, similarly with #5138.

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Apr 4, 2022
1 parent 46e9040 commit b6cf33e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Remove deprecated structs/funcs from previous versions (#5131)
- Do not set TraceProvider to global otel (#5138)
- Remove deprecated funcs from otlpgrpc (#5144)
- Do not set MeterProvider to global otel (#5146)

### 🚩 Deprecations 🚩

Expand All @@ -16,6 +17,8 @@

### 🧰 Bug fixes 🧰

- Setup the correct meter provider if telemetry.useOtelForInternalMetrics featuregate enabled (#5146)

## v0.48.0 Beta

### 🛑 Breaking changes 🛑
Expand Down
20 changes: 11 additions & 9 deletions service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func New(set CollectorSettings) (*Collector, error) {
return &Collector{
logger: zap.NewNop(), // Set a Nop logger as a place holder until a logger is created based on configuration

tracerProvider: trace.NewNoopTracerProvider(),
meterProvider: nonrecording.NewNoopMeterProvider(),
asyncErrorChannel: make(chan error),

set: set,
state: int32(Starting),
shutdownChan: make(chan struct{}),
Expand Down Expand Up @@ -215,6 +219,13 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
return err
}

// TODO: This should be part of the service initialization, which should be responsible to create TelemetrySettings.
// For the moment happens here, since it needs service.Config and Logger.
// It is called once because that is how it is implemented using sync.Once.
if err = collectorTelemetry.init(col); err != nil {
return err
}

if err = col.service.Start(ctx); err != nil {
return err
}
Expand All @@ -230,20 +241,11 @@ func (col *Collector) Run(ctx context.Context) error {
sdktrace.WithSampler(internal.AlwaysRecord()),
sdktrace.WithSpanProcessor(col.zPagesSpanProcessor))

col.meterProvider = nonrecording.NewNoopMeterProvider()

col.asyncErrorChannel = make(chan error)

if err := col.setupConfigurationComponents(ctx); err != nil {
col.setCollectorState(Closed)
return err
}

if err := collectorTelemetry.init(col); err != nil {
col.setCollectorState(Closed)
return err
}

col.logger.Info("Starting "+col.set.BuildInfo.Command+"...",
zap.String("Version", col.set.BuildInfo.Version),
zap.Int("NumCPU", runtime.NumCPU()),
Expand Down
7 changes: 3 additions & 4 deletions service/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/google/uuid"
"go.opencensus.io/stats/view"
otelprometheus "go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
"go.opentelemetry.io/otel/sdk/metric/export/aggregation"
Expand Down Expand Up @@ -113,7 +112,7 @@ func (tel *colTelemetry) initOnce(col *Collector) error {

var pe http.Handler
if featuregate.IsEnabled(useOtelForInternalMetricsfeatureGateID) {
otelHandler, err := tel.initOpenTelemetry()
otelHandler, err := tel.initOpenTelemetry(col)
if err != nil {
return err
}
Expand Down Expand Up @@ -193,7 +192,7 @@ func (tel *colTelemetry) initOpenCensus(col *Collector, instanceID string) (http
return pe, nil
}

func (tel *colTelemetry) initOpenTelemetry() (http.Handler, error) {
func (tel *colTelemetry) initOpenTelemetry(col *Collector) (http.Handler, error) {
config := otelprometheus.Config{}
c := controller.New(
processor.NewFactory(
Expand All @@ -210,7 +209,7 @@ func (tel *colTelemetry) initOpenTelemetry() (http.Handler, error) {
return nil, err
}

global.SetMeterProvider(pe.MeterProvider())
col.meterProvider = pe.MeterProvider()
return pe, err
}

Expand Down

0 comments on commit b6cf33e

Please sign in to comment.