LogTide

Hono SDK

@logtide/hono provides Hono middleware with automatic request logging, context-based scoping, and support for all Hono runtimes (Node.js, Bun, Deno, Cloudflare Workers).

Installation

npm install @logtide/hono

Quick Start

import { Hono } from 'hono';
import { hub } from '@logtide/core';
import { logtide } from '@logtide/hono';

const app = new Hono();

// Add LogTide middleware (initializes LogTide automatically)
app.use('*', logtide({
  dsn: 'https://[email protected]',
  service: 'hono-api',
  environment: 'production',
}));

app.get('/users/:id', (c) => {
  const scope = c.get('logtideScope');
  scope.setTag('userId', c.req.param('id'));

  hub.captureLog('info', 'Fetching user', {
    userId: c.req.param('id'),
  });

  return c.json({ id: c.req.param('id'), name: 'Alice' });
});

export default app;

Middleware Options

The middleware accepts all ClientOptions from @logtide/core:

app.use('*', logtide({
  dsn: 'https://[email protected]',
  service: 'hono-api',
  environment: 'production',
  release: '1.0.0',
  tracesSampleRate: 1.0,
  debug: false,
}));

Context Access

The middleware stores the scope and trace ID in Hono's context variables:

import { hub } from '@logtide/core';

app.get('/orders', (c) => {
  // Access the request scope
  const scope = c.get('logtideScope');
  scope.setExtra('userId', 'user-123');
  scope.setTag('module', 'orders');

  // Access the trace ID
  const traceId = c.get('logtideTraceId');

  hub.captureLog('info', 'Listing orders');

  return c.json({
    orders: [],
    traceId,
  });
});

Multi-Runtime

The same code works across all Hono-supported runtimes:

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 automatically captured by the middleware,
  // but you can add custom handling here
  return c.json({
    error: err.message,
    traceId: c.get('logtideTraceId'),
  }, 500);
});

API Reference

Export Description
logtide(options?)Hono middleware — request logging, scoping, tracing
c.get('logtideScope')Per-request scope via Hono context
c.get('logtideTraceId')Current trace ID via Hono context

See the JavaScript SDK core docs for the full @logtide/core API.