From e8cc01583eff5bb70e54f75e1d8d1dc3e9801efa Mon Sep 17 00:00:00 2001 From: Tigran Najaryan <4194920+tigrannajaryan@users.noreply.github.com> Date: Wed, 20 Jan 2021 12:00:29 -0500 Subject: [PATCH] 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. --- examples/demo/app/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/demo/app/main.go b/examples/demo/app/main.go index 18cc7be86ac..189c255fbef 100644 --- a/examples/demo/app/main.go +++ b/examples/demo/app/main.go @@ -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") } }