Docs/Monitoring/APM Setup

APM Setup

Set up Application Performance Monitoring to track response times, throughput, and performance metrics across your applications.

Overview

QODRYX APM provides real-time visibility into your application's performance. Track request latency, database queries, external API calls, and identify performance bottlenecks before they impact users.

Response Time

P50, P95, P99 latencies

Throughput

Requests per minute

Traces

Distributed tracing

Installation

Install the QODRYX APM agent for your runtime:

Node.js

Terminal
npm install @qodryx/apm

Python

Terminal
pip install qodryx-apm

Configuration

Initialize the APM agent at the start of your application:

Node.js / Express

app.js
// Initialize APM at the very top of your entry file
const qodryx = require('@qodryx/apm');

qodryx.init({
  apiKey: process.env.QODRYX_API_KEY,
  serviceName: 'my-api',
  environment: process.env.NODE_ENV,
  
  // Optional configurations
  sampleRate: 1.0,        // 100% sampling
  captureBody: true,      // Capture request/response bodies
  captureHeaders: true,   // Capture HTTP headers
  
  // Database instrumentation
  instrumentations: {
    postgres: true,
    mongodb: true,
    redis: true,
  }
});

// Your application code
const express = require('express');
const app = express();

// APM automatically instruments Express routes
app.get('/api/users', async (req, res) => {
  // This request will be traced automatically
  const users = await db.query('SELECT * FROM users');
  res.json(users);
});

Next.js

instrumentation.ts
// Next.js 13+ instrumentation file
export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    const qodryx = await import('@qodryx/apm');
    
    qodryx.init({
      apiKey: process.env.QODRYX_API_KEY,
      serviceName: 'my-nextjs-app',
      environment: process.env.NODE_ENV,
    });
  }
}

Custom Spans

Create custom spans to trace specific operations:

JavaScript
const qodryx = require('@qodryx/apm');

async function processOrder(orderId) {
  // Create a custom span
  return qodryx.startSpan('process-order', async (span) => {
    span.setTag('order.id', orderId);
    
    // Child span for payment processing
    await qodryx.startSpan('payment-processing', async (paymentSpan) => {
      const result = await chargeCard(orderId);
      paymentSpan.setTag('payment.status', result.status);
      return result;
    });
    
    // Child span for inventory update
    await qodryx.startSpan('inventory-update', async () => {
      await updateInventory(orderId);
    });
    
    span.setTag('order.status', 'completed');
  });
}

Custom Metrics

Track custom business metrics:

JavaScript
const qodryx = require('@qodryx/apm');

// Counter - track occurrences
qodryx.metrics.increment('orders.created', {
  region: 'us-east',
  plan: 'pro'
});

// Gauge - track current values
qodryx.metrics.gauge('queue.length', queueSize);

// Histogram - track distributions
qodryx.metrics.histogram('order.value', orderAmount, {
  currency: 'USD'
});

// Timing - track durations
const timer = qodryx.metrics.startTimer('external_api.duration');
await callExternalAPI();
timer.end({ api: 'stripe' });

Dashboard

View APM data in the QODRYX dashboard:

Service Map

Visualize service dependencies

Trace Explorer

Search and analyze traces

Performance Trends

Track metrics over time

Slow Endpoints

Identify bottlenecks

Supported Frameworks

Automatic instrumentation for popular frameworks:

  • Node.js: Express, Fastify, Koa, Hapi, Next.js, NestJS
  • Python: Django, Flask, FastAPI, Starlette
  • Databases: PostgreSQL, MySQL, MongoDB, Redis, Elasticsearch
  • Message Queues: RabbitMQ, Kafka, SQS
  • HTTP Clients: Axios, fetch, requests