From 7465495ceb6bf145d8799930ecacbdffb3747c06 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Wed, 9 Oct 2024 14:14:42 +0200 Subject: [PATCH 1/2] [pino] Omit misleading context when executed in thread-stream worker --- packages/node/src/context.ts | 7 ++++++- packages/pino/src/pino.ts | 1 + packages/types/src/types.ts | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/node/src/context.ts b/packages/node/src/context.ts index 9761d32..e7989ef 100644 --- a/packages/node/src/context.ts +++ b/packages/node/src/context.ts @@ -41,7 +41,7 @@ function getCallingFrame(logtail: Node, stackContextHint?: StackContextHint): St return null; } -function getRelevantStackFrame(frames: StackFrame[], stackContextHint?: StackContextHint): StackFrame { +function getRelevantStackFrame(frames: StackFrame[], stackContextHint?: StackContextHint): StackFrame | null { if (stackContextHint) { frames.reverse(); let index = frames.findIndex((frame) => { @@ -55,6 +55,11 @@ function getRelevantStackFrame(frames: StackFrame[], stackContextHint?: StackCon if (index > 0) { return frames[index - 1]; } + + if (stackContextHint.required) { + return null; + } + return frames[frames.length - 1]; } diff --git a/packages/pino/src/pino.ts b/packages/pino/src/pino.ts index 42cd77f..849c7f3 100644 --- a/packages/pino/src/pino.ts +++ b/packages/pino/src/pino.ts @@ -23,6 +23,7 @@ export interface IPinoLogtailOptions { const stackContextHint = { fileName: "node_modules/pino", methodNames: ["log", "fatal", "error", "warn", "info", "debug", "trace", "silent"], + required: true, }; export async function logtailTransport(options: IPinoLogtailOptions) { diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index f27b8d9..d975372 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -118,7 +118,7 @@ export enum LogLevel { */ export type ContextKey = any; export type Context = { [key: string]: ContextKey }; -export type StackContextHint = { fileName: string; methodNames: string[] }; +export type StackContextHint = { fileName: string; methodNames: string[]; required?: true }; /** * Interface representing a minimal Logtail log From f59fe2318477f3766de22c2b80215543f0df8de1 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Wed, 9 Oct 2024 14:16:00 +0200 Subject: [PATCH 2/2] typo --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b441c9..fa09b8f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,5 +10,5 @@ We are using `yarn` to manage dependencies. 4. To use `example-project` with the locally built packages 1. Make sure all dependencies are installed and all packages built 2. Run `npm install` in the `/example-project` directory - 3. Run `yarn boostrap-example` in the root directory + 3. Run `yarn bootstrap-example` in the root directory 4. To run the example project, run `node index.js ` in the `/example-project` directory