Skip to main content

Lightweight, framework-agnostic Python library for sending metrics to Datadog, SumoLogic, or Console. Lambda/Zappa-ready with live config support.

Project description

ddog-monitoring

A lightweight, framework-agnostic Python library for sending metrics to Datadog, SumoLogic, or a local Console output. Designed for use in Django, FastAPI, or any Python app — including AWS Lambda / Zappa deployments.

Installation

pip install ddog-monitoring

Quick Start

from monitoring.client import MonitoringFacade
from monitoring.config import MonitoringConfig

# Configure once at startup
MonitoringFacade.configure(MonitoringConfig(
    provider="datadog",
    datadog_api_key="your-api-key",
    datadog_app_key="your-app-key",
    datadog_hostname="your-host",
))

# Use anywhere
provider = MonitoringFacade.get_instance()
provider.send("api.request", value=1, metric_type="count", tags=["env:prod"])

Providers

Provider Config keys required
console (none) — prints metrics to stdout
datadog datadog_api_key, datadog_app_key, datadog_hostname
sumologic sumologic_url

Django + AWS Lambda / Zappa Usage

For Django apps, call configure() once in AppConfig.ready(). Pass a callable factory (lambda) instead of a static config so that django-constance value changes are picked up automatically on warm Lambda starts — without a redeploy.

# main_app/apps.py
from django.apps import AppConfig

class MainAppConfig(AppConfig):
    name = "main_app"

    def ready(self):
        from constance import config
        from monitoring.client import MonitoringFacade
        from monitoring.config import MonitoringConfig

        MonitoringFacade.configure(lambda: MonitoringConfig(
            provider=config.MONITORING_PROVIDER,
            datadog_api_key=config.DATADOG_API_KEY,
            datadog_app_key=config.DATADOG_APP_KEY,
            datadog_hostname=config.DATADOG_HOSTNAME,
            sumologic_url=config.SUMOLOGIC_URL,
        ))

Create a thin accessor module so views, management commands, and middleware never import MonitoringFacade directly:

# main_app/monitor.py
from monitoring.client import MonitoringFacade

def get_monitor():
    return MonitoringFacade.get_instance()
# views.py
from .monitor import get_monitor

def my_view(request):
    get_monitor().send("api.hit", value=1, metric_type="count", tags=["endpoint:my_view"])

How warm-start caching works

On every get_instance() call the library fetches the current config (via your factory) and compares it using Pydantic field equality. The provider is only recreated when config actually changes — otherwise the cached instance is reused immediately, keeping warm starts fast.

Decorators

Track function execution time and errors automatically:

from monitoring.decorators import track_metric

@track_metric("my_function")
def my_function():
    ...

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ddog_monitoring-0.6.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ddog_monitoring-0.6.0-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file ddog_monitoring-0.6.0.tar.gz.

File metadata

  • Download URL: ddog_monitoring-0.6.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for ddog_monitoring-0.6.0.tar.gz
Algorithm Hash digest
SHA256 0625410ee3b6a50a8ce0c83825f2095fa58768f0814790b476623d2929d45d0e
MD5 2eab6990bb43460ff546169dce9198be
BLAKE2b-256 f0e6ad5ce087d109f50a7ec9ce18c0c72a2a9e5e25fce9fed1e54ed8bbda4adc

See more details on using hashes here.

File details

Details for the file ddog_monitoring-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ddog_monitoring-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8e0cbe7056398f7a5f1d72d482c7d0b22f6804dc59e60344d719506edb284ff
MD5 1b515dfdf196bff2d0877dccfd316619
BLAKE2b-256 baa5695c774b016547c5ab19c7eeac1e7f7eb131b282c9d8af341a4995f7ba54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page