Watchlog DocsWatchlog Docs
Home
Get Started
Home
Get Started
  • Watchlog
    • Get Started
    • Custom Events
    • APM
    • Kubernetes Cluster Monitoring

Application Performance Monitoring (APM)

Access the APM dashboard at https://app.watchlog.io/apm to view your applications and performance metrics.


Express Icon Node.js

Installation

npm install @watchlog/apm

Usage

// index.js — must be first
const { instrument } = require('@watchlog/apm');

// Initialize with your service name and options
const sdk = instrument({
  app: 'my-service',          // your application name
  errorTPS: 5,                // max 5 error spans/sec
  sendErrorTraces: true,      // always send error spans
  slowThresholdMs: 300,       // always send spans slower than 300ms
  sampleRate: 1               // random sample rate (0.0–1.0, capped at 0.3)
});

// Continue loading your application
const express = require('express');
const app = express();

app.get('/', (req, res) => res.send('Hello World!'));
app.listen(3000, () => console.log('Listening on 3000'));

Flask Icon Flask

Installation

pip install flask-watchlog-apm

Usage

# main.py
from flask import Flask
from flask_watchlog_apm.instrument import instrument_app

app = Flask(__name__)

# 1) Initialize Watchlog APM
instrument_app(
    app,
    service_name="my-flask-service",   # your service name
    headers={"Authorization": "Bearer <token>"},
    sample_rate=0.5,                   # random sample rate (0.0–1.0, capped at 0.3)
    send_error_spans=True,             # always export error spans
    error_tps=10,                      # max 10 error spans per second
    slow_threshold_ms=100              # always export spans >100ms
)

# 2) Define your routes
@app.route("/")
def hello():
    return "Hello, Watchlog APM!"

# 3) Run your app
if __name__ == "__main__":
    app.run(host="0.0.0.0", port=6000, debug=True)

Django Icon Django

Installation

pip install django-watchlog-apm

Usage

# wsgi.py (or asgi.py)
import os
from django.core.wsgi import get_wsgi_application  # or get_asgi_application

# 1) Instrumentation before Django setup
from django_watchlog_apm.instrument import instrument_django

instrument_django(
    service_name="my-django-app",       # your service name
    sample_rate=0.5,                    # random sample rate (0.0–1.0, capped at 0.3)
    send_error_spans=True,              # always export error spans
    error_tps=5,                        # max 5 error spans per second
    slow_threshold_ms=200,              # always export spans >200ms
    export_timeout=10.0                 # HTTP timeout for exporter
)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()  # or get_asgi_application()

FastAPI Icon FastAPI

Installation

pip install fastapi-apm-watchlog

Usage

# main.py
from fastapi import FastAPI
from fastapi_apm_watchlog import instrument

app = FastAPI()

# 1) Initialize Watchlog APM
instrument(
    app,
    service_name='my-fastapi-app',  # your service name
    error_tps=5,                    # max 5 error spans/sec
    sendErrorTraces=True,           # always send error spans
    slowThresholdMs=300,            # always send spans >300ms
    sampleRate=1.0                  # random sample rate (0.0–1.0, capped at 0.3)
)

# 2) Define your routes
@app.get('/')
async def read_root():
    return {'message': 'Hello, Watchlog APM + FastAPI'}

# 3) Run your app
# uvicorn main:app --reload
Last Updated:: 7/30/25, 8:18 PM
Contributors: mohammad
Prev
Custom Events
Next
Kubernetes Cluster Monitoring