Skip to content

Commit

Permalink
stdouttrace: Refine example (#4872)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Jan 31, 2024
1 parent bf1ae8c commit d9d9507
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions exporters/stdout/stdouttrace/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit d9d9507

Please sign in to comment.