Skip to content
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
3 changes: 2 additions & 1 deletion typescript/logging/fireworks-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class FireworksTransport extends Transport {

constructor(opts: {
gatewayBaseUrl?: string;
apiKey?: string;
rolloutIdEnv?: string;
waitUntil?: (promise: Promise<any>) => void;
} = {}) {
Expand All @@ -56,7 +57,7 @@ export class FireworksTransport extends Transport {
'https://tracing.fireworks.ai';

this.rolloutIdEnv = opts.rolloutIdEnv || 'EP_ROLLOUT_ID';
this.apiKey = process.env.FIREWORKS_API_KEY;
this.apiKey = opts.apiKey || process.env.FIREWORKS_API_KEY;
this.waitUntil = opts.waitUntil;
}

Expand Down
44 changes: 41 additions & 3 deletions typescript/logging/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import winston from 'winston';
import { FireworksTransport } from './fireworks-transport.js';

type RolloutLoggerOptions = {
gatewayBaseUrl?: string;
apiKey?: string;
name?: string;
};

// Global reference to waitUntil function
let globalWaitUntil: ((promise: Promise<any>) => void) | undefined;

Expand Down Expand Up @@ -36,9 +42,41 @@ export const logger = winston.createLogger({
/**
* Create a child logger with rollout_id context.
*/
export function createRolloutLogger(rolloutId: string, name: string = 'init'): winston.Logger {
return logger.child({
export function createRolloutLogger(
rolloutId: string,
nameOrOptions: string | RolloutLoggerOptions = 'init'
): winston.Logger {
const options = typeof nameOrOptions === 'string' ? { name: nameOrOptions } : nameOrOptions;
const name = options.name || 'init';
const defaultMeta = {
rollout_id: rolloutId,
logger_name: `${name}.${rolloutId}`
});
};

if (options.gatewayBaseUrl || options.apiKey) {
return winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.errors({ stack: true }),
winston.format.json()
),
defaultMeta,
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
)
}),
new FireworksTransport({
gatewayBaseUrl: options.gatewayBaseUrl,
apiKey: options.apiKey,
waitUntil: (promise: Promise<any>) => globalWaitUntil?.(promise)
})
]
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated logger configuration will drift over time

Low Severity

The logger configuration inside createRolloutLogger (level, format, console transport) is a near-exact copy of the module-level logger configuration. If either copy is updated in the future (e.g., log level, format options, additional transports), the other will silently remain stale. Extracting shared config (format, level, console transport factory) into a reusable constant or helper would eliminate this risk.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c4aa43a. Configure here.

}

return logger.child(defaultMeta);
}
Loading