Python Metrics

Learn how to setup metrics in your Python application.

Setup

Open the Vigilant dashboard and generate an API key.

Install

Install the Vigilant SDK in your Python application.

pip install vigilant-py

Initialize

Initialize the Vigilant SDK in your Python application. Vigilant automatically captures print statements.

from vigilant import init_vigilant

init_vigilant(
  name="backend",
  token="tk_1234567890" # Use your API key from the dashboard
)

Metrics Functions

The Vigilant SDK provides several functions to emit metrics.

from vigilant import metric_counter, metric_gauge, metric_histogram, GaugeMode

def function():
  # Create a counter metric
  metric_counter("user_login_count", 1)

  # Create a counter metric with a tag
  metric_counter("user_login_count", 1, {"route": "/"})

  # Create a gauge metric
  metric_gauge("active_users", 1, GaugeMode.SET)

  # Create a gauge metric with a tag
  metric_gauge("active_users", 1, GaugeMode.SET, {"route": "/"})

  # Create a histogram metric
  metric_histogram("request_duration", 123.4)

  # Create a histogram metric with a tag
  metric_histogram("request_duration", 123.4, {"route": "/"})

Optional Setup

The Vigilant SDK exposes a few setup options when you initialize it.

from vigilant import init_vigilant

init_vigilant(
  # Disable all functionality
  noop=True,

  # Disable automatic capture of logs, only direct logs are captured
  autocapture=False,

  # Disable logging to the console
  passthrough=False,
)