From 3002a046ed7546f47d9727c21acba3eccb5445dd Mon Sep 17 00:00:00 2001 From: alrex Date: Tue, 13 Oct 2020 21:54:26 -0700 Subject: [PATCH] Use BatchSpanProcessor instead of SimpleSpanProcessor (#24) As reported by @milanaleksic, the launcher was configured to use the SimpleSpanProcessor which was affecting application performance. This change updates the launcher to configure the BatchSpanProcessor by default. --- launcher/config.go | 4 +++- launcher/config_test.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/launcher/config.go b/launcher/config.go index e84041af..d3dbef5e 100644 --- a/launcher/config.go +++ b/launcher/config.go @@ -361,9 +361,10 @@ func setupTracing(c Config) (func() error, error) { return nil, fmt.Errorf("failed to create span exporter: %v", err) } + bsp := trace.NewBatchSpanProcessor(spanExporter) tp := trace.NewTracerProvider( trace.WithConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}), - trace.WithSyncer(spanExporter), + trace.WithSpanProcessor(bsp), trace.WithResource(c.Resource), ) @@ -374,6 +375,7 @@ func setupTracing(c Config) (func() error, error) { global.SetTracerProvider(tp) return func() error { + bsp.Shutdown() return spanExporter.Shutdown(context.Background()) }, nil } diff --git a/launcher/config_test.go b/launcher/config_test.go index 0514bb19..bdce8b64 100644 --- a/launcher/config_test.go +++ b/launcher/config_test.go @@ -449,7 +449,8 @@ func TestConfigurePropagators(t *testing.T) { prop = global.TextMapPropagator() prop.Inject(ctx, carrier) assert.Greater(t, len(carrier.Get("x-b3-traceid")), 0) - assert.Equal(t, "keyone=foo1,keytwo=bar1", carrier.Get("otcorrelations")) + assert.Contains(t, carrier.Get("otcorrelations"), "keytwo=bar1") + assert.Contains(t, carrier.Get("otcorrelations"), "keyone=foo1") logger = &testLogger{} lsOtel = ConfigureOpentelemetry(