Skip to content

Commit

Permalink
fix(telemetry): Empty context persisted when remaining beans are nega…
Browse files Browse the repository at this point in the history
…tive after run finish (#10635)
  • Loading branch information
usmanmani1122 authored Dec 6, 2024
1 parent 3653dc7 commit ad4e83e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions packages/telemetry/src/context-aware-slog.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ export const makeContextualSlogProcessor = (

/**
* @param {Slog} slog
* @returns {{ attributes: T & LogAttributes, body: Partial<Slog>; timestamp: Slog['time'] }}
* @returns {{ attributes: T & LogAttributes, body: Partial<Slog>; time: Slog['time'] }}
*/
const slogProcessor = ({ monotime, time: timestamp, ...body }) => {
const slogProcessor = ({ monotime, time, ...body }) => {
const finalBody = { ...body };

/** @type {{'crank.syscallNum'?: Slog['syscallNum']}} */
Expand Down Expand Up @@ -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,
};

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -373,9 +377,9 @@ export const makeContextualSlogProcessor = (
}

return {
attributes: /** @type {T & LogAttributes} */ (logAttributes),
body: finalBody,
timestamp,
attributes: /** @type {T & LogAttributes} */ (logAttributes),
time,
};
};

Expand Down
4 changes: 2 additions & 2 deletions packages/telemetry/src/otel-context-aware-slog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit ad4e83e

Please sign in to comment.