From b09df84a24b35cb5f287a501e31d9dec324be5a9 Mon Sep 17 00:00:00 2001 From: Aaron Clawson Date: Wed, 14 Apr 2021 10:51:41 -0500 Subject: [PATCH] Changes stdout to expose the `*sdktrace.TracerProvider` (#1800) * Changes stdout to expose the actual tracerProvider This enables flushing and stopping the exporter. * updated changelog * Update CHANGELOG.md Co-authored-by: Tyler Yahn Co-authored-by: Tyler Yahn --- CHANGELOG.md | 1 + exporters/stdout/example_test.go | 5 ++++- exporters/stdout/exporter.go | 13 ++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5008d9bcfad..29a7a7fb560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Make `ExportSpans` in Jaeger Exporter honor context deadline. (#1773) - The `go.opentelemetry.io/otel/sdk/export/trace` package is merged into the `go.opentelemetry.io/otel/sdk/trace` package. (#1778) - The prometheus.InstallNewPipeline example is moved from comment to example test (#1796) +- Convenience functions for stdout exporter have been updated to return the `TracerProvider` implementation and enable the shutdown of the exporter. (#1800) ### Removed diff --git a/exporters/stdout/example_test.go b/exporters/stdout/example_test.go index fc41dafa264..82da5665bf9 100644 --- a/exporters/stdout/example_test.go +++ b/exporters/stdout/example_test.go @@ -81,7 +81,7 @@ func Example() { stdout.WithPrettyPrint(), } // Registers both a trace and meter Provider globally. - pusher, err := stdout.InstallNewPipeline(exportOpts, nil) + tracerProvider, pusher, err := stdout.InstallNewPipeline(exportOpts, nil) if err != nil { log.Fatal("Could not initialize stdout exporter:", err) } @@ -92,4 +92,7 @@ func Example() { if err := pusher.Stop(ctx); err != nil { log.Fatal("Could not stop stdout exporter:", err) } + if err := tracerProvider.Shutdown(ctx); err != nil { + log.Fatal("Could not stop stdout tracer:", err) + } } diff --git a/exporters/stdout/exporter.go b/exporters/stdout/exporter.go index 192256d3206..88b0b9ad9e5 100644 --- a/exporters/stdout/exporter.go +++ b/exporters/stdout/exporter.go @@ -24,7 +24,6 @@ import ( processor "go.opentelemetry.io/otel/sdk/metric/processor/basic" "go.opentelemetry.io/otel/sdk/metric/selector/simple" sdktrace "go.opentelemetry.io/otel/sdk/trace" - "go.opentelemetry.io/otel/trace" ) type Exporter struct { @@ -51,8 +50,8 @@ func NewExporter(options ...Option) (*Exporter, error) { // NewExportPipeline creates a complete export pipeline with the default // selectors, processors, and trace registration. It is the responsibility -// of the caller to stop the returned push Controller. -func NewExportPipeline(exportOpts []Option, pushOpts []controller.Option) (trace.TracerProvider, *controller.Controller, error) { +// of the caller to stop the returned tracer provider and push Controller. +func NewExportPipeline(exportOpts []Option, pushOpts []controller.Option) (*sdktrace.TracerProvider, *controller.Controller, error) { exporter, err := NewExporter(exportOpts...) if err != nil { return nil, nil, err @@ -76,7 +75,7 @@ func NewExportPipeline(exportOpts []Option, pushOpts []controller.Option) (trace // InstallNewPipeline creates a complete export pipelines with defaults and // registers it globally. It is the responsibility of the caller to stop the -// returned push Controller. +// returned tracer provider and push Controller. // // Typically this is called as: // @@ -86,12 +85,12 @@ func NewExportPipeline(exportOpts []Option, pushOpts []controller.Option) (trace // } // defer pipeline.Stop() // ... Done -func InstallNewPipeline(exportOpts []Option, pushOpts []controller.Option) (*controller.Controller, error) { +func InstallNewPipeline(exportOpts []Option, pushOpts []controller.Option) (*sdktrace.TracerProvider, *controller.Controller, error) { tracerProvider, controller, err := NewExportPipeline(exportOpts, pushOpts) if err != nil { - return controller, err + return tracerProvider, controller, err } otel.SetTracerProvider(tracerProvider) global.SetMeterProvider(controller.MeterProvider()) - return controller, err + return tracerProvider, controller, err }