What you will learn in this TP
- Connect an existing logger to OpenTelemetry
- Correlate logs and traces
- Collect files with filelog
Introduction #
What you will learn in this section
- Connect an existing logger to OpenTelemetry
- Correlate logs and traces
- Collect files with filelog
Context. Billing logs are text files nobody links to traces. You connect the modern service to OpenTelemetry and collect the legacy application's logs without changing it.
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: 45 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. Connect the logging module
Why? The LoggingHandler turns each logging call into an OpenTelemetry LogRecord, with the active trace context.
Writefacturation.py: a LoggerProvider with OTLP exporter, a handler added to the root logger, a TracerProvider, and INFO and ERROR logs emitted inside spans.3. Query and correlate in Grafana
Why? The trace_id carried by each log lets you jump from the log to the trace and back.
In Explore > Loki, show the service's errors, expand a line and spottrace_id,span_id, severity and your attributes. Open the linked trace, then from a Tempo span show its logs.4. Collect a legacy application's logs
Why? Without touching code, the filelog receiver reads files and parses JSON, severity and trace context.
Generate a JSON log file, then run a contrib Collector on the same network as the stack, withfilelog,json_parser,trace_parserand aresourceprocessor settingservice.name.5. Reduce and mask
Why? The Collector removes noise and personal data before storage.
Add afilterprocessor dropping INFO logs and atransformmasking e-mail addresses in the body, then check in Loki.
Difficulty level : ●●●○○ (3/5)
My progress
Sign in to track your progress and take notes. Sign in
Recommended Articles
Grafana Alloy: Log Management with Loki
Discover how to configure Grafana Alloy to read log files, journald, or network streams, process ...
Grafana Alloy: Trace Management with Tempo
Dive into distributed trace processing. Learn how to ingest OTLP, Jaeger, or Zipkin traces with G...
Grafana Alloy: Continuous Profiling with Pyroscope
Discover how to configure continuous profiling in your environments using Grafana Alloy and Pyros...
Grafana Alloy: Advanced Deployment and Clustering
Learn how to manage large-scale Grafana Alloy deployments. Configure Clustering mode for high ava...
Grafana Assistant: AI at the service of observability
Discover Grafana Assistant, the artificial intelligence integrated into Grafana Cloud. Learn how ...
Grafana Alloy vs OpenTelemetry Collector: Which One Should You Choose?
A detailed comparison between Grafana Alloy and the OpenTelemetry Collector. Discover the strengt...
Grafana Alloy vs Dynatrace ActiveGate: Which to choose?
Comparison between Grafana Alloy and Dynatrace ActiveGate. Understand the fundamental differences...
Application Protection
Learn how to secure your backends against abuse and common attacks. A practical guide to Rate Lim...