Skip to content

Logging fixes #475

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
Dec 20, 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
3 changes: 2 additions & 1 deletion packages/restate-sdk/src/context_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
readonly input: vm.WasmInput,
public readonly console: Console,
public readonly handlerKind: HandlerKind,
private readonly vmLogger: Console,
private readonly invocationRequest: Request,
private readonly invocationEndPromise: CompletablePromise<void>,
private readonly inputReader: ReadableStreamDefaultReader<Uint8Array>,
Expand Down Expand Up @@ -835,7 +836,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
!(error instanceof RestateError) ||
error.code !== SUSPENDED_ERROR_CODE
) {
this.console.warn("Function completed with an error.\n", error);
this.vmLogger.warn("Invocation completed with an error.\n", error);
}
this.coreVm.notify_error(error.message, error.stack);

Expand Down
26 changes: 22 additions & 4 deletions packages/restate-sdk/src/endpoint/handlers/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ export class GenericHandler implements RestateHandler {
}
);

// Use a default logger that still respects the endpoint custom logger
// We will override this later with a logger that has a LoggerContext
// See vm_log below for more details
invocationLoggers.set(
loggerId,
createLogger(
this.endpoint.loggerTransport,
LogSource.JOURNAL,
undefined,
() => false
)
);

const inputReader = body.getReader();

// Now buffer input entries
Expand Down Expand Up @@ -290,14 +303,18 @@ export class GenericHandler implements RestateHandler {
);
const vmLogger = createLogger(
this.endpoint.loggerTransport,
LogSource.USER,
LogSource.JOURNAL,
loggerContext,
// Filtering is done within the shared core
() => false
);
// See vm_log below for more details
invocationLoggers.set(loggerId, vmLogger);
ctxLogger.info("Starting invocation.");
if (!coreVm.is_processing()) {
vmLogger.info("Replaying invocation.");
} else {
vmLogger.info("Starting invocation.");
}

// This promise is used to signal the end of the computation,
// which can be either the user returns a value,
Expand All @@ -316,6 +333,7 @@ export class GenericHandler implements RestateHandler {
input,
ctxLogger,
handler.kind(),
vmLogger,
invocationRequest,
invocationEndPromise,
inputReader,
Expand All @@ -328,15 +346,15 @@ export class GenericHandler implements RestateHandler {
.then((bytes) => {
coreVm.sys_write_output_success(bytes);
coreVm.sys_end();
ctxLogger.info("Invocation completed successfully.");
vmLogger.info("Invocation completed successfully.");
})
.catch((e) => {
const error = ensureError(e);
if (
!(error instanceof RestateError) ||
error.code !== SUSPENDED_ERROR_CODE
) {
ctxLogger.warn("Invocation completed with an error.\n", error);
vmLogger.warn("Invocation completed with an error.\n", error);
}

if (error instanceof TerminalError) {
Expand Down
Loading