Custom Metrics

Track application and business metrics with OTLP.

Metric Types

Counter

Monotonically increasing value:

const meter = otel.getMeterProvider().getMeter('my-service');
const requestCounter = meter.createCounter('http.requests', {
  description: 'Total HTTP requests'
});

requestCounter.add(1, { method: 'POST', endpoint: '/api/users' });

Histogram

Distribution of values:

const responseTime = meter.createHistogram('http.response_time', {
  description: 'HTTP response time in ms',
  unit: 'ms'
});

responseTime.record(245, { method: 'GET', endpoint: '/api/users' });

Gauge

Current value (up or down):

const activeConnections = meter.createObservableGauge('db.connections.active');

activeConnections.addCallback((result) => {
  result.observe(getActiveConnections());
});

Business Metrics

const revenueCounter = meter.createCounter('business.revenue', {
  unit: 'USD'
});

revenueCounter.add(49.99, {
  plan: 'pro',
  billing_period: 'monthly'
});

Viewing Metrics

Dashboard → Observability → Apps → Metrics

Create dashboards:

  • Time-series charts
  • Aggregations (sum, avg, percentiles)
  • Filtering by attributes
  • Alerting on thresholds

Next Steps

  • Traces - Add spans for metric context
  • SDKs - Language-specific examples