Function: createUpDownCounter()
@arolariu/website / instrumentation.server / createUpDownCounter
Function: createUpDownCounter()
createUpDownCounter(
name,description?,unit?):UpDownCounter<Attributes>
Defined in: instrumentation.server.ts:1248
Create an up-down counter metric instrument.
Up-down counters track values that can increase or decrease. Use for gauges like active connections, queue depth, or resource utilization.
Parameters
name
Metric name following semantic conventions (e.g., "http.server.active_requests")
description?
string
Human-readable description of what the metric measures
unit?
string
Optional unit of measurement (e.g., "1", "connections", "bytes")
Returns
UpDownCounter<Attributes>
UpDownCounter instrument for recording values with type-safe attributes
Remarks
- Values can increase or decrease (unlike regular counters)
- Use add() with positive or negative values
- Ideal for tracking current state or active resources
- Backends typically report the current sum
- Not suitable for rates or totals (use counter instead)
Examples
const activeConnections = createUpDownCounter(
'http.server.active_requests',
'Number of active HTTP requests being processed',
'1'
);
// Request starts
activeConnections.add(1, {
'http.method': 'GET',
'next.render_context': 'api',
});
// ... process request
// Request completes
activeConnections.add(-1, {
'http.method': 'GET',
'next.render_context': 'api',
});
// Cache size tracking
const cacheSize = createUpDownCounter('cache.size.bytes', 'Current cache size in bytes', 'bytes');
cacheSize.add(1024, { 'cache.system': 'redis' }); // Item cached
cacheSize.add(-1024, { 'cache.system': 'redis' }); // Item evicted
See
https://opentelemetry.io/docs/specs/otel/metrics/api/#updowncounter
// was this page useful?