Use the OpenTelemetry Go SDK to instrument your application and send traces to a Jaeger collector. Install the SDK, configure the tracer provider with a Jaeger exporter, and wrap your business logic in spans.
import (
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/sdk/trace"
)
func initTracer() {
exporter, _ := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint("http://localhost:14268/api/traces")))
tp := trace.NewTracerProvider(trace.WithSyncer(exporter))
otel.SetTracerProvider(tp)
}
- Initialize the tracer provider in your
mainfunction before starting your application logic. - Create a tracer instance using
otel.Tracer("your-service-name"). - Start a span for each operation using
tracer.Start(ctx, "operation-name"). - Call
span.End()when the operation completes to send the trace data.