RousselTMLEARNING

Observability

Instrumenting applications for Jaeger with OpenTelemetry

Send traces to Jaeger with OpenTelemetry: auto-instrumentation (Java, Python, Node.js), SDK and manual spans, environment variables, attributes, propagation and the HotROD demo application.

1. Environment variables #

Configuration common to all languages.

OTEL variables #

VariableExample
OTEL_SERVICE_NAMEcommandes
OTEL_EXPORTER_OTLP_ENDPOINThttp://jaeger:4318
OTEL_EXPORTER_OTLP_PROTOCOLhttp/protobuf or grpc
OTEL_RESOURCE_ATTRIBUTESdeployment.environment=production,service.version=2.4.1
OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARGparentbased_traceidratio, 0.1
OTEL_PROPAGATORStracecontext,baggage
Good practice: Jaeger receives OTLP natively: no Jaeger-specific library is needed. The same code can send to Jaeger, Tempo, Elastic or SigNoz by changing a variable.

2. Auto-instrumentation #

Traces without changing the code.

Java #

curl -LO https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
OTEL_SERVICE_NAME=commandes OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318 \
  java -javaagent:opentelemetry-javaagent.jar -jar commandes.jar

Python #

pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install          # installe les instrumentations des bibliothèques présentes
OTEL_SERVICE_NAME=stock OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318 \
  opentelemetry-instrument python app.py

Node.js #

npm install @opentelemetry/auto-instrumentations-node
OTEL_SERVICE_NAME=front OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318 \
  node --require @opentelemetry/auto-instrumentations-node/register server.js

3. Manual spans #

Adding business context.

Python #

from opentelemetry import trace

tracer = trace.get_tracer("stock")

def reserver(produit_id, quantite):
    with tracer.start_as_current_span("reserver_stock") as span:
        span.set_attribute("produit.id", produit_id)
        span.set_attribute("stock.quantite", quantite)
        try:
            ...
        except RuptureDeStock as e:
            span.record_exception(e)
            span.set_status(trace.Status(trace.StatusCode.ERROR, "rupture"))
            raise
Common mistake: Do not add personal data (email, name) to attributes: traces are often kept and widely viewed.

The HotROD application #

HotROD (« Rides on Demand ») is Jaeger's demo application: four simulated microservices, realistic latencies and errors, problems to diagnose. It is ideal for learning to read traces.

docker run --rm -p 8080:8080 -e OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318 jaegertracing/example-hotrod:latest all

Related articles

Distributed tracing with Jaeger: concepts and architecture

The concepts of distributed tracing (trace, span, context, propagation) and Jaeger: its history, its v2 archi…

Installing Jaeger v2: all-in-one, configuration and storage

Run Jaeger v2 as all-in-one, understand its configuration file (jaeger_storage and jaeger_query extensions, O…

Analyzing traces in the Jaeger interface

Search for traces, read a timeline, spot the critical path, compare two traces, use the dependency graph and …

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!