Skip to content

Record types

Choose a record type based on the question you want to answer.

Use increment(...) for values that increase over time:

Terminal window
runtime.increment("posts.list.requests")
runtime.increment("jobs.email.processed", 1, { queue: "email" })

Good examples are request counts, processed job counts, retry counts, and webhook delivery attempts.

Use gauge(...) for values that can go up or down:

Terminal window
runtime.gauge("jobs.email.pending", pendingCount)

Good examples are queue depth, open connection count, and active worker count.

Use histogram(...) for distributions:

Terminal window
runtime.histogram("payload.bytes", size)

Good examples are payload size, batch size, and rows returned.

Use timing(...) to measure callback duration:

Terminal window
const posts = await runtime.timing("posts.list.duration_ms", () => {
return listPosts()
})

The method returns the callback result.

Use event(...) for named activity:

Terminal window
runtime.event("posts.created", { postId: post.id })

Good examples are post.created, webhooks.stripe.replayed, and jobs.email.completed.

Use signal(...) for numeric operational values:

Terminal window
runtime.signal("db.shard.hotness", 0.82, { shard: "shard-1" })

Signals are useful for product internals and operational pressure values.

Use capture(...) for errors:

Terminal window
try {
await handleStripeWebhook(request)
} catch (error) {
runtime.capture(error, { provider: "stripe" })
throw error
}

Captured errors share the stream context and attributes.

Use span(...) to wrap a named operation:

Terminal window
await runtime.span("webhooks.stripe.handle", () => {
return handleStripeWebhook(request)
})

Layeron emits one span record when the callback finishes.

Span records include spanId, parentSpanId when the span is nested, traceId when the request has one, duration, and outcome.