Required dependencies

Add the following dependencies to your project by running:

go get go.opentelemetry.io/otel \
  go.opentelemetry.io/otel/trace

Creating Spans

To create a span, you need to get a Tracer and use it to start a new span. The following example demonstrates how to create a span using the OpenTelemetry Go API.

package main

import (
    "context"
    "go.opentelemetry.io/otel"
)

var tracer = otel.Tracer("trace-example")

func my_function(ctx context.Context) {
    _, span := tracer.Start(ctx, "my_function")
    // Do some work
    defer span.End()
}

Additional information

For more use cases, see the OpenTelemetry Go API documentation.