Skip to main content

Link agent actions to traces

Pass the trace of an agent run to LumoAuth, and find that trace on every audit row of the run.

RecipeReadyView source
Works with
JavaScript / TypeScriptPython

What it shows​

  1. The agent traces each run with OpenTelemetry. One run of the agent is one trace.
  2. The instrumentation of the HTTP client sends the W3C traceparent header with each request, also with the requests of the LumoAuth SDK.
  3. LumoAuth stores the trace ID with each audit row that these requests write.
  4. The Audit logs page of the portal shows the trace ID on each row. With a connected tracing backend, each row links to the trace in Langfuse, LangSmith or Arize.

Before you start​

  • An agent with a client ID and secret. The setup script below registers "Trip planner".
  • For the links into your tracing backend, check that your plan includes agent trace integrations in the plans matrix. The trace ID itself is stored without a connection.

To link the rows to your traces, connect a backend in the portal:

  1. Open Settings, Integrations, Agent ecosystem.
  2. Under Trace correlation, choose Langfuse, LangSmith, Arize or OpenTelemetry (OTLP). The portal may ask for your password again.
  3. Fill in the form. For Langfuse, enter the Project ID and the Base URL of your Langfuse, for example https://cloud.langfuse.com.
  4. Click Add connection. The page of the connection shows a sample link under Deep links.
VariableValue
LUMOAUTH_URLThe address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region.
LUMOAUTH_ORG_IDYour organization, for example acme-corp.
AGENT_CLIENT_IDThe client ID of the agent "Trip planner". The setup script prints it.
AGENT_CLIENT_SECRETIts client secret. The setup script prints it.

The setup script registers the agent "Trip planner" with the capability trips:read. Its API key needs the scopes admin:agents:read and admin:agents:write. The programs themselves use only the credentials of the agent.

node agents/trace-correlation/setup.mjs
setup.mjs
// Registers the agent of this recipe, "Trip planner", with one capability, and
// prints its client ID and secret. Run it again at any time.
//
// node agents/trace-correlation/setup.mjs
//
// The API key needs the scopes admin:agents:read and admin:agents:write.
import { call, ensure, printEnv } from '../../_lib/admin.mjs';

const agent = await ensure('/admin/agents', (a) => a.name === 'Trip planner', {
name: 'Trip planner',
description: 'Reads trips and proposes changes. It may not book.',
identityType: 'client_secret',
capabilities: ['trips:read'],
});

// LumoAuth shows a secret once, in the answer that creates it. On a second
// run the script therefore asks for a new secret, and the old one stops.
const secret =
agent.clientSecret ??
(await call('POST', `/admin/agents/${agent.agentId}/rotate-credentials`)).data.clientSecret;

console.log(`Agent "${agent.name}" (${agent.agentId}) holds: trips:read`);
printEnv({ AGENT_CLIENT_ID: agent.agentId, AGENT_CLIENT_SECRET: secret });

Code​

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The trace ID on the audit rows and the Open trace link of a Langfuse connection were checked in the portal.

agents/trace-correlation/js/run.mjs
// One run of an agent, traced with OpenTelemetry. Each call to LumoAuth
// carries the traceparent header of the run, and LumoAuth stores the trace ID
// with the audit rows that the calls write.
//
// node agents/trace-correlation/js/run.mjs
import { trace } from '@opentelemetry/api';
import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { LumoAgent } from '@lumoauth/agent';

// Tracing for this process. The instrumentation adds the traceparent header
// to every fetch, also to the requests of the LumoAuth SDK. To see the spans
// in Langfuse, LangSmith, Arize or your own collector, add an exporter here.
const provider = new NodeTracerProvider();
provider.register();
new UndiciInstrumentation();

// Reads LUMOAUTH_URL, LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
const agent = new LumoAgent();
const tracer = trace.getTracer('trip-planner');

// One run of the agent is one trace. Every span of the run shares its ID.
await tracer.startActiveSpan('plan-trip', async (run) => {
console.log(`trace ID: ${run.spanContext().traceId}`);
for (const action of ['trips:read', 'trips:book']) {
const answer = await agent.ask(action, { trip: 'TRIP-2207' });
console.log(`${action}: ${answer.allowed ? 'allowed' : 'denied'}`);
}
run.end();
});
await provider.shutdown();
node agents/trace-correlation/js/run.mjs

Check the result​

Output
trace ID: 8b6f0e1b604b5e179cf2a2ef78edbb08
trips:read: allowed
trips:book: denied
  • In the portal, open Audit logs under Security, choose "Trip planner" under Actor, and click Apply filters. The rows of the questions show Trace with the first 8 characters of the trace ID that the program printed.
  • With a connected backend, these rows show Open trace. For Langfuse, the link has the form https://cloud.langfuse.com/project/<project>/traces/<trace ID>.
  • The row of the token request has no trace ID: LumoAuth reads the header only on the agent APIs, which the tracing docs list.

Limits​

  • LumoAuth keeps only the trace ID. It drops the span ID and the flags of the header.
  • The Admin API does not return the trace ID of a row, and the search of the audit log does not find it. Use the Audit logs page, or the links of a connected backend.
  • The programs create spans, but they send them nowhere. Add the exporter of your backend to see the spans of the run next to the audit rows.
  • An MCP server that uses @lumoauth/mcp or lumoauth-fastmcp reads the traceparent header of a tool call and sends it with its own requests to LumoAuth.