Skip to content

Commit

Permalink
chore: improve basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Apr 19, 2024
1 parent 49852d5 commit 62b18ff
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"

"github.com/uptrace/uptrace-go/uptrace"
)
Expand All @@ -29,13 +30,13 @@ func main() {
tracer := otel.Tracer("app_or_package_name")

// Create a root span (a trace) to measure some operation.
ctx, main := tracer.Start(ctx, "main-operation")
ctx, main := tracer.Start(ctx, "main-operation", trace.WithSpanKind(trace.SpanKindClient))
// End the span when the operation we are measuring is done.
defer main.End()

// The passed ctx carries the parent span (main).
// That is how OpenTelemetry manages span relations.
_, child1 := tracer.Start(ctx, "GET /posts/:id")
_, child1 := tracer.Start(ctx, "GET /posts/:id", trace.WithSpanKind(trace.SpanKindServer))
child1.SetAttributes(
attribute.String("http.method", "GET"),
attribute.String("http.route", "/posts/:id"),
Expand Down

0 comments on commit 62b18ff

Please sign in to comment.