OpenTelemetry Hands-On Guide: Mastering Observability with Practical Examples

Listen to this Post

Featured Image
Check out this week’s o11y newsletter with excellent OpenTelemetry hands-on material:
🔗 OpenTelemetry Observability Newsletter

You Should Know:

1. Setting Up OpenTelemetry Collector

To collect telemetry data (metrics, logs, traces), deploy the OpenTelemetry Collector:

 Download OpenTelemetry Collector 
wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.60.0/otelcol_0.60.0_linux_amd64.tar.gz 
tar -xvf otelcol_0.60.0_linux_amd64.tar.gz 
./otelcol --config=config.yaml 

Example `config.yaml`:

receivers: 
otlp: 
protocols: 
grpc: 
http: 
exporters: 
logging: 
loglevel: debug 
service: 
pipelines: 
traces: 
receivers: [bash] 
exporters: [bash] 

2. Instrumenting a Python App with OpenTelemetry

Install the required packages:

pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp 

Sample Python code:

from opentelemetry import trace 
from opentelemetry.sdk.trace import TracerProvider 
from opentelemetry.sdk.trace.export import BatchSpanProcessor 
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter

trace.set_tracer_provider(TracerProvider()) 
tracer = trace.get_tracer(<strong>name</strong>) 
otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317", insecure=True) 
span_processor = BatchSpanProcessor(otlp_exporter) 
trace.get_tracer_provider().add_span_processor(span_processor)

with tracer.start_as_current_span("hello-world"): 
print("Hello, OpenTelemetry!") 

3. Querying Traces with Jaeger

Deploy Jaeger for visualization:

docker run -d --name jaeger \ 
-e COLLECTOR_OTLP_ENABLED=true \ 
-p 16686:16686 \ 
-p 4317:4317 \ 
jaegertracing/all-in-one:latest 

Access Jaeger UI at `http://localhost:16686`.

4. Monitoring Metrics with Prometheus

Configure OpenTelemetry to export metrics to Prometheus:

exporters: 
prometheus: 
endpoint: "0.0.0.0:8889" 

Start Prometheus:

docker run -d --name prometheus -p 9090:9090 \ 
-v prometheus.yml:/etc/prometheus/prometheus.yml \ 
prom/prometheus 

What Undercode Say:

OpenTelemetry is revolutionizing observability by providing a unified standard for logs, metrics, and traces. Key takeaways:
– Use OTLP for efficient data export.
– Leverage auto-instrumentation for minimal code changes.
– Combine Jaeger + Prometheus + Grafana for full-stack monitoring.

Expected Output:

✔ Traces visible in Jaeger UI

✔ Metrics scraped by Prometheus

✔ Logs centralized via FluentBit/ELK

Prediction:

OpenTelemetry will dominate cloud-native observability, replacing proprietary agents like Datadog and New Relic in cost-sensitive environments.

🔗 Further Reading:

References:

Reported By: Mhausenblas Observability – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 Telegram