const trackedAgent = instrumentAgent(agent, { apiKey: process.env.SENTRIAL_API_KEY, // required apiUrl: 'https://api.sentrial.com', // optional — defaults to production agentName: 'my-agent', // optional — defaults to agent.name or agent.id failSilently: true, // optional — true by default pii: true, // optional — auto-fetch PII redaction config});
Fail-Safe by Default — With failSilently: true (the default), any Sentrial API errors are logged but never crash your app. Your agent calls always go through. Set to false during development to see full errors.
When you use Mastra’s memory system, conversations are automatically linked. No extra config needed.
const THREAD_ID = 'convo-abc-123';const USER_ID = 'user-42';// Turn 1await trackedAgent.generate('Hi, my name is Alice.', { memory: { resource: USER_ID, thread: THREAD_ID },});// Turn 2 — automatically linked to the same conversationawait trackedAgent.generate('What was my name again?', { memory: { resource: USER_ID, thread: THREAD_ID },});
In your Sentrial dashboard, both sessions appear linked under the same conversation ID. The mapping is:
Streaming works transparently. The wrapper intercepts the onFinish callback, records the full response, and completes the session when the stream ends.
const stream = await trackedAgent.stream( 'Give me a summary of my recent orders.', { memory: { resource: 'user-42', thread: 'convo-abc' }, maxSteps: 5, onStepFinish: (step) => { // Your callback still works — Sentrial injects alongside it console.log('Step done:', step.toolCalls?.length, 'tool calls'); }, });for await (const chunk of stream.textStream) { process.stdout.write(chunk);}// Session recorded when stream finishes: full text, tokens, cost, latency
Enable PII redaction to automatically scrub sensitive data from tracked inputs before they reach Sentrial’s servers.
const tracked = instrumentAgent(agent, { apiKey: process.env.SENTRIAL_API_KEY, agentName: 'support-agent', pii: true, // Auto-fetch redaction config from your Sentrial org});// User sends: "My email is john@example.com and SSN is 123-45-6789"// Sentrial stores: "My email is [EMAIL] and SSN is [SSN]"
PII redaction happens client-side before data leaves your server. Configure which PII types to redact in your Sentrial dashboard under Settings > PII Redaction.
If an agent call throws, the error is recorded and the session is marked as failed. The original error is always re-thrown so your error handling works normally.
try { await trackedAgent.generate('Do something risky');} catch (error) { // Error is recorded in Sentrial as a failed session // with error type and message, then re-thrown here console.error(error);}