The Netra SDK exposes a meter API that lets you:
- Create custom metrics – Counters, histograms, gauges, and more
- Export to Netra backend – Using OpenTelemetry OTLP/HTTP JSON
This page shows how to use meter utility in Netra to define and record your own metrics.
Getting Started
The metrics pipeline is configured automatically when you enable metrics in Netra.init.
If enable_metrics is False or no OTLP endpoint is configured, Netra installs a no-op MeterProvider. Your code can still call get_meter and record metrics safely, they will simply be discarded.
get_meter
Return an OpenTelemetry Meter instance backed by Netra’s global MeterProvider.
Parameters
Creating Instruments
The returned Meter is a standard OpenTelemetry Meter and supports the usual instrument types.
Counter
Monotonically increasing value (e.g. request counts).
Up Down Counter
Value that can increase or decrease (e.g. active connections).
Histogram
Distribution of measurements (e.g. latency, payload size).
Observable Instruments (Advanced)
You can also create observable instruments (pull-based metrics), such as periodic gauges or counters, by registering callbacks.
Example for CPU and memory utilization gauges:
These callbacks are invoked periodically by the metrics reader configured by Netra.
Metrics Export Pipeline
Netra configures the metrics pipeline viaMetricsSetup(), which:
- Uses OTLP/HTTP JSON
Wraps the upstream OTLPMetricExporter to serialize metrics to JSON and send them
- Uses delta temporality for all instruments
Every export contains increments since the last export (delta), matching common observability platforms.
- Respects configuration
Uses app_name, environment, and optional resource_attributes from Netra.init as resource attributes on all metrics.
- Exports periodically
Uses metrics_export_interval_ms to control the export interval.
Complete Example
Next Steps
Last modified on March 27, 2026