What you will learn in this TP
- Create spans with the SDK
- Report errors, events and links
- Query with TraceQL and sample
Introduction #
What you will learn in this section
- Create spans with the SDK
- Report errors, events and links
- Query with TraceQL and sample
Context. The order service has no auto-instrumented library for its business logic. You instrument it by hand to see an order's steps, its payment errors and its batch processing.
Prerequisites: Docker and Python 3.10 or later; the grafana/otel-lgtm stack (Collector, Tempo, Loki, Prometheus, Pyroscope and Grafana in one container) · Estimated time: 50 min
Hands-on #
Guided steps, with their solution.
1. Start the observability stack
Why? A single image provides an OTLP Collector and every backend: focus on the signal.
Startgrafana/otel-lgtm, create a Python environment and point exporters to OTLP/HTTP port 4318.2. Initialise the SDK
Why? The TracerProvider holds the resource and exporter; the BatchSpanProcessor sends in batches.
Install the SDK and the OTLP/HTTP exporter, then writeotel_setup.pyconfiguring the resource (service.name,service.version,deployment.environment.name) and export.3. Create a business trace
Why? Spans named per step, with SpanKind and convention-compliant attributes, make the trace readable by every tool.
Writecommande.py: a root spantraiter commandeand three children (stock as CLIENT with database attributes, computation, payment), an event, and a payment error one time in three withrecord_exceptionand ERROR status.4. Explore and query with TraceQL
Why? TraceQL filters on span structure and attributes: one query finds the traces that matter.
In Grafana, open Explore > Tempo. Run the queries below, open a failed trace and find the event and exception of thepayerspan.5. Link a batch job with links
Why? A batch processing items from several traces cannot have several parents: use links.
Writelot.py: three independent "reception" traces, then afacturer lotspan linked to all three. Find the links in the span details.6. Sample
Why? Ratio sampling reduces volume; parentbased ensures a trace is kept or dropped as a whole.
Re-runcommande.pywith 20% sampling and compare the number of traces received; check no trace is partial. Explain why Collector tail sampling would be better to keep all errors.
Difficulty level : ●●●○○ (3/5)
My progress
Sign in to track your progress and take notes. Sign in
Recommended Articles
Les traces OpenTelemetry en profondeur : spans, statuts, événements, liens et échantillonnage
Maîtriser le signal trace : anatomie d'une trace distribuée, span et SpanKind, attributs, statut ...
Tracing distribué : la propagation du contexte (W3C Trace Context et baggage)
Comprendre et mettre en œuvre la propagation de contexte OpenTelemetry : en-tête traceparent, tra...
Understanding the concept of score
The concept of score allows Elasticsearch to rank your documents by relevance during a search.
Understanding the Elastic Common Schema (ECS)
As always in our consulting engagements, we recommend that companies harmonise and standardise: k...
License consumption types
Understand the evolution of billing in Dynatrace: the difference between the old licensing model ...
Grafana Alloy: The importance of Self-Monitoring
Discover why and how to configure Grafana Alloy so that it monitors itself, collecting its own lo...
Grafana Alloy: Understanding and exploiting the User Interface (UI)
Discover how to enable, secure, and use Grafana Alloy's built-in web interface to visualize your ...
Grafana Alloy: Introduction and Architecture
Discover the fundamental concepts of Grafana Alloy, the transition from the static Agent to Alloy...
Grafana Alloy: Syntax and Configuration (Alloy Language: River)
As part of a Grafana training or observability training, master the declarative syntax of Grafana...