1. Environment variables #
Configuration common to all languages.
OTEL variables #
| Variable | Example |
|---|---|
OTEL_SERVICE_NAME | commandes |
OTEL_EXPORTER_OTLP_ENDPOINT | http://jaeger:4318 |
OTEL_EXPORTER_OTLP_PROTOCOL | http/protobuf or grpc |
OTEL_RESOURCE_ATTRIBUTES | deployment.environment=production,service.version=2.4.1 |
OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG | parentbased_traceidratio, 0.1 |
OTEL_PROPAGATORS | tracecontext,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.jarPython #
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.pyNode.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.js3. 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"))
raiseCommon 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