Skip to content

Handle logging strange behaviours #492

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

Merged
merged 1 commit into from
Mar 4, 2025
Merged
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
31 changes: 22 additions & 9 deletions packages/restate-sdk/src/endpoint/handlers/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export class GenericHandler implements RestateHandler {

// See vm_log below for more details
const invocationLoggers: Map<number, Logger> = new Map<number, Logger>();
const logsTextDecoder = new TextDecoder();
const logsTextDecoder = new TextDecoder("utf-8", { fatal: false });

/**
* The shared core propagates logs to the SDK invoking this method.
Expand All @@ -463,18 +463,31 @@ export function vm_log(
strBytes: Uint8Array,
loggerId?: number
) {
const logger = (loggerId && invocationLoggers.get(loggerId)) || undefined;
const str = logsTextDecoder.decode(strBytes);
if (logger !== undefined) {
logger.logForLevel(wasmLogLevelToRestateLogLevel(level), str);
} else {
try {
const logger = (loggerId && invocationLoggers.get(loggerId)) || undefined;
const str = logsTextDecoder.decode(strBytes);
if (logger !== undefined) {
logger.logForLevel(wasmLogLevelToRestateLogLevel(level), str);
} else {
defaultLoggerTransport(
{
level: wasmLogLevelToRestateLogLevel(level),
replaying: false,
source: LogSource.JOURNAL,
},
str
);
}
} catch (e) {
// This function CAN'T EVER propagate an error,
// because otherwise it will cause an awesome error in the shared core due to concurrent usage of it.
defaultLoggerTransport(
{
level: wasmLogLevelToRestateLogLevel(level),
level: RestateLogLevel.ERROR,
replaying: false,
source: LogSource.JOURNAL,
source: LogSource.SYSTEM,
},
str
"Unexpected error thrown while trying to log: " + e?.toString()
);
}
}
Expand Down