Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(telemetry): Empty context persisted when remaining beans are negative after run finish #10635

Merged
merged 2 commits into from
Dec 6, 2024
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
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
Copy link
Member

Choose a reason for hiding this comment

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

I sometimes dislike what types force us to do. The finalBody.remainingBeans && part is totally unnecessary at runtime.

? {}
: 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
Loading