feat: add per-job context to global Pino logger#1338
Open
karan-dhir wants to merge 1 commit intolivekit:mainfrom
Open
feat: add per-job context to global Pino logger#1338karan-dhir wants to merge 1 commit intolivekit:mainfrom
karan-dhir wants to merge 1 commit intolivekit:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 2b543e4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 26 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Set jobId and roomName on the global logger when a job starts so that all SDK-internal logs (TTS/STT metrics, speech events, AgentSession lifecycle) are filterable by job in log aggregation tools. The job context is stored separately so enableOtelLogging() can re-apply it when reconfiguring the logger mid-job. Context is cleared after shutdown callbacks complete to prevent stale fields leaking to the next job on the same worker.
2f1f1dc to
2b543e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1336.
Sets
jobIdandroomNameon the global Pino logger when a job starts, so all SDK-internal logs (TTS/STT metrics, speech events, AgentSession lifecycle) include per-job fields on every log line. Context is cleared after shutdown callbacks complete to prevent stale fields leaking to the next job.This enables filtering all logs for a single call in log aggregation tools:
Changes
agents/src/log.ts: AddsetJobContext()— creates a Pino child logger with the provided fields, storing the base logger so it can be restored. Also updatesenableOtelLogging()to keep the base logger in sync.agents/src/job.ts: CallsetJobContext({ jobId, roomName })in theJobContextconstructor.agents/src/ipc/job_proc_lazy_main.ts: CallsetJobContext({})after shutdown callbacks to clear context before the next job.Why this is safe
LiveKit workers process one job at a time (single-threaded, sequential dispatch), so mutating the global logger has no concurrency risk.
Testing
Verified locally that Pino child logger correctly adds fields to all subsequent
log()calls and that restoring the base logger cleanly removes them: