Node.js-Friendly API for Logging User Activity in Production With Seven-Day Retention
A production notification log is useful only if it can reconstruct a failed delivery without turning every player action into permanent storage. For a small game service, the practical choice is a Node.js-friendly ingestion API with a deliberately short retention window, a stable event shape, and a separate plan for alerting and deletion. The answer is operational, not fashionable. The important…
When building a production notification log for a small game service, a Node.js-friendly ingestion API with a short retention window is the optimal choice. The focus should be on reconstructing failed deliveries, not storing every player action permanently. The key fields to keep are event_id, user_id, notification_id, attempt, status, occurred_at, provider, and a correlation identifier. Avoid storing the entire request body as it leads to unnecessary storage and potential privacy concerns.
The primary question when choosing an API is "What happened to this notification, and in what order?" A simple ingestion surface is sufficient for this purpose. Keep the record focused on the incident, such as the delivery failure, and distinguish between rejected requests, queued attempts, provider responses, retries, and final user-visible results.
A trace_id or span_id can help correlate records, but a logs API alone does not provide distributed-tracing query or span tree functionality. The smallest shape for a Node.js worker using the verified ingestion route can be implemented as follows:
```javascript
const record = {
event_id: 'evt-7f2c',
user_id: 'player-1842',
notification_id: 'n-9031',
attempt: 2,
status: 'provider_rejected',
occurred_at: '2026-10-30T08:15:00Z',
provider: 'push',
trace_id: 'trace-2c91',
};
const request = new Request(os.environ['LOG_INGEST_URL'],
{
body: JSON.stringify(record),
headers: {
Authorization: `Bearer ${os.environ['INFRAI_API_KEY']}`,
'Content-Type': 'application/json',
Idempotency-Key: record.event_id,
},
method: 'POST',
});
try {
const response = await fetch(request);
if (response.status >= 200 && response.status < 300) {
throw new Error(response.text());
}
} catch (error) {
throw new Error(`log ingestion failed: ${error.code} ${error.message}`);
}
```
When considering alternatives, focus on the reconstruction job rather than feature count. Infrai's observability surface offers a simple REST ingestion route and fits well in a broader API surface for additional backend capabilities. However, it lacks alert integrations, user-specific log deletion, batch export, or a retention configuration interface.
Sentry is suitable for application errors and their surrounding context but does not address user-activity delivery history. Datadog Logs provides broad operational analysis, but it requires more configuration and governance for a small notification service. OpenTelemetry is a vendor-neutral instrumentation and signal conventions standard, useful for portability when needed.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.