Observability and CloudWatch logging
The SDKs are deliberately cloud-agnostic and do not ship an AWS SDK or logging dependency. On AWS (ECS/Fargate or Lambda), emit structured JSON logs to stdout using the runecode.aggregator.log.v1 contract below. AWS ships stdout to CloudWatch Logs automatically with zero network latency in the wallet hot path, and RGS Admin → Aggregator Logs consumes this exact schema for RuneCode-hosted aggregators.
1. AWS CloudWatch log group convention
Every RuneCode-hosted aggregator writes to a dedicated log group following this naming convention:
/runecode/<env>/aggregator-<slug>
For example: /runecode/prod/aggregator-timelesstech or /runecode/dev/aggregator-timelesstech.
- ECS / Fargate: Configure the container's
logConfigurationwith theawslogsdriver:
``json "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "/runecode/prod/aggregator-timelesstech", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "wallet" } } ``
- AWS Lambda:
stdoutis shipped automatically to/aws/lambda/<function-name>. Map that log group inAGGREGATOR_LOG_GROUPS(for exampletimeless-tech=/aws/lambda/integration-timelesstech) if it differs from the default/runecode/<env>/aggregator-<slug>convention.
2. Log contract (runecode.aggregator.log.v1)
Emit one JSON object per line to stdout. RGS Admin parses these fields directly to power filtering, retry tracing, and round drill-downs:
Required fields
| Field | Type | Description |
|---|---|---|
schema | string | Always "runecode.aggregator.log.v1" |
ts | string | RFC 3339 UTC timestamp (e.g. "2026-11-20T08:15:00.123Z") |
level | string | "info", "warn", or "error" |
msg | string | Event type: "wallet_call", "provider_call", or "retry_scheduled" |
aggregator | string | Aggregator / integration slug (e.g. "timeless-tech") |
endpoint | string | Wallet path: "/v1/balance", "/v1/debit", "/v1/credit", "/v1/rollback" |
http_status | number | HTTP status returned to the RGS (200, 400, 500, …) |
latency_ms | number | End-to-end handler duration in milliseconds |
Optional correlation fields
| Field | Type | Description |
|---|---|---|
sub_operator | string | null | Sub-operator id resolved from SessionRecord |
tx_id | string | null | RGS transaction id (debit.id, credit.id, or first rollbacks[].id) |
round | number | null | RGS round id (clickable to Round Detail in RGS Admin) |
retry_attempt | number | Value of the x-retry-attempt request header (0 on first try, 1+ on retries) |
retry_after_s | number | null | Value sent in Retry-After response header, if any |
error_code | string | null | Wallet error code (ERR_GE, ERR_IPB, …) |
provider_code | string | null | Upstream provider error code (e.g. "GS_12", "GS_50") |
provider_tx_id | string | null | Upstream provider transaction id or reference |
Security rule: Never logtoken,x-signature, raw signed request bodies, or providersecret_keyvalues. High-RPS cost optimization (recommended): Skip routine fast200 OKcalls on attempt0— log 100% of errors (http_status >= 400), retries and retry recoveries (retry_attempt >= 1), and slow calls (latency_ms >= 1000). Both the TypeScript (shouldLogWalletEvent(ev)) and Rust (ev.should_log(DEFAULT_SLOW_LOG_THRESHOLD_MS)) SDKs provide this helper out of the box, cutting CloudWatch ingestion cost by ~95–99% at high RPS while keeping full auditability in Core Postgres (wallet.wallet_tx.receipt).
3. Examples
Rust (tracing + tracing-subscriber with the json feature)
// Once at startup:
tracing_subscriber::fmt()
.json()
.with_current_span(false)
.flatten_event(true)
.init();
// After handling a wallet call:
tracing::info!(
schema = "runecode.aggregator.log.v1",
aggregator = "timeless-tech",
sub_operator = %session.sub_operator,
endpoint = "/v1/credit",
tx_id = %credit_id,
round = round_id,
retry_attempt,
retry_after_s = retry_after.map(|d| d.as_secs()),
http_status = status,
error_code = ?err_code,
provider_code = ?provider_code,
latency_ms = elapsed.as_millis() as u64,
"wallet_call"
);
TypeScript / Node
const startedAt = Date.now();
const { status, body } = await router.handle(req.method, req.path, rawBody, req.headers);
console.log(JSON.stringify({
schema: "runecode.aggregator.log.v1",
ts: new Date().toISOString(),
level: status >= 500 ? "error" : status >= 400 ? "warn" : "info",
msg: "wallet_call",
aggregator: "timeless-tech",
sub_operator: session?.subOperator ?? null,
endpoint: req.path,
tx_id: parsed?.credit?.id ?? parsed?.debit?.id ?? parsed?.rollbacks?.[0]?.id ?? null,
round: parsed?.round ?? null,
retry_attempt: Number(req.headers["x-retry-attempt"] ?? 0),
retry_after_s: retryAfterSecs ?? null,
http_status: status,
error_code: status >= 400 ? (JSON.parse(body).code ?? null) : null,
provider_code: providerCode ?? null,
latency_ms: Date.now() - startedAt,
}));
4. CloudWatch Logs Insights queries
Filter retryable failures for a specific aggregator:
fields @timestamp, aggregator, sub_operator, endpoint, tx_id, round, retry_attempt, retry_after_s, http_status, error_code, provider_code, latency_ms
| filter schema = "runecode.aggregator.log.v1" and aggregator = "timeless-tech" and http_status >= 500
| sort @timestamp desc
| limit 50
Trace every attempt for a single transaction (tx_id):
fields @timestamp, aggregator, sub_operator, endpoint, retry_attempt, retry_after_s, http_status, error_code, provider_code, latency_ms
| filter tx_id = "019a1b2c-4e5f-7a80-9b1c-2d3e4f5a6b7c"
| sort @timestamp asc
5. Consuming in RGS Admin & alarms
- RGS Admin → Aggregator Logs (
/observability/aggregators) queries the configured CloudWatch log group for each RuneCode-hosted aggregator and parsesrunecode.aggregator.log.v1events. External (partner-hosted) aggregators are marked as external and do not require a CloudWatch log group. - Stuck win retries alarm: CloudWatch Metric Filter on
endpoint = "/v1/credit"andretry_attempt >= 5. - Aggregator 5xx spike alarm: Metric Filter on
aggregator = "<name>"andhttp_status >= 500. - End-to-end audit correlation: For provider receipts that must be persisted permanently in RuneCode Core (such as provider hashes or
wager_id), return them in the optionalmetadatamap (≤ 2 KiB) on your2xxwallet response so Core stores them alongsidetx_idinwallet_tx.receipt.