diff --git a/src/o11y/logger.ts b/src/o11y/logger.ts index eee08156..4678651d 100644 --- a/src/o11y/logger.ts +++ b/src/o11y/logger.ts @@ -1,4 +1,5 @@ import Pino from 'pino'; +import { agentContext } from '#agent/agentContextLocalStorage'; const logLevel = process.env.LOG_LEVEL || 'INFO'; // Review config at https://github.com/simenandre/pino-cloud-logging/blob/main/src/main.ts @@ -57,6 +58,12 @@ export const logger: Pino.Logger = Pino({ const stackTrace = logObject.err?.stack; const stackProp: any = stackTrace ? { stack_trace: stackTrace } : {}; + const agent = agentContext(); + if (agent) { + object.agentId = agent.agentId; + if (agent.parentAgentId) object.parentAgentId = agent.parentAgentId; + } + return { ...object, ...stackProp }; }, },