Skip to main content

LynxTracer

Main telemetry collector.
import { LynxTracer } from "@lynx/sdk";

const lynx = new LynxTracer(config);

run(agentName, callback)

Runs code inside a Lynx trace context.
await lynx.run("SupportAgent", async () => {
  lynx.userInput("Help me reset my password");
});

run(options, callback)

Use structured run metadata.
await lynx.run(
  {
    agentName: "SupportAgent",
    workspaceId: "workspace_123",
    agentId: "agent_123",
    sessionId: "session_123",
  },
  async () => {
    // agent work
  },
);

Semantic helpers

MethodPurpose
userInput(input, metadata?)Capture user input.
decision(reasonOrDecision, options?)Capture an agent decision.
context(labelOrData, dataOrMetadata?)Capture retrieved or constructed context.
memory(label, payload)Capture memory access.
outcome(options)Capture final session outcome.
setAttributes(attributes)Attach attributes to later events in the run.
annotate(label, payload)Capture a custom annotation.
log(label, payload)Capture a custom context alert.

Instrumentation helpers

MethodPurpose
instrumentLLM(client, options?)Wrap an LLM client object.
instrumentTool(name, fn, metadata?)Wrap a tool function.
guardTool(name, fn, options)Wrap a tool with local policy evaluation.

Delivery helpers

MethodPurpose
flush()Send queued telemetry now.
shutdown(options?)Clear timers and flush before exit.
getStatus()Read local queue, circuit breaker, and delivery status.

LynxPolicyError

Thrown when guardTool() blocks a tool call.
import { LynxPolicyError } from "@lynx/sdk";

if (error instanceof LynxPolicyError) {
  console.log(error.action);
}

lynx

Default tracer configured from environment variables.
import { lynx } from "@lynx/sdk";
Use this for simple applications. Use new LynxTracer() when you need explicit config per process, tenant, or test.