Documentation

Metrics with OpenTelemetry

Overview

Lumigo provides the ability to integrate your metrics with OpenTelemetry's solution. OpenTelemetry's metrics consist of a protocl specification that allows you to deliver pre-sorted metric data, and is designed for importing / exporting metrics data from and into existing systems.

The OpenTelemetry protocol (OTLP) data model is composed of Metric data streams. These streams are in turn composed of metric data points. Metric data streams can be converted directly into Timeseries. For more on this, consult the OpenTelemetry documentation.

Most popular formats such as Prometheus are supported.

Getting Started

  1. Install the OpenTelemetry SDK and Metrics packages:
pip install opentelemetry-sdk opentelemetry-api opentelemetry-exporter-otlp
  1. Configure a meter and exporter. For example, if you wish to record and export a custom metric:
from opentelemetry import metrics
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import (
    PeriodicExportingMetricReader,
)
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter

# Set up OTLP exporter
otlp_exporter = OTLPMetricExporter(endpoint="http://localhost:4317", insecure=True)

# Create a periodic reader and meter provider
reader = PeriodicExportingMetricReader(otlp_exporter)
provider = MeterProvider(metric_readers=[reader])
metrics.set_meter_provider(provider)

# Create a meter
meter = metrics.get_meter("example-meter")

# Create a counter
counter = meter.create_counter(
    name="example_counter",
    description="A simple counter",
    unit="1"
)

# Record a value
counter.add(1, attributes={"env": "dev"})
  1. Run an OpenTelemetry Collector. You need a Collector running to receive any OTLP data. For a basic otel-collector-config-yaml example:
receivers:
  otlp:
    protocols:
      grpc:
      http:

exporters:
  logging:
    loglevel: debug
  prometheus:
    endpoint: "0.0.0.0:9464"

service:
  pipelines:
    metrics:
      receivers: [otlp]
      exporters: [logging, prometheus]
  1. Then, start the collector:
otelcol --config otel-collector-config.yaml

You should now be able to view metrics from your Collector.

OpenTelemetry Model Details

OpenTelemetry divides itself into three separate types of models:

  • An Event model, representing how instrumentation reports metric data.
  • A Timeseries model, representing how backends store metric data.
  • A Metric Stream model, which defines the OpenTeLemetry Protocol (OTLP) that represents how metric data streams are manipulated and transmitted between the previous two models.

Additional Information

You can consult OpenTelemetry's documentation about metrics with their solution for further details.