Skip to content

Commit

Permalink
Fix broken metrics exporting in the example (#2381)
Browse files Browse the repository at this point in the history
Pusher was missing in the metric controller creation. Due to this no metrics
were exported at all.

Added pusher similar to this example: https://github.com/open-telemetry/opentelemetry-go/blob/c066f15ed74fec52c4755014bfcf2bdfb8e0e661/example/otel-collector/main.go#L81

Tested with Collector and verified that now metrics are exported.

Also renamed "pusher" to "cont" since it is not a Pusher but a Controller.
  • Loading branch information
tigrannajaryan authored Jan 20, 2021
1 parent 86feb9e commit e8cc015
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/demo/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,24 @@ func initProvider() func() {
sdktrace.WithSpanProcessor(bsp),
)

pusher := controller.New(
cont := controller.New(
processor.New(
simple.NewWithExactDistribution(),
exp,
),
controller.WithCollectPeriod(7*time.Second),
controller.WithPusher(exp),
)

// set global propagator to tracecontext (the default is no-op).
otel.SetTextMapPropagator(propagation.TraceContext{})
otel.SetTracerProvider(tracerProvider)
otel.SetMeterProvider(pusher.MeterProvider())
pusher.Start(context.Background())
otel.SetMeterProvider(cont.MeterProvider())
cont.Start(context.Background())

return func() {
handleErr(tracerProvider.Shutdown(ctx), "failed to shutdown provider")
pusher.Stop(context.Background()) // pushes any last exports to the receiver
cont.Stop(context.Background()) // pushes any last exports to the receiver
handleErr(exp.Shutdown(ctx), "failed to stop exporter")
}
}
Expand Down

0 comments on commit e8cc015

Please sign in to comment.