LogTide

Elysia SDK

@logtide/elysia is a Bun-optimized Elysia plugin for automatic request logging, scoped context, lifecycle hooks, and W3C trace propagation.

Installation

bun add @logtide/elysia

Quick Start

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

const app = new Elysia()
  .use(logtide({
    dsn: 'https://[email protected]',
    service: 'elysia-api',
    environment: 'production',
  }))
  .get('/users/:id', ({ params }) => {
    hub.captureLog('info', 'Fetching user', {
      userId: params.id,
    });

    return { id: params.id, name: 'Alice' };
  })
  .listen(3000);

The plugin automatically applies .as('global') to cover all routes, including those registered after the plugin.

Plugin Options

The plugin accepts all ClientOptions from @logtide/core:

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

Lifecycle Hooks

The plugin hooks into Elysia's lifecycle:

Hook Behavior
onRequestCreates scope, extracts traceparent, starts span
afterResponseLogs request completion with duration, finishes span
onErrorCaptures errors with full request context
onStopFlushes pending events on server shutdown

Scoped Context

The plugin automatically creates request scopes and traces for each request. Use the hub to capture logs and errors:

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

app
  .use(logtide({
    dsn: 'https://[email protected]',
    service: 'elysia-api',
  }))
  .get('/orders', () => {
    hub.captureLog('info', 'Listing orders');
    return { orders: [] };
  });

Error Handling

app
  .use(logtide({
    dsn: 'https://[email protected]',
    service: 'elysia-api',
  }))
  .onError(({ code, error }) => {
    // Error is already captured by the plugin
    // Customize the response
    return new Response(JSON.stringify({
      error: error.message,
    }), {
      status: code === 'NOT_FOUND' ? 404 : 500,
      headers: { 'Content-Type': 'application/json' },
    });
  });

API Reference

Export Description
logtide(options)Elysia plugin factory — auto-applies .as('global'), initializes LogTide

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

Esc

Type to search across all documentation pages