OpenTelemetry Tracing
The framework automatically configures OpenTelemetry tracing.
Creating Spans
go
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
)
func processOrder(ctx context.Context, orderID string) error {
// Create new span
tracer := otel.Tracer("order-service")
ctx, span := tracer.Start(ctx, "processOrder")
defer span.End()
// Add attributes
span.SetAttributes(
attribute.String("order.id", orderID),
attribute.String("order.status", "processing"),
)
// Call other services
if err := validateOrder(ctx, orderID); err != nil {
span.RecordError(err)
return err
}
// Add event
span.AddEvent("order validated")
return nil
}Configuration
HTTP Export
bash
export BUTTERFLY_TRACING_PROVIDER=http
export BUTTERFLY_TRACING_ENDPOINT=localhost:4318gRPC Export
bash
export BUTTERFLY_TRACING_PROVIDER=grpc
export BUTTERFLY_TRACING_ENDPOINT=localhost:4317Disable Tracing
bash
export BUTTERFLY_TRACING_DISABLE=true