Gain deep insights into your application performance with Prometheus metrics and OpenTelemetry distributed tracing. Compatible with Jaeger, Zipkin, and Datadog.
Automatic HTTP, CPU, and memory metrics exposed at /metrics endpoint.
Track requests across microservices with OpenTelemetry support.
Create counters, histograms, and gauges for your business logic.
Automatic exception recording in spans for debugging.
CanxJS automatically exposes default metrics (CPU, Memory, HTTP latency) at /metrics. Add custom metrics for your business logic.
1import { metrics } from 'canxjs';23// Counter - track occurrences4metrics.increment('users_registered_total');5metrics.increment('api_requests_total', { endpoint: '/users' });67// Histogram - track durations8metrics.recordDuration('db_query_duration_ms', 150);9metrics.recordDuration('http_request_duration_ms', 45, {10method: 'GET',11route: '/api/users'12});1314// Gauge - track current values15metrics.gauge('active_connections', 42);16metrics.gauge('queue_size', await queue.size());
Use the @Trace decorator for automatic span creation, or create spans manually for fine-grained control.
1import { Trace, createSpan } from 'canxjs';23class OrderController {45@Trace('order.process')6async create(req: Request) {7// Automatic span creation8await this.validate(req);9await this.charge(req);10await this.notify(req);11}1213async validate(req: Request) {14// Manual span creation15const span = createSpan('order.validate');16try {17// validation logic...18span.setStatus('ok');19} catch (e) {20span.recordException(e);21throw e;22} finally {23span.end();24}25}26}
| Exporter | Use Case | Config |
|---|---|---|
| jaeger | Self-hosted tracing | JAEGER_ENDPOINT |
| zipkin | Self-hosted tracing | ZIPKIN_URL |
| otlp | OpenTelemetry Collector | OTEL_EXPORTER_URL |
| datadog | Managed service | DD_API_KEY |
1// config/observability.ts2export default {3metrics: {4enabled: true,5endpoint: '/metrics', // Prometheus scrape endpoint6prefix: 'canx_', // Metric name prefix7},8tracing: {9enabled: true,10exporter: 'jaeger', // or 'zipkin', 'otlp'11serviceName: 'my-app',12sampleRate: 0.1, // Sample 10% in production13}14};