Skip to main content

Prerequisites

  • Node.js 18 or later
  • A Lynx ingestion endpoint
  • A Lynx API key

Install

npm install @lynx/sdk
You can also use your package manager of choice:
pnpm add @lynx/sdk
yarn add @lynx/sdk

Create a tracer

import { LynxTracer } from "@lynx/sdk";

const lynx = new LynxTracer({
  clientId: "support-api",
  endpoint: "https://lynx.example.com",
  apiKey: process.env.LYNX_API_KEY,
});

Trace an agent run

Wrap your agent workflow in run(). Events captured inside the callback are attached to the same run context.
await lynx.run("SupportAgent", async () => {
  lynx.userInput("I want a refund", { userId: "usr_123" });
  lynx.setAttributes({ orderId: "order_123" });

  lynx.context("refund-policy", {
    refundWindowDays: 30,
  });

  lynx.decision({
    name: "select_refund_workflow",
    selected: "refund",
    confidence: 0.82,
    reason: "The order is inside the refund window",
  });

  lynx.outcome({
    status: "COMPLETED",
    businessStatus: "SUCCEEDED",
  });
});

Shut down gracefully

For servers, call shutdown() in your process shutdown hook. For serverless functions, call it before the handler exits if you need a best-effort final flush.
process.on("SIGTERM", () => {
  void lynx.shutdown({ timeoutMs: 1000 });
});
The default delivery mode is background-only. Telemetry failures do not throw from your agent workflow.