Skip to content

Commit dba4313

Browse files
committed
v3: more visibility into flushing worker otel data in prod
1 parent 506613d commit dba4313

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

packages/cli-v3/src/workers/prod/worker-facade.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,54 @@ const zodIpc = new ZodIpcConnection({
202202
},
203203
CLEANUP: async ({ flush, kill }, sender) => {
204204
if (kill) {
205-
await Promise.all([prodUsageManager.flush(), tracingSDK.flush()]);
205+
await flushAll();
206206
// Now we need to exit the process
207207
await sender.send("READY_TO_DISPOSE", undefined);
208208
} else {
209209
if (flush) {
210-
await Promise.all([prodUsageManager.flush(), tracingSDK.flush()]);
210+
await flushAll();
211211
}
212212
}
213213
},
214214
},
215215
});
216216

217+
async function flushAll(timeoutInMs: number = 10_000) {
218+
const now = performance.now();
219+
220+
console.log(`Flushing at ${now}`);
221+
222+
await Promise.all([flushUsage(), flushTracingSDK()]);
223+
224+
const duration = performance.now() - now;
225+
226+
console.log(`Flushed in ${duration}ms`);
227+
}
228+
229+
async function flushUsage() {
230+
const now = performance.now();
231+
232+
console.log(`Flushing usage at ${now}`);
233+
234+
await prodUsageManager.flush();
235+
236+
const duration = performance.now() - now;
237+
238+
console.log(`Flushed usage in ${duration}ms`);
239+
}
240+
241+
async function flushTracingSDK() {
242+
const now = performance.now();
243+
244+
console.log(`Flushing tracingSDK at ${now}`);
245+
246+
await tracingSDK.flush();
247+
248+
const duration = performance.now() - now;
249+
250+
console.log(`Flushed tracingSDK in ${duration}ms`);
251+
}
252+
217253
// Ignore SIGTERM, handled by entry point
218254
process.on("SIGTERM", async () => {});
219255

packages/cli-v3/src/workers/prod/worker-setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export const tracingSDK = new TracingSDK({
1616
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://0.0.0.0:4318",
1717
instrumentations: setupImportedConfig?.instrumentations ?? [],
1818
diagLogLevel: (process.env.OTEL_LOG_LEVEL as TracingDiagnosticLogLevel) ?? "none",
19-
forceFlushTimeoutMillis: 1_000,
19+
forceFlushTimeoutMillis: process.env.OTEL_FORCE_FLUSH_TIMEOUT
20+
? parseInt(process.env.OTEL_FORCE_FLUSH_TIMEOUT, 10)
21+
: 1_000,
2022
});
2123

2224
export const otelTracer: Tracer = tracingSDK.getTracer("trigger-prod-worker", packageJson.version);

0 commit comments

Comments
 (0)