1. Les variables d'environnement #
La configuration commune à tous les langages.
Variables OTEL #
| Variable | Exemple |
|---|---|
OTEL_SERVICE_NAME | commandes |
OTEL_EXPORTER_OTLP_ENDPOINT | http://jaeger:4318 |
OTEL_EXPORTER_OTLP_PROTOCOL | http/protobuf ou 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 |
Bonne Pratique : Jaeger reçoit l'OTLP nativement : aucune bibliothèque spécifique à Jaeger n'est nécessaire. Le même code peut envoyer à Jaeger, Tempo, Elastic ou SigNoz en changeant une variable.
2. Auto-instrumentation #
Des traces sans modifier le 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. Spans manuels #
Ajouter le contexte métier.
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"))
raiseErreur Courante : N'ajoutez pas de données personnelles (e-mail, nom) dans les attributs : les traces sont souvent conservées et consultées largement.
L'application HotROD #
HotROD (« Rides on Demand ») est l'application de démonstration de Jaeger : quatre microservices simulés, des latences et erreurs réalistes, des problèmes à diagnostiquer. Elle est idéale pour apprendre à lire des traces.
docker run --rm -p 8080:8080 -e OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318 jaegertracing/example-hotrod:latest all