From ad4e83e0b6dff9716da91fd65d367d3acad1772e Mon Sep 17 00:00:00 2001 From: Usman Saleem <57341641+usmanmani1122@users.noreply.github.com> Date: Fri, 6 Dec 2024 18:20:45 +0500 Subject: [PATCH] fix(telemetry): Empty context persisted when remaining beans are negative after run finish (#10635) --- packages/telemetry/src/context-aware-slog.js | 16 ++++++++++------ .../telemetry/src/otel-context-aware-slog.js | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/telemetry/src/context-aware-slog.js b/packages/telemetry/src/context-aware-slog.js index 33c2739efc5..dd55f418734 100644 --- a/packages/telemetry/src/context-aware-slog.js +++ b/packages/telemetry/src/context-aware-slog.js @@ -135,9 +135,9 @@ export const makeContextualSlogProcessor = ( /** * @param {Slog} slog - * @returns {{ attributes: T & LogAttributes, body: Partial; timestamp: Slog['time'] }} + * @returns {{ attributes: T & LogAttributes, body: Partial; time: Slog['time'] }} */ - const slogProcessor = ({ monotime, time: timestamp, ...body }) => { + const slogProcessor = ({ monotime, time, ...body }) => { const finalBody = { ...body }; /** @type {{'crank.syscallNum'?: Slog['syscallNum']}} */ @@ -321,13 +321,13 @@ export const makeContextualSlogProcessor = ( const logAttributes = { ...staticContext, - 'process.uptime': monotime, ...initContext, // Optional prelude ...blockContext, // Block is the first level of execution nesting ...triggerContext, // run and trigger info is nested next ...crankContext, // Finally cranks are the last level of nesting ...replayContext, // Replay is a substitute for crank context during vat page in ...eventLogAttributes, + 'process.uptime': monotime, }; /** @@ -356,7 +356,11 @@ export const makeContextualSlogProcessor = ( // eslint-disable-next-line no-restricted-syntax case SLOG_TYPES.COSMIC_SWINGSET.RUN.FINISH: { assert(!!triggerContext); - persistContext(finalBody.remainingBeans ? {} : triggerContext); + persistContext( + finalBody.remainingBeans && finalBody.remainingBeans > 0 + ? {} + : triggerContext, + ); triggerContext = null; break; } @@ -373,9 +377,9 @@ export const makeContextualSlogProcessor = ( } return { - attributes: /** @type {T & LogAttributes} */ (logAttributes), body: finalBody, - timestamp, + attributes: /** @type {T & LogAttributes} */ (logAttributes), + time, }; }; diff --git a/packages/telemetry/src/otel-context-aware-slog.js b/packages/telemetry/src/otel-context-aware-slog.js index 51891460eba..271c13da787 100644 --- a/packages/telemetry/src/otel-context-aware-slog.js +++ b/packages/telemetry/src/otel-context-aware-slog.js @@ -82,9 +82,9 @@ export const makeSlogSender = async options => { * @param {import('./context-aware-slog.js').Slog} slog */ const slogSender = slog => { - const { timestamp, ...logRecord } = contextualSlogProcessor(slog); + const { time, ...logRecord } = contextualSlogProcessor(slog); - const [secondsStr, fractionStr] = String(timestamp).split('.'); + const [secondsStr, fractionStr] = String(time).split('.'); const seconds = parseInt(secondsStr, 10); const nanoSeconds = parseInt( (fractionStr || String(0)).padEnd(9, String(0)).slice(0, 9),