Jaeger Setup
Integrating OpenTelemetry with Jaeger for Distributed Tracing¶
Distributed tracing with Jaeger and OpenTelemetry enables end-to-end visibility into microservices, allowing you to monitor latency, debug issues, and optimize performance. This guide walks you through setting up Jaeger as a backend for OpenTelemetry, including configuration steps, code examples, and integration patterns.
1. Installing and Configuring Jaeger¶
Jaeger can be deployed via Docker, binaries, or cloud services. For local development, use Docker to run the Jaeger collector and query service:
docker run -d -p 16686:16686 -p 14250:14250 -p 14268:14268 -p 14251:14251 -p 14269:14269 jaegertracing/all-in-one:1.42
This command starts Jaeger with:
- UI: Accessible at http://localhost:16686
- Agent: Receives traces via gRPC or HTTP on ports 14250/14317 and 14268/14317
For production, configure Jaeger with persistent storage (e.g., Cassandra, PostgreSQL) and scale the collector cluster.
2. Configuring OpenTelemetry Collector to Send Traces to Jaeger¶
The OpenTelemetry Collector acts as a bridge between your application and Jaeger. Configure it to export traces to Jaeger using the jaeger exporter:
Example otelcol-contrib.yaml configuration:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
exporters:
jaeger:
endpoint: http://jaeger-agent:14268
headers:
"jaeger-version": "1.42"
service:
pipelines:
traces:
receivers: [otlp]
exporters: [jaeger]
Replace jaeger-agent with the actual hostname or IP of your Jaeger instance. Ensure the Collector and Jaeger are on the same network or use appropriate DNS resolution.
3. Instrumenting Your Application with OpenTelemetry¶
Add OpenTelemetry SDKs to your application to generate traces. Below is a Go example using the OpenTelemetry SDK:
package main
import (
"context"
"log"
"net/http"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)
var tracer = otel.Tracer("example.com/my-service")
func main() {
// Initialize the OTel SDK
exporter, err := otlpgrpc.NewExporter(
otlpgrpc.WithEndpoint("http://jaeger-agent:14268"),
otlpgrpc.WithHeaders(map[string]string{"jaeger-version": "1.42"}),
)
if err != nil {
log.Fatalf("failed to create exporter: %v", err)
}
tp := trace.NewTracerProvider(trace.WithBatcher(exporter))
defer tp.Shutdown(context.Background())
// Set the global TracerProvider
trace.SetTracerProvider(tp)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
ctx, span := tracer.Start(r.Context(), "http-handler")
defer span.End()
log.Println("Request received")
w.Write([]byte("Hello, OpenTelemetry!"))
})
http.ListenAndServe(":8080", nil)
}
For Java, Python, or other languages, refer to the OpenTelemetry documentation for SDK setup.
4. Viewing Traces in Jaeger UI¶
After sending traces, access the Jaeger UI at http://localhost:16686 (if using Docker). Use the following steps:
1. Navigate to Find Services and select your service name.
2. Click a trace to view spans, timing, and annotations.
3. Use the Trace Graph to visualize service dependencies.
Diagram: OpenTelemetry-Jaeger Architecture
5. Advanced Configuration Tips¶
- Sampling: Adjust sampling rates in the Jaeger exporter to balance data volume and observability.
- Authentication: Use TLS or authentication tokens if Jaeger requires secure access.
- Customization: Modify the Jaeger exporter’s
endpointandheadersto match your deployment.
Key takeaways¶
- Use Docker or cloud services to deploy Jaeger and ensure it’s accessible to the OpenTelemetry Collector.
- Configure the OpenTelemetry Collector to export traces to Jaeger using the
jaegerexporter. - Instrument your application with OpenTelemetry SDKs to generate and send traces.
- Monitor traces via the Jaeger UI to debug latency, dependencies, and errors.
- Customize sampling, authentication, and exporter settings based on your deployment needs.