1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-04 09:43:23 +02:00

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 <MrAlias@users.noreply.github.com>

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Aaron Clawson 2021-04-14 10:51:41 -05:00 committed by GitHub
parent 0489060896
commit b09df84a24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -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)
}
}

View File

@ -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
}