APILensAPILens
frameworks/elysia

Elysia

v0.7+

A plugin for Elysia's ultra-fast Bun HTTP framework.

Returns a plugin object with a `setup(app)` method. Hooks into onRequest and onAfterHandle lifecycle events.

Designed for Bun runtime. Works with Node.js too.

Install

bash
npm install auto-api-observe

Quick Start

The minimal setup — import, configure, and you're observing.

elysia-quick-start.js
javascript
import { Elysia }            from 'elysia';
import { elysiaObservability } from 'auto-api-observe';

const observePlugin = elysiaObservability({
  apiKey: process.env.APILENS_KEY,
});

const app = new Elysia()
  .use(observePlugin.setup)
  .get('/users', () => ({ users: [] }))
  .listen(3000);

Full Example

All available options with custom fields and real-world usage.

elysia-full.js
javascript
import { Elysia }                        from 'elysia';
import { elysiaObservability, addField } from 'auto-api-observe';

const plugin = elysiaObservability({
  apiKey:        process.env.APILENS_KEY,
  slowThreshold: 400,
  tags:          { service: 'bun-api', runtime: 'bun' },
});

const app = new Elysia()
  .use(plugin.setup)
  .get('/users/:id', ({ params }) => {
    addField('userId', params.id);
    return { user: { id: params.id } };
  })
  .listen(3000);

What's Tracked Automatically

  • request.method, request.url, response.status, latency
  • Context stored per-request via WeakMap<Request>
  • DB and outbound calls

Options Reference

OptionTypeDefault
apiKeystring
slowThresholdnumber1000
tagsRecord{}

Custom Fields

Attach any business context to the current request via AsyncLocalStorage — scoped per request, works the same on every framework.

javascript
const { addField } = require('auto-api-observe');

// In any route handler:
addField('userId',  req.user.id);
addField('plan',    req.user.plan);
addField('country', req.headers['cf-ipcountry']);

// Sensitive keys are auto-redacted before shipping:
addField('authorization', token); // → "[REDACTED]"
addField('password',      pass);  // → "[REDACTED]"

Ready to observe your Elysia app?

Sign up free — get your API key in under 30 seconds. No credit card required.

Get your free API key