Skip to content

Commit

Permalink
(feat) Add agentId and agentParentId to structured logs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcampagnolitg committed Dec 6, 2024
1 parent f3683f7 commit 1c2b9f0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/o11y/logger.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 };
},
},
Expand Down

0 comments on commit 1c2b9f0

Please sign in to comment.