From d9d9507227b30ad83500ec59e5714d0314ac83be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 31 Jan 2024 16:10:28 +0100 Subject: [PATCH] stdouttrace: Refine example (#4872) --- exporters/stdout/stdouttrace/example_test.go | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/exporters/stdout/stdouttrace/example_test.go b/exporters/stdout/stdouttrace/example_test.go index 33164852343..e769aad58ab 100644 --- a/exporters/stdout/stdouttrace/example_test.go +++ b/exporters/stdout/stdouttrace/example_test.go @@ -38,20 +38,18 @@ var tracer = otel.GetTracerProvider().Tracer( trace.WithSchemaURL(semconv.SchemaURL), ) -func add(ctx context.Context, x, y int64) (context.Context, int64) { - var span trace.Span - ctx, span = tracer.Start(ctx, "Addition") +func add(ctx context.Context, x, y int64) int64 { + _, span := tracer.Start(ctx, "Addition") defer span.End() - return ctx, x + y + return x + y } -func multiply(ctx context.Context, x, y int64) (context.Context, int64) { - var span trace.Span - ctx, span = tracer.Start(ctx, "Multiplication") +func multiply(ctx context.Context, x, y int64) int64 { + _, span := tracer.Start(ctx, "Multiplication") defer span.End() - return ctx, x * y + return x * y } func Resource() *resource.Resource { @@ -91,8 +89,10 @@ func Example() { } }() - ctx, ans := multiply(ctx, 2, 2) - ctx, ans = multiply(ctx, ans, 10) - ctx, ans = add(ctx, ans, 2) + ctx, span := tracer.Start(ctx, "Calculation") + defer span.End() + ans := multiply(ctx, 2, 2) + ans = multiply(ctx, ans, 10) + ans = add(ctx, ans, 2) log.Println("the answer is", ans) }