Skip to content

Commit e7b69d2

Browse files
authored
fix: support request-scoped rollout logging config (#449)
Allow TypeScript rollout loggers to use per-request gateway URLs and API keys so remote rollout servers can log status to the same tracing environment used for model calls. Made-with: Cursor
1 parent b3b02c8 commit e7b69d2

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

typescript/logging/fireworks-transport.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class FireworksTransport extends Transport {
4545

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

5859
this.rolloutIdEnv = opts.rolloutIdEnv || 'EP_ROLLOUT_ID';
59-
this.apiKey = process.env.FIREWORKS_API_KEY;
60+
this.apiKey = opts.apiKey || process.env.FIREWORKS_API_KEY;
6061
this.waitUntil = opts.waitUntil;
6162
}
6263

typescript/logging/logger.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
import winston from 'winston';
66
import { FireworksTransport } from './fireworks-transport.js';
77

8+
type RolloutLoggerOptions = {
9+
gatewayBaseUrl?: string;
10+
apiKey?: string;
11+
name?: string;
12+
};
13+
814
// Global reference to waitUntil function
915
let globalWaitUntil: ((promise: Promise<any>) => void) | undefined;
1016

@@ -36,9 +42,41 @@ export const logger = winston.createLogger({
3642
/**
3743
* Create a child logger with rollout_id context.
3844
*/
39-
export function createRolloutLogger(rolloutId: string, name: string = 'init'): winston.Logger {
40-
return logger.child({
45+
export function createRolloutLogger(
46+
rolloutId: string,
47+
nameOrOptions: string | RolloutLoggerOptions = 'init'
48+
): winston.Logger {
49+
const options = typeof nameOrOptions === 'string' ? { name: nameOrOptions } : nameOrOptions;
50+
const name = options.name || 'init';
51+
const defaultMeta = {
4152
rollout_id: rolloutId,
4253
logger_name: `${name}.${rolloutId}`
43-
});
54+
};
55+
56+
if (options.gatewayBaseUrl || options.apiKey) {
57+
return winston.createLogger({
58+
level: 'info',
59+
format: winston.format.combine(
60+
winston.format.timestamp(),
61+
winston.format.errors({ stack: true }),
62+
winston.format.json()
63+
),
64+
defaultMeta,
65+
transports: [
66+
new winston.transports.Console({
67+
format: winston.format.combine(
68+
winston.format.colorize(),
69+
winston.format.simple()
70+
)
71+
}),
72+
new FireworksTransport({
73+
gatewayBaseUrl: options.gatewayBaseUrl,
74+
apiKey: options.apiKey,
75+
waitUntil: (promise: Promise<any>) => globalWaitUntil?.(promise)
76+
})
77+
]
78+
});
79+
}
80+
81+
return logger.child(defaultMeta);
4482
}

0 commit comments

Comments
 (0)