cool-baker-11020
12/02/2025, 3:27 PMtall-airline-16756
12/02/2025, 3:27 PMtall-airline-16756
12/02/2025, 3:28 PMctx.job.id — unique per call job.
• Room name / ID: ctx.room.name and ctx.room.sid.
• SIP call ID (for telephony): participant.attributes['sip.callID'].
• Caller phone number (if available): participant.attributes['sip.phoneNumber'].
2) Log at session start (example)
• At entry, wait for the participant and immediately log these fields so every subsequent log can be correlated:
entry: async (ctx: JobContext) => {
const participant = await ctx.waitForParticipant();
console.log('call:start', {
jobId: ctx.job.id,
roomName: ctx.room.name,
roomSid: ctx.room.sid,
kind: participant.kind,
callId: participant.attributes['sip.callID'],
phoneNumber: participant.attributes['sip.phoneNumber'],
});
}
3) Attach context to all logs
• Set ctx.log_context_fields so all later logs automatically include the same identifiers:
ctx.log_context_fields = {
job_id: ctx.job.id,
room_name: ctx.room.name,
call_id: participant.attributes['sip.callID'],
phone_number: participant.attributes['sip.phoneNumber'],
};
4) Search and filter
• Use the job ID, room name/SID, or SIP call ID as your filter in log storage or the Agent insights UI to isolate a single call’s logs, traces, and transcripts.
If you want, tell me which identifier you prefer (job ID, room name, or SIP call ID) and I’ll give a tailored example for filtering logs in your logging system.
Sources: Agents (Node.js) | livekit/livekit_composite | DeepWiki | SIP participant | LiveKit docs | https://blog.livekit.io/streamline-troubleshooting-with-agent-observability/#/portal|cool-baker-11020
12/02/2025, 3:32 PMtall-airline-16756
12/02/2025, 3:32 PMconst callCtx = {
jobId: ctx.job.id,
roomName: ctx.room.name,
roomSid: ctx.room.sid,
kind: participant.kind,
callId: participant.attributes?.['sip.callID'],
phoneNumber: participant.attributes?.['sip.phoneNumber'],
};
2) Make that context appear on every log line
• Two options:
◦ Set ctx.log_context_fields so the agent runtime includes these fields automatically with every log line:
ctx.log_context_fields = {
job_id: callCtx.jobId,
room_name: callCtx.roomName,
room_sid: callCtx.roomSid,
call_id: callCtx.callId,
};
• Or, if you control the logger, include the context object on every log call:
logger.info('some event', { ...callCtx, event: 'something_happened' });
3) Use a single canonical identifier for filtering
• Pick one primary field to filter by (recommended: jobId or callId if available) and ensure it is always present in ctx.log_context_fields so every log line can be searched by that value.
4) Verify in practice
• Emit a test log after setting context:
console.log('call:context_set', callCtx);
• Then search your logs for that jobId or callId to confirm all lines include the same identifier.
If you tell me which logger or log sink you use (console, Winston, Datadog, CloudWatch, etc.), I can give the exact snippet to automatically attach the context to every log line.cool-baker-11020
12/02/2025, 3:36 PMctx.log_context_fieldstall-airline-16756
12/02/2025, 3:36 PMctx.log_context_fields isn't available in the JavaScript SDK. To ensure every log line maps to a single call, add the call identifiers to each log entry yourself. Two simple options — pick one and I can give a snippet for your logger:
• Lightweight: wrap console with a per-job logger
const makeLogger = (ctx, participant) => {
const meta = {
jobId: ctx.job.id,
roomName: ctx.room.name,
roomSid: ctx.room.sid,
callId: participant?.attributes?.['sip.callID'],
};
return {
info: (msg, obj = {}) => console.info(JSON.stringify({ level: 'info', ...meta, msg, ...obj })),
warn: (msg, obj = {}) => console.warn(JSON.stringify({ level: 'warn', ...meta, msg, ...obj })),
error: (msg, obj = {}) => console.error(JSON.stringify({ level: 'error', ...meta, msg, ...obj })),
};
};
Use const log = makeLogger(ctx, participant) at session start and call log.info(...) everywhere — every line will include the same identifiers.
• Structured logger: initialize a logger (pino/winston) per job with persistent bindings
const logger = pino().child({ jobId: ctx.job.id, roomName: ctx.room.name, callId: participant?.attributes?.['sip.callID'] });
logger.info('something happened', { extra: 'data' });
Tell me which logger you use (console, pino, winston, Datadog agent, etc.) and I’ll provide the exact snippet to integrate into your agent.
Sources: Job lifecycle | LiveKit docs | Agents (Node.js) | livekit/livekit_composite | DeepWiki | Agent insights in LiveKit Cloud | LiveKit docs | https://blog.livekit.io/streamline-troubleshooting-with-agent-observability/#/portal/signup|cool-baker-11020
12/02/2025, 3:40 PMtall-airline-16756
12/02/2025, 3:42 PM