Skip to content

Commit

Permalink
[pino] Omit misleading context when executed in thread-stream worker (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrHeinz authored Oct 9, 2024
1 parent dad3c25 commit ab0a429
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <source-token>` in the `/example-project` directory
7 changes: 6 additions & 1 deletion packages/node/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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];
}

Expand Down
1 change: 1 addition & 0 deletions packages/pino/src/pino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab0a429

Please sign in to comment.