1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-12-01 23:12:29 +02:00

Unify trace and metric exporter helpers (#944)

* Adjust Jaeger and Zipkin exporters helper methods

* Update and add tests, examples, various minor improvements

* Update changelog

* Correct the Zipkin example

- wait for the spans to be exported
- rebuild the example

* Zipkin service name as argument

* Rework Jaeger and Zipkin tests

* Include more detailed Changelog

Co-authored-by: ET <evantorrie@users.noreply.github.com>
Co-authored-by: Liz Fong-Jones <lizf@honeycomb.io>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Matej Gera
2020-07-22 20:57:48 +02:00
committed by GitHub
parent c5d77d234c
commit f31d8ec1d0
9 changed files with 452 additions and 163 deletions

View File

@@ -30,7 +30,7 @@ import (
// initTracer creates a new trace provider instance and registers it as global trace provider.
func initTracer() func() {
// Create and install Jaeger export pipeline
_, flush, err := jaeger.NewExportPipeline(
flush, err := jaeger.InstallNewPipeline(
jaeger.WithCollectorEndpoint("http://localhost:14268/api/traces"),
jaeger.WithProcess(jaeger.Process{
ServiceName: "trace-demo",
@@ -39,7 +39,6 @@ func initTracer() func() {
kv.Float64("float", 312.23),
},
}),
jaeger.RegisterAsGlobal(),
jaeger.WithSDK(&sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
)
if err != nil {

View File

@@ -33,30 +33,20 @@ var logger = log.New(os.Stderr, "zipkin-example", log.Ldate|log.Ltime|log.Llongf
// initTracer creates a new trace provider instance and registers it as global trace provider.
func initTracer(url string) {
// Create Zipkin Exporter
exporter, err := zipkin.NewExporter(
url,
"zipkin-example",
zipkin.WithLogger(logger),
)
if err != nil {
log.Fatal(err)
}
// Create Zipkin Exporter and install it as a global tracer.
//
// For demoing purposes, always sample. In a production application, you should
// configure this to a trace.ProbabilitySampler set at the desired
// configure the sampler to a trace.ProbabilitySampler set at the desired
// probability.
tp, err := sdktrace.NewProvider(
sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
sdktrace.WithBatcher(exporter,
sdktrace.WithBatchTimeout(5),
sdktrace.WithMaxExportBatchSize(10),
),
err := zipkin.InstallNewPipeline(
url,
"zipkin-test",
zipkin.WithLogger(logger),
zipkin.WithSDK(&sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}),
)
if err != nil {
log.Fatal(err)
}
global.SetTraceProvider(tp)
}
func main() {
@@ -73,7 +63,9 @@ func main() {
bar(ctx)
<-time.After(6 * time.Millisecond)
span.End()
<-time.After(24 * time.Millisecond)
// Wait for the spans to be exported.
<-time.After(5 * time.Second)
}
func bar(ctx context.Context) {