Skip to content

jsg::Lock::logWarning() and reportError() should send warnings/errors to tail workers #6073

@harrishancock

Description

@harrishancock

In JSG isolate setup, we only install a logging handler if an inspector is attached or we're running in --verbose mode. This makes jsg::Lock::logWarning() only go to those sinks, and not tail Workers, which differs from IoContext::logWarning()'s behavior.

Relatedly, errors reported via jsg::Lock::reportError() are clearly intended to go to tail workers if they are installed, but we only install an error handler callback when an inspector is attached:

if (impl->inspector != kj::none || ::kj::_::Debug::shouldLog(::kj::LogSeverity::INFO)) {
lock->setLoggerCallback([this](jsg::Lock& js, kj::StringPtr message) {
if (impl->inspector != kj::none) {
logMessage(js, static_cast<uint16_t>(cdp::LogType::WARNING), message);
}
KJ_LOG(INFO, "console warning", message);
});
lock->setErrorReporterCallback([this](jsg::Lock& js, kj::String desc,
const jsg::JsValue& error, const jsg::JsMessage& message) {
// Only add exception to trace when running within an I/O context with a tracer.
KJ_IF_SOME(ioContext, IoContext::tryCurrent()) {
KJ_IF_SOME(tracer, ioContext.getWorkerTracer()) {

Originally posted by @harrishancock in #6070 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions