Skip to content

Commit e8cc015

Browse files
Fix broken metrics exporting in the example (#2381)
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.
1 parent 86feb9e commit e8cc015

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

examples/demo/app/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,24 @@ func initProvider() func() {
7171
sdktrace.WithSpanProcessor(bsp),
7272
)
7373

74-
pusher := controller.New(
74+
cont := controller.New(
7575
processor.New(
7676
simple.NewWithExactDistribution(),
7777
exp,
7878
),
7979
controller.WithCollectPeriod(7*time.Second),
80+
controller.WithPusher(exp),
8081
)
8182

8283
// set global propagator to tracecontext (the default is no-op).
8384
otel.SetTextMapPropagator(propagation.TraceContext{})
8485
otel.SetTracerProvider(tracerProvider)
85-
otel.SetMeterProvider(pusher.MeterProvider())
86-
pusher.Start(context.Background())
86+
otel.SetMeterProvider(cont.MeterProvider())
87+
cont.Start(context.Background())
8788

8889
return func() {
8990
handleErr(tracerProvider.Shutdown(ctx), "failed to shutdown provider")
90-
pusher.Stop(context.Background()) // pushes any last exports to the receiver
91+
cont.Stop(context.Background()) // pushes any last exports to the receiver
9192
handleErr(exp.Shutdown(ctx), "failed to stop exporter")
9293
}
9394
}

0 commit comments

Comments
 (0)