Framework
An unexpected failure needs a stable identity if repeated occurrences should reach the same issue. Record enough context to investigate it, choose an error code that groups like failures, and let the reporting hook route it to the configured destination.
Recording an error is not reporting it.
A catch that persists a row, sets a failed status, dead-letters an item or returns a fallback has recorded the failure. Nobody outside the database learns about it. Reporting means the error reaches the active telemetry backend as an error: an exception on the current span, an error log record, a sample on the om.errors counter, and – for backends that model errors as issues – an entry there.
A
catchthat does anything other than rethrow MUST also route the error toreportError, either directly or through a chokepoint that does.
logger.error alone does not satisfy the rule. It produces a log record (which does reach the backend's logs signal when telemetry is on), but no span exception, no om.errors sample, and no fingerprint for the backend to group on. Log it and report it.
import { reportError } from '@open-mercato/telemetry'
try {
await pullBatch()
} catch (error) {
logger.error('Batch pull failed', { runId, err: error })
reportError(error, { module: 'data_sync', code: 'data_sync.batch_pull_failed', attributes: { runId } })
// …then whatever the caller does: retry, dead-letter, mark failed
}
From a package that must not depend on @open-mercato/telemetry (anything in packages/core, packages/queue, …), go through the runtime bridge instead of importing the package:
import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
getTelemetryRuntime()?.reportError(error, { module: 'integrations', code: 'integrations.log_error' })
With telemetry off, that is one global lookup and nothing else.
Client components use the report-only dispatcher so they can reach either a full runtime or the reporter installed by the enabled BrowserTelemetry entry:
import { reportTelemetryError } from '@open-mercato/shared/lib/telemetry/runtime'
reportTelemetryError(error, { module: 'ui', code: 'ui.address_types_load_failed' })
The browser reporter retains calls during deferred SDK startup and exports redacted exception spans through the existing same-origin trace proxy. It requires the existing browser RUM opt-in; a server runtime is not shared with the browser. With browser telemetry disabled this path does nothing. Startup and reporting failures cannot interrupt user feedback. Browser logs and metrics export are not added by this path.
code – the fingerprintcode is a stable, enumerated token shaped module.reason (data_sync.item_failed, queue.job_failed). It is published under one name, error.code, on all three built-in surfaces – the span attribute, the log record's attributes and the om.errors metric label – so a query written against one works against the others. One exception belongs to the exporter, not to us: the OTLP→Prometheus translation replaces . with _, so the om.errors alert rule queries error_code against a Prometheus-backed pipeline while the span and the log record keep error.code.
It MUST NOT be interpolated. `import failed for ${id}` gives every occurrence its own group at the backend and unbounded cardinality on the metric. Worse, metric labels – unlike attributes – do not pass through redaction, so an interpolated email or token would egress. Put the id in attributes, where it belongs.
The shape is enforced, not merely documented, because code routinely originates outside the framework – an adapter's data.errorCode, a third-party module's integrationLogService.write({ code }). reportError narrows it once at the funnel: a value that is not module.reason is dropped and the error reports exactly as one carrying no code at all, so a malformed fingerprint can never reach a metric label. A chokepoint that has a fallback of its own substitutes it first (integrations.log_error, data_sync.item_failed), so the error still lands in a group rather than none.
code exists because the backends' automatic grouping cannot work without it here:
Three chokepoints mean most module code inherits the rule without writing a line:
| Chokepoint | Covers | Codes |
|---|---|---|
integrationLogService.write() at level: 'error' | every integration error row – data_sync, payment_gateways, gateway_stripe, and any future integration | the row's own code, or integrations.log_error |
The queue strategies' failure paths (async + local) | a handler that throws, a job that spends its last attempt, a worker-level fault, a failed abandonment sweep | queue.job_failed, queue.job_exhausted, queue.worker_error, queue.abandon_* |
data_sync's engine | per-item dead letters, run faults, a run that completed with failures, a dropped coverage refresh | data_sync.item_failed, data_sync.export_item_failed, data_sync.run_failed, data_sync.run_partial_failure, data_sync.coverage_refresh_failed |
Adapters that classify their own item failures set data.errorCode on a failed import item and the engine uses it as the code, provided it is shaped module.reason; otherwise the fallback applies.
A job failure is reported once, and its code says which failure it is: queue.job_failed while retries remain, queue.job_exhausted on the attempt that dead-letters it. Both strategies agree on this, so an alert written against one holds for the other – queue.job_exhausted is the condition to page on.
Info · For operators upgrading
The local strategy previously emitted both queue.job_failed and queue.job_exhausted on a job's final attempt. It now emits only queue.job_exhausted, matching async. An alert thresholding on queue.job_failed alone will stop seeing terminal failures – page on queue.job_exhausted, or on both.
Two properties hold at each chokepoint:
reportError's own call into the provider hook, so a third-party sink that throws cannot escape into a caller that still has to rethrow or return a 500. A telemetry outage cannot fail a sync batch or lose a log row.integration_logs.payload never leaves the database. The row's message, its code and opaque ids are reported; the payload carries the failed record itself, so it stays put. Put the cause in the message – a constant message with the reason only in the payload reports an error an operator cannot act on – and the failed record in the payload.The framework reports every error. There is no sampling, throttling or suppression in reportError, and no env var to add one.
Three layers below the facade already own volume, and each drops where the drop is visible and adjustable:
A fourth limiter inside the facade would be the only one that loses an error irrecoverably at the source, and its budget would be per process – not a number an operator can alert on. If a burst is noisy, the fix is the alert rule (group by code, threshold on the om.errors rate), not throwing the events away first.
reportError does hold one guard: it no-ops a nested call, so an error raised inside the reporting path cannot recurse.
TelemetryProvider has an optional reportError hook, called in addition to the span/log/metric path, so implementing it can never make signal disappear. The provider owns its own de-duplication.
import { registerProvider, initTelemetry } from '@open-mercato/telemetry'
registerProvider({
...baseProvider,
name: 'sentry',
supports: ['errors', 'logs'],
reportError(error, { module, code, attributes }) {
Sentry.captureException(new Error(error.message), {
fingerprint: code ? [code] : undefined,
tags: { module, code },
extra: attributes,
})
},
})
await initTelemetry() // with TELEMETRY_BACKEND=sentry
The error argument arrives already serialized and PII-redacted (name, message, stack) and attributes already redacted – never reach for the original thrown value. code arrives in the context and is deliberately not repeated in attributes.
The hook MUST NOT throw. The facade wraps it and degrades a throwing hook to a warning, but swallow your SDK's failures inside the implementation, where you can decide what a dropped report means.
TELEMETRY_BACKEND=console yarn mercato data_sync run --integration <id>
The console provider prints every reported error with its code and attributes, so a failing import shows one line per dead-lettered item plus one data_sync.run_partial_failure summary for the run.
reportError writes its log record throughpackages/telemetry/AGENTS.md, .ai/specs/2026-09-08-error-reporting-policy.mdPrevious: Dev Runtime Diagnostics · Next: Structured Logging