diff --git a/exporters/stdout/stdouttrace/example_test.go b/exporters/stdout/stdouttrace/example_test.go index fd5425c830e..33164852343 100644 --- a/exporters/stdout/stdouttrace/example_test.go +++ b/exporters/stdout/stdouttrace/example_test.go @@ -38,20 +38,20 @@ var tracer = otel.GetTracerProvider().Tracer( trace.WithSchemaURL(semconv.SchemaURL), ) -func add(ctx context.Context, x, y int64) int64 { +func add(ctx context.Context, x, y int64) (context.Context, int64) { var span trace.Span - _, span = tracer.Start(ctx, "Addition") + ctx, span = tracer.Start(ctx, "Addition") defer span.End() - return x + y + return ctx, x + y } -func multiply(ctx context.Context, x, y int64) int64 { +func multiply(ctx context.Context, x, y int64) (context.Context, int64) { var span trace.Span - _, span = tracer.Start(ctx, "Multiplication") + ctx, span = tracer.Start(ctx, "Multiplication") defer span.End() - return x * y + return ctx, x * y } func Resource() *resource.Resource { @@ -62,7 +62,7 @@ func Resource() *resource.Resource { ) } -func InstallExportPipeline(ctx context.Context) (func(context.Context) error, error) { +func InstallExportPipeline() (func(context.Context) error, error) { exporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint()) if err != nil { return nil, fmt.Errorf("creating stdout exporter: %w", err) @@ -81,7 +81,7 @@ func Example() { ctx := context.Background() // Registers a tracer Provider globally. - shutdown, err := InstallExportPipeline(ctx) + shutdown, err := InstallExportPipeline() if err != nil { log.Fatal(err) } @@ -91,5 +91,8 @@ func Example() { } }() - log.Println("the answer is", add(ctx, multiply(ctx, multiply(ctx, 2, 2), 10), 2)) + ctx, ans := multiply(ctx, 2, 2) + ctx, ans = multiply(ctx, ans, 10) + ctx, ans = add(ctx, ans, 2) + log.Println("the answer is", ans) }