LogTide SDK middleware for Hono — request tracing and error capture
npm install @logtide/hono

LogTide middleware for Hono — automatic request tracing, error capture, and breadcrumbs.
---
- Automatic request spans for every incoming request
- Error capture with full request context
- W3C Trace Context propagation (traceparent in/out)
- Breadcrumbs for HTTP requests
- Scope access via c.get('logtideScope')
- Works everywhere — Node.js, Bun, Deno, Cloudflare Workers
- Full TypeScript support with strict types
``bash`
npm install @logtide/honoor
pnpm add @logtide/honoor
yarn add @logtide/hono
---
`typescript
import { Hono } from 'hono';
import { logtide } from '@logtide/hono';
const app = new Hono();
app.use('*', logtide({
dsn: 'https://lp_your_key@your-instance.com',
// Or use apiUrl + apiKey instead of dsn:
// apiUrl: 'https://your-instance.com',
// apiKey: 'lp_your_key',
service: 'my-hono-api',
environment: 'production',
}));
app.get('/hello', (c) => c.json({ message: 'Hello World' }));
export default app;
`
---
The middleware runs on every request and:
1. Extracts incoming traceparent header (or generates a new trace ID)GET /hello
2. Creates a span named after the request (e.g. )c.set('logtideScope', scope)
3. Stores scope on the Hono context ()next()
4. Calls to process the requestok
5. Finishes the span with or error based on response statustraceparent
6. Injects into the response headers
7. Captures errors thrown by handlers with full context
---
Use c.get() to access the LogTide scope inside your handlers:
`typescript
app.get('/users/:id', (c) => {
const scope = c.get('logtideScope');
const traceId = c.get('logtideTraceId');
// Add custom breadcrumbs
scope.addBreadcrumb({
type: 'query',
category: 'database',
message: 'SELECT * FROM users WHERE id = ?',
timestamp: Date.now(),
});
return c.json({ id: c.req.param('id') });
});
`
---
All ClientOptions from @logtide/core are supported:
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| dsn | string | required | DSN string: https://lp_KEY@host/PROJECT |service
| | string | required | Service name for log attribution |environment
| | string | — | Environment (e.g. production, staging) |release
| | string | — | Release / version identifier |debug
| | boolean | false | Enable debug logging |tracesSampleRate
| | number | 1.0 | Sample rate for traces (0.0 to 1.0) |
See @logtide/core README for the full list of options.
---
Errors thrown by handlers are automatically captured with:
- HTTP method and URL
- Request span marked as error
- Error serialized with stack trace
`typescript`
app.get('/boom', () => {
throw new Error('Something broke');
// Automatically captured by LogTide middleware
});
For 5xx responses (e.g. from Hono's error handler), the middleware also logs an error entry.
---
`typescript``
import { logtide } from '@logtide/hono';
import type { LogtideHonoOptions } from '@logtide/hono';
---
MIT License - see LICENSE for details.