You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
stdouttrace: Refine example (#4872)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user