RousselTMLEARNING

TP · OpenTelemetry: From Discovery to Expertise

Lab: OpenTelemetry logs correlated with traces and file collection

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

Structured logs correlated with traces, from both collection paths.

Hands-on #

Guided steps, with their solution.

  1. 1. Start the observability stack

    Why? A single image provides an OTLP Collector and every backend: focus on the signal.

    Start grafana/otel-lgtm, create a Python environment and point exporters to OTLP/HTTP port 4318.
  2. 2. Connect the logging module

    Why? The LoggingHandler turns each logging call into an OpenTelemetry LogRecord, with the active trace context.

    Write facturation.py: a LoggerProvider with OTLP exporter, a handler added to the root logger, a TracerProvider, and INFO and ERROR logs emitted inside spans.
  3. 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 spot trace_id, span_id, severity and your attributes. Open the linked trace, then from a Tempo span show its logs.
  4. 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, with filelog, json_parser, trace_parser and a resource processor setting service.name.
  5. 5. Reduce and mask

    Why? The Collector removes noise and personal data before storage.

    Add a filter processor dropping INFO logs and a transform masking e-mail addresses in the body, then check in Loki.

Difficulty level : ●●●○○ (3/5)

My progress

  • ⏱ Estimated time : ≈ 45 min

Sign in to track your progress and take notes. Sign in

💬 Recent discussions about this course

Ask a question about this lesson →See all discussions about this course

Recommended Articles

Logs with OpenTelemetry: data model, appenders, correlation and collection

Master the log signal: the LogRecord data model, the Logs Bridge API and appenders (Logback, Log4...

Correlating traces, metrics, logs and profiles with OpenTelemetry

Link the four signals to diagnose quickly: shared resource, trace_id in logs, exemplars on metric...

Ingesting OpenTelemetry logs into Elasticsearch

Collect and structure logs with the OpenTelemetry Collector (filelog receiver, operators, transfo...

Capstone project: the four signals of the OpenTelemetry Demo in the Grafana stack

A capstone project spanning the observability courses: deploy the OpenTelemetry Demo, send metric...

OpenTelemetry: automatic vs manual instrumentation

Understand the differences between automatic and manual instrumentation with OpenTelemetry, their...

Sending telemetry to ClickStack: OpenTelemetry SDKs, collectors, logs, Kubernetes and browser sessions

Feeding ClickStack: ingestion key, OpenTelemetry SDK variables, forwarding through an existing co...

Collecting logs into Loki: Alloy, Promtail, Docker and OpenTelemetry

Send logs to Loki: Grafana Alloy, Promtail, the Docker driver, OTLP, good labels, parsing and enr...

Profiles, OpenTelemetry's fourth signal: continuous profiling and correlation with traces

Understand OpenTelemetry's new profile signal: continuous profiling, flame graphs, data model and...

OpenTelemetry Collector: exporters (sending telemetry to backends)

Configure OpenTelemetry Collector exporters: OTLP gRPC/HTTP, Prometheus, prometheusremotewrite, L...

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!