diff --git a/src/workerd/io/worker.c++ b/src/workerd/io/worker.c++ index 98c2ae019c4..75fcb3e5d31 100644 --- a/src/workerd/io/worker.c++ +++ b/src/workerd/io/worker.c++ @@ -1194,6 +1194,31 @@ Worker::Isolate::Isolate(kj::Own apiParam, v8::Local argument)> callback) -> v8::Maybe { try { auto& js = jsg::Lock::from(isolate); + + { + // TODO(soon): Hopefully this logging is temporary. We want to get an idea + // of where the cross request promises are being resolved just in general. + // To do so we need to try to capture a stack. We do so by creating an error + // object and logging it. + v8::HandleScope handleScope(isolate); + auto err = + v8::Exception::Error(js.str("Cross Request Promise Resolve"_kj)).As(); + jsg::check(err->Set(js.v8Context(), js.str("name"_kj), js.str("Warning"_kj))); + auto stack = jsg::check(err->Get(js.v8Context(), js.str("stack"_kj))); + auto msg = kj::str("NOSENTRY ", stack); + if (msg != "NOSENTRY Warning: Cross Request Promise Resolve") { + LOG_PERIODICALLY(WARNING, msg); + } else { + // If we get here, it means we don't have a useful JS stack trace. + // Either the stack trace limit was set to zero for some reason or + // this resolve/reject originated from inside the runtime where a + // JS stack trace is not available. Let's emit the warning with a + // C++ stack instead. + // TODO(review): Is this worthwhile? Does it give us enough useful signal? + LOG_PERIODICALLY(WARNING, kj::str(msg, "\n", kj::getStackTrace())); + } + } + // The promise tag is generally opaque except for right here. The tag // wraps an instanceof kj::Own, which wraps an atomically // refcounted pointer to the DeleteQueue for the correct isolate.