Opentelemetry Python Instrumentation


Installation

Install OpenTelemetry SDK and OTLP exporter for autoinstrumentation of Python applications

pip install opentelemetry-distro opentelemetry-exporter-otlp

opentelemetry-bootstrap -a install

Starting the Application with OTEL

Environment variables to configure OpenTelemetry SDK for Python application

OTEL_SERVICE_NAME=application-name
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-opentelemetry-collector.istio-system.svc.cluster.local:4317

OTEL_TRACES_EXPORTER=otlp,console
OTEL_METRICS_EXPORTER=otlp

opentelemetry-instrument python myapp.py

Adding Span

...
from opentelemetry import trace
tracer = trace.get_tracer(__name__)

def ingest_metrics(metrics: list):
    with tracer.start_as_current_span("ingest_metrics"):
        logger.info("Ingesting Metrics")
        ...

...

Visualizing Traces

By sending opentelemetry data to a backend like Jaeger or Tempo, you can visualize the traces and spans




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • Don’t Repeat Yourself with YAML anchor
  • Monitor SNMP ด้วย CloudProxy-vROps
  • การสร้าง Root HTTPProxy บน Contour
  • Crontab but Kubernetes
  • Automate your Proxmox with Packer