Hono Framework Logging Integration
Add structured logging to Hono applications across Node.js, Bun, Deno, and Cloudflare Workers with trace propagation.
LogTide’s Hono SDK provides lightweight middleware for automatic request logging and distributed tracing across all Hono-supported runtimes: Node.js, Bun, Deno, and Cloudflare Workers.
Why use LogTide with Hono?
- Multi-runtime: Same code on Node.js, Bun, Deno, and Workers
- Lightweight: Minimal overhead, fetch-based transport
- Context-based: Uses Hono’s
c.get()/c.set()for scoping - Trace propagation: W3C traceparent headers across services
- Automatic: Request logging without manual instrumentation
Prerequisites
- Hono 4.x
- Node.js 18+, Bun, Deno, or Cloudflare Workers
- LogTide instance with a DSN
Installation
npm install @logtide/hono
# or
bun add @logtide/hono
Quick Start
import { Hono } from 'hono';
import { hub } from '@logtide/core';
import { logtide } from '@logtide/hono';
const app = new Hono();
app.use('*', logtide({
dsn: process.env.LOGTIDE_DSN,
service: 'hono-api',
environment: process.env.NODE_ENV,
}));
app.get('/users/:id', (c) => {
c.get('logtideScope').setTag('userId', c.req.param('id'));
hub.captureLog('info', 'Fetching user', {
userId: c.req.param('id'),
});
return c.json({ id: c.req.param('id') });
});
export default app;
Middleware Options
app.use('*', logtide({
dsn: process.env.LOGTIDE_DSN,
service: 'hono-api',
environment: process.env.NODE_ENV,
release: '1.0.0',
tracesSampleRate: 1.0,
}));
Context-Based Scoping
app.get('/orders', (c) => {
const scope = c.get('logtideScope');
scope.setExtra('userId', 'user-123');
scope.setTag('module', 'orders');
const traceId = c.get('logtideTraceId');
return c.json({ orders: [], traceId });
});
Runtime Examples
Node.js
import { serve } from '@hono/node-server';
serve(app, { port: 3000 });
Bun
export default { port: 3000, fetch: app.fetch };
Cloudflare Workers
export default app;
Deno
Deno.serve(app.fetch);
Error Handling
app.onError((err, c) => {
// Errors are captured automatically by the middleware
return c.json({
error: err.message,
traceId: c.get('logtideTraceId'),
}, 500);
});
Next Steps
- JavaScript SDK - Core SDK reference
- Hono SDK Reference - Full API documentation
- Docker Integration - Container deployments
Frequently Asked Questions
How do I add LogTide logging to a Hono application?
Install @logtide/hono (or use bun add @logtide/hono for Bun) and register the middleware with app.use('*', logtide({ dsn, service, environment })). Every request is logged automatically from that point, regardless of which runtime you deploy to.
Does LogTide work with Hono on Cloudflare Workers?
Yes. The Hono SDK is designed for multi-runtime support and works on Node.js, Bun, Deno, and Cloudflare Workers. The same middleware code runs across all targets — just export the app and LogTide uses a fetch-based transport suitable for each environment.
How do I access per-request scope and trace ID in Hono routes?
Use Hono's context API: c.get('logtideScope') returns the request scope where you can call setTag() and setExtra(), and c.get('logtideTraceId') returns the W3C trace ID you can forward in responses or downstream requests.
Does the Hono integration support structured JSON logs?
Yes. Log events captured via hub.captureLog() or the automatic request middleware are shipped as structured JSON including service name, level, message, and any custom metadata you attach through the scope — making them fully searchable in LogTide.