TypeScript SDK: Metrics
Recording Metrics
Section titled “Recording Metrics”Use aires.metric() to record a metric value:
Signature
Section titled “Signature”| Parameter | Type | Description |
|---|---|---|
name | string | Metric name (dot-separated hierarchy) |
value | number | Numeric value (integer or float) |
opts | LogOptions | Optional — tags, attributes, trace context, etc. |
The call is non-blocking. The metric event is batched and shipped like any other event.
Metric Types
Section titled “Metric Types”In the protobuf schema, each metric has a MetricType enum. The TypeScript SDK creates metrics as GAUGE by default. You can indicate the type via naming conventions or attributes:
Gauges
Section titled “Gauges”A gauge represents a point-in-time value that can go up or down. Use for current state:
Counters
Section titled “Counters”A counter represents a cumulative value that only increases. Use for totals:
Histograms
Section titled “Histograms”Record individual observations that will be aggregated. Use for latencies and sizes:
Compute percentiles in ClickHouse:
Naming Conventions
Section titled “Naming Conventions”Follow a dot-separated hierarchical naming convention:
Examples:
| Metric Name | Description |
|---|---|
http.request.duration_ms | HTTP request latency in milliseconds |
http.request.size_bytes | Request body size in bytes |
http.response.size_bytes | Response body size in bytes |
http.requests.total | Total HTTP requests (counter) |
db.query.duration_ms | Database query latency |
db.connections.active | Active database connections (gauge) |
db.connections.idle | Idle database connections (gauge) |
queue.depth | Current queue depth (gauge) |
queue.processing.duration_ms | Queue item processing time |
cache.hits.total | Cache hit count (counter) |
cache.misses.total | Cache miss count (counter) |
process.memory.rss_bytes | Process RSS memory usage |
process.cpu.usage_percent | Process CPU usage |
ai.llm.tokens.total | LLM tokens consumed (counter) |
ai.llm.duration_ms | LLM call latency |
Labels and Dimensions
Section titled “Labels and Dimensions”Use attr for metric dimensions/labels. These become filterable columns in ClickHouse:
Use tags for free-form categorization:
Cardinality Guidelines
Section titled “Cardinality Guidelines”Keep attribute values low-cardinality to avoid ClickHouse performance issues:
- Good:
method: "GET",status: "200",region: "us-east-1" - Bad:
userId: "user-12345",requestId: "req-abc-...",timestamp: "..."
If you need to record high-cardinality dimensions, use data instead of attr:
Trace Context on Metrics
Section titled “Trace Context on Metrics”You can attach trace context to metrics to correlate them with specific requests:
This lets you join metrics with trace events in ClickHouse:
Aggregation Queries
Section titled “Aggregation Queries”Since metrics are stored as events, you aggregate them with SQL: