Alerts
Flag any step in a Node.js trace as a warning or error, with the values that triggered it, using recount.addAlert.
Call recount.addAlert() to flag the most recently added span with a warn or error badge in the dashboard. There's no built-in threshold comparison - you decide when it fires with a plain if.
Basic usage
recount.addSpan('json', 'Query time', {
output: { durationMs: 1240 }
});
if (durationMs > 1000) {
recount.addAlert('Query duration (ms)', 'warn', {
checks: [{ value: 1240 }]
});
}addAlert attaches to whichever span was most recently added on the active trace - call it right after the addSpan (or addMessage) it applies to.
You can call it more than once to flag several conditions on the same span - for example, separate warn and error alerts:
recount.addSpan('json', 'Query time', {
output: { durationMs: 5240 }
});
if (durationMs > 1000) {
recount.addAlert('Query duration (ms)', 'warn', {
checks: [{ value: durationMs }]
});
}
if (durationMs > 5000) {
recount.addAlert('Query duration (ms)', 'error', {
checks: [{ value: durationMs }]
});
}Multiple checks
checks shows which field(s) the alert is about. Pass one entry per value, with target naming the field it came from - the SDK doesn't evaluate these against anything, they're just what gets displayed:
recount.addSpan('json', 'Transaction review', {
output: { amount: 4200, riskScore: 82 }
});
recount.addAlert('Suspicious transaction', 'error', {
checks: [
{ target: 'Amount', value: 4200 },
{ target: 'Risk score', value: 82 }
]
});An alert with no checks at all is valid too - useful when the label alone says everything:
recount.addAlert('Manual review required', 'warn');Inside groups
SpanGroup (the g passed to addGroup's builder) has the same alert() method - it attaches to the most recently added span within that group:
recount.addGroup('Risk checks', (g) => {
g.span('json', 'Credit check', { output: { score: 610 } });
if (creditScore < 650) {
g.alert('Below minimum credit score', 'error', {
checks: [{ value: 610 }]
});
}
});recount.addAlert(label, level, options?)
| Parameter | Type | Description |
|---|---|---|
label | string | Display label shown in the dashboard (max 128 chars) |
level | 'warn' | 'error' | Severity shown in the dashboard |
options | SpanAlertOptions | Optional - see below |
SpanAlertOptions
| Option | Type | Required | Description |
|---|---|---|---|
checks | SpanAlertCheck[] | No | Context values to show alongside the alert |
SpanAlertCheck
| Option | Type | Required | Description |
|---|---|---|---|
value | number | Yes | The value to display |
target | string | No | Name of the field value came from, e.g. 'Amount' |
Max 10 alerts per span, max 200 checks per alert. See Limits.
Dashboard behaviour
- Collapsed span - a
warnorerrorbadge appears on the right of the span header if any alert was attached. - Expanded span - a coloured banner appears for each alert, showing the label and any check values (e.g.
Suspicious transaction: Amount: 4200, Risk score: 82).