diff --git a/internal/telemetry/bench_test.go b/internal/telemetry/bench_test.go index fe6fdf17f8..c3e5317a28 100644 --- a/internal/telemetry/bench_test.go +++ b/internal/telemetry/bench_test.go @@ -162,6 +162,33 @@ func BenchmarkLogging(b *testing.B) { } } } +func BenchmarkTracingNoExporter(b *testing.B) { + ctx := context.Background() + export.SetExporter(nil) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + for _, value := range values { + if g := A_trace(ctx, value); g <= 0 { + b.Fatalf("Unexpected got g(%d) <= 0", g) + } + } + } +} + +func BenchmarkTracing(b *testing.B) { + ctx := context.Background() + export.SetExporter(newExporter()) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + for _, value := range values { + if g := A_trace(ctx, value); g <= 0 { + b.Fatalf("Unexpected got g(%d) <= 0", g) + } + } + } +} func BenchmarkLoggingStdlib(b *testing.B) { ctx := context.Background() diff --git a/internal/telemetry/export/log.go b/internal/telemetry/export/log.go index d75e4f2654..752e686e8b 100644 --- a/internal/telemetry/export/log.go +++ b/internal/telemetry/export/log.go @@ -25,8 +25,21 @@ type logWriter struct { onlyErrors bool } -func (w *logWriter) StartSpan(context.Context, *telemetry.Span) {} -func (w *logWriter) FinishSpan(context.Context, *telemetry.Span) {} +func (w *logWriter) StartSpan(ctx context.Context, span *telemetry.Span) { + if w.onlyErrors { + return + } + fmt.Fprintf(w.writer, "start: %v %v", span.Name, span.ID) + if span.ParentID.IsValid() { + fmt.Fprintf(w.writer, "[%v]", span.ParentID) + } +} +func (w *logWriter) FinishSpan(ctx context.Context, span *telemetry.Span) { + if w.onlyErrors { + return + } + fmt.Fprintf(w.writer, "finish: %v %v", span.Name, span.ID) +} func (w *logWriter) ProcessEvent(ctx context.Context, event telemetry.Event) context.Context { if w.onlyErrors && event.Error == nil { return ctx