Skip to content

Bun, Deno, and Edge runtimes

The Node.js SDK (@amlexiahq/node) runs on any runtime with global fetch and standard timers.

For Go or Ruby backends, use the native SDKs — Go · Ruby.

Bun

bash
bun add @amlexiahq/node
typescript
import { AmlexiaClient, wrapFetch } from '@amlexiahq/node';

const client = AmlexiaClient.fromEnv();
globalThis.fetch = wrapFetch(client, fetch);

client.track({
  endpoint: '/api/health',
  method: 'GET',
  statusCode: 200,
  latencyMs: 12,
  environment: process.env.AMLEXIA_ENVIRONMENT,
});

CLI: bunx amlexia health

Deno

typescript
import { AmlexiaClient } from 'npm:@amlexiahq/node';

const client = new AmlexiaClient({
  sdkKey: Deno.env.get('AMLEXIA_SDK_KEY')!,
  environment: Deno.env.get('AMLEXIA_ENVIRONMENT'),
});

Cloudflare Workers

Use the Node package in a Workers bundle, or call ingest via fetch directly.

typescript
import { AmlexiaClient } from '@amlexiahq/node';

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext) {
    const client = new AmlexiaClient({
      sdkKey: env.AMLEXIA_SDK_KEY,
      flushIntervalMs: 1000,
      maxBatchSize: 10,
    });
    const start = Date.now();
    const res = await handle(request);
    client.track({
      endpoint: new URL(request.url).pathname,
      method: request.method,
      statusCode: res.status,
      latencyMs: Date.now() - start,
      environment: 'production',
    });
    ctx.waitUntil(client.flush());
    return res;
  },
};

TIP

Always ctx.waitUntil(client.flush()) so events send before the isolate stops.

Python on Edge

Where CPython Workers are available, use the standard amlexia package. Otherwise POST to ingest with fetch.