how can I identify a single call in livekit agents...
# ask-ai
c
how can I identify a single call in livekit agents js logs
t
Thanks for reaching out, Human. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to identify a single call in LiveKit Agents (Node.js) logs — here’s the simplest, reliable approach you can add to your agent code and log workflow. 1) Key identifiers to log • Job ID:
ctx.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:
Copy code
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:
Copy code
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|
c
NO, I'm asking how to identify which call corresponds to each log line
t
Thanks — I see you want each individual log line tied to the exact call it came from. Here’s how to do that so every log line is unambiguously correlated to a call. 1) Log a persistent call context object at session start • At entry, wait for the participant and build a small context object containing the unique identifiers:
Copy code
const 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:
Copy code
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:
Copy code
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:
Copy code
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.
c
I don't see this param
ctx.log_context_fields
t
You're right —
ctx.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
Copy code
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
Copy code
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|
c
The LiveKit Agents-JS codebase uses Pino
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!