Skip to content

Pino

Ship Pino log records to AxonPush as OpenTelemetry-shaped app.log events. Pino is the fastest Node.js logger and the modern standard for backend services.

[!TIP] Non-blocking by default (v0.0.2+)

The returned stream pushes each record onto a bounded in-memory queue and drains it from a single background task, so log.info(...) stays O(microseconds) on the caller’s path. Call stream.flush(timeoutMs?) at known checkpoints to guarantee delivery. Pass mode: "sync" for blocking publishes.

Terminal window
npm install @axonpush/sdk pino
import pino from "pino";
import { AxonPush } from "@axonpush/sdk";
import { createAxonPushPinoStream } from "@axonpush/sdk/integrations/pino";
const client = new AxonPush({
apiKey: process.env.AXONPUSH_API_KEY!,
tenantId: process.env.AXONPUSH_TENANT_ID!,
});
const stream = createAxonPushPinoStream({
client,
channelId: 1,
serviceName: "my-api",
environment: "production",
});
const log = pino({ level: "info" }, stream);

Log normally — Pino structured fields become OTel attributes:

log.info({ userId: 42, method: "oauth" }, "user signed in");
log.warn({ endpoint: "/api/search", remaining: 3 }, "rate limit approaching");
log.error({ endpoint: "/api/search", elapsedMs: 5000 }, "downstream timeout");

Wrap your handler with flushAfterInvocation so the stream drains before the container freezes:

import { flushAfterInvocation } from "@axonpush/sdk/integrations/pino";
export const handler = flushAfterInvocation(stream, async (event, _ctx) => {
log.info({ event }, "processing event");
return { statusCode: 200 };
});
await stream.flush(1000); // block until queue drained, up to 1 second
await stream.close(); // drain pending records and stop the worker

stream.close() is also called automatically by the module-level beforeExit / SIGTERM / SIGINT hook at process shutdown.

OptionTypeDefaultDescription
clientAxonPushrequiredThe pre-built SDK client.
channelIdnumberrequiredTarget channel for log events.
serviceNamestringOTel service.name resource attribute.
serviceVersionstringOTel service.version.
environmentstringOTel deployment.environment.
agentIdstringOptional agent correlation ID.
mode"background" | "sync""background"Publishing mode.
queueSizenumber1000Max records buffered before drop.
shutdownTimeoutMsnumber2000Time to wait for drain on close().
concurrencynumber1Parallel in-flight publishes.
FieldValue
identifier"pino"
eventType"app.log"
payload.bodyThe Pino msg field
payload.severityNumber / payload.severityTextOTel severity mapped from Pino’s numeric level (10→TRACE, 20→DEBUG, 30→INFO, 40→WARN, 50→ERROR, 60→FATAL)
payload.attributesAll non-standard fields from the Pino record plus host.name, process.pid
payload.resourceservice.name, service.version, deployment.environment (if configured)