mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-30 04:40:41 +02:00
ensure batch span processors are shutdown in examples (#1199)
This commit is contained in:
parent
1e72b51b31
commit
304d4cdffc
@ -77,6 +77,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
- Zipkin example no longer mentions `ParentSampler`, corrected to `ParentBased`. (#1171)
|
- Zipkin example no longer mentions `ParentSampler`, corrected to `ParentBased`. (#1171)
|
||||||
- Fix missing shutdown processor in otel-collector example. (#1186)
|
- Fix missing shutdown processor in otel-collector example. (#1186)
|
||||||
|
- Fix missing shutdown processor in basic and namedtracer examples. (#1197)
|
||||||
|
|
||||||
## [0.11.0] - 2020-08-24
|
## [0.11.0] - 2020-08-24
|
||||||
|
|
||||||
|
@ -11,4 +11,5 @@ replace (
|
|||||||
require (
|
require (
|
||||||
go.opentelemetry.io/otel v0.11.0
|
go.opentelemetry.io/otel v0.11.0
|
||||||
go.opentelemetry.io/otel/exporters/stdout v0.11.0
|
go.opentelemetry.io/otel/exporters/stdout v0.11.0
|
||||||
|
go.opentelemetry.io/otel/sdk v0.11.0
|
||||||
)
|
)
|
||||||
|
@ -24,6 +24,10 @@ import (
|
|||||||
"go.opentelemetry.io/otel/api/trace"
|
"go.opentelemetry.io/otel/api/trace"
|
||||||
"go.opentelemetry.io/otel/exporters/stdout"
|
"go.opentelemetry.io/otel/exporters/stdout"
|
||||||
"go.opentelemetry.io/otel/label"
|
"go.opentelemetry.io/otel/label"
|
||||||
|
"go.opentelemetry.io/otel/sdk/metric/controller/push"
|
||||||
|
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||||
|
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
||||||
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -34,14 +38,28 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
pusher, err := stdout.InstallNewPipeline([]stdout.Option{
|
exporter, err := stdout.NewExporter([]stdout.Option{
|
||||||
stdout.WithQuantiles([]float64{0.5, 0.9, 0.99}),
|
stdout.WithQuantiles([]float64{0.5, 0.9, 0.99}),
|
||||||
stdout.WithPrettyPrint(),
|
stdout.WithPrettyPrint(),
|
||||||
}, nil)
|
}...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to initialize stdout export pipeline: %v", err)
|
log.Fatalf("failed to initialize stdout export pipeline: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bsp := sdktrace.NewBatchSpanProcessor(exporter)
|
||||||
|
defer bsp.Shutdown()
|
||||||
|
tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(bsp))
|
||||||
|
pusher := push.New(
|
||||||
|
basic.New(
|
||||||
|
simple.NewWithExactDistribution(),
|
||||||
|
exporter,
|
||||||
|
),
|
||||||
|
exporter,
|
||||||
|
)
|
||||||
|
pusher.Start()
|
||||||
defer pusher.Stop()
|
defer pusher.Stop()
|
||||||
|
global.SetTracerProvider(tp)
|
||||||
|
global.SetMeterProvider(pusher.MeterProvider())
|
||||||
|
|
||||||
tracer := global.Tracer("ex.com/basic")
|
tracer := global.Tracer("ex.com/basic")
|
||||||
meter := global.Meter("ex.com/basic")
|
meter := global.Meter("ex.com/basic")
|
||||||
|
@ -36,27 +36,30 @@ var (
|
|||||||
var tp *sdktrace.TracerProvider
|
var tp *sdktrace.TracerProvider
|
||||||
|
|
||||||
// initTracer creates and registers trace provider instance.
|
// initTracer creates and registers trace provider instance.
|
||||||
func initTracer() {
|
func initTracer() func() {
|
||||||
var err error
|
var err error
|
||||||
exp, err := stdout.NewExporter(stdout.WithPrettyPrint())
|
exp, err := stdout.NewExporter(stdout.WithPrettyPrint())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("failed to initialize stdout exporter %v\n", err)
|
log.Panicf("failed to initialize stdout exporter %v\n", err)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
bsp := sdktrace.NewBatchSpanProcessor(exp)
|
||||||
tp = sdktrace.NewTracerProvider(
|
tp = sdktrace.NewTracerProvider(
|
||||||
sdktrace.WithConfig(
|
sdktrace.WithConfig(
|
||||||
sdktrace.Config{
|
sdktrace.Config{
|
||||||
DefaultSampler: sdktrace.AlwaysSample(),
|
DefaultSampler: sdktrace.AlwaysSample(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
sdktrace.WithBatcher(exp),
|
sdktrace.WithSpanProcessor(bsp),
|
||||||
)
|
)
|
||||||
global.SetTracerProvider(tp)
|
global.SetTracerProvider(tp)
|
||||||
|
return bsp.Shutdown
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// initialize trace provider.
|
// initialize trace provider.
|
||||||
initTracer()
|
shutdown := initTracer()
|
||||||
|
defer shutdown()
|
||||||
|
|
||||||
// Create a named tracer with package path as its name.
|
// Create a named tracer with package path as its name.
|
||||||
tracer := tp.Tracer("example/namedtracer/main")
|
tracer := tp.Tracer("example/namedtracer/main")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user