Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pino] Omit misleading context when executed in thread-stream worker #127

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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