@@ -246,7 +246,8 @@ void reportStartupError(kj::StringPtr id,
246246 ExceptionOrDuration limitErrorOrTime,
247247 v8::TryCatch& catcher,
248248 kj::Maybe<Worker::ValidationErrorReporter&> errorReporter,
249- kj::Maybe<kj::Exception>& permanentException) {
249+ kj::Maybe<kj::Exception>& permanentException,
250+ SpanParent parentSpan) {
250251 v8::TryCatch catcher2 (js.v8Isolate );
251252 ExceptionOrDuration limitErrorOrTime2 = 0 * kj::NANOSECONDS;
252253 try {
@@ -301,6 +302,10 @@ void reportStartupError(kj::StringPtr id,
301302 message.addJsStackTrace (js, lines);
302303 auto trace = kj::strArray (lines, " ; " );
303304 auto description = KJ_ASSERT_NONNULL (permanentException).getDescription ();
305+ auto span = parentSpan.newChild (" script_startup_exception" _kjc);
306+ span.addLog (kj::systemPreciseCalendarClock ().now (), " exception" _kjc,
307+ kj::ConstString (
308+ kj::str (" script startup threw exception" , id, description, trace)));
304309 KJ_LOG (ERROR, " script startup threw exception" , id, description, trace);
305310 KJ_FAIL_REQUIRE (" script startup threw exception" );
306311 }
@@ -1426,7 +1431,7 @@ Worker::Script::Script(kj::Own<const Isolate> isolateParam,
14261431 }
14271432 impl->configureDynamicImports (lock, *jsg::ModuleRegistry::from (lock));
14281433 isolate->getApi ().compileModules (
1429- lock, modulesSource, *isolate, kj::mv (artifacts), kj::mv ( parentSpan));
1434+ lock, modulesSource, *isolate, kj::mv (artifacts), parentSpan. addRef ( ));
14301435 }
14311436 impl->unboundScriptOrMainModule = kj::Path::parse (modulesSource.mainModule );
14321437 }
@@ -1440,7 +1445,8 @@ Worker::Script::Script(kj::Own<const Isolate> isolateParam,
14401445 }
14411446 } catch (const jsg::JsExceptionThrown&) {
14421447 reportStartupError (id, lock, isolate->impl ->inspector , isolate->getLimitEnforcer (),
1443- kj::mv (limitErrorOrTime), catcher, errorReporter, impl->permanentException );
1448+ kj::mv (limitErrorOrTime), catcher, errorReporter, impl->permanentException ,
1449+ parentSpan.addRef ());
14441450 }
14451451 });
14461452 });
@@ -1832,7 +1838,7 @@ Worker::Worker(kj::Own<const Script> scriptParam,
18321838 } catch (const jsg::JsExceptionThrown&) {
18331839 reportStartupError (script->id , lock, script->isolate ->impl ->inspector ,
18341840 script->isolate ->getLimitEnforcer (), kj::mv (limitErrorOrTime), catcher, errorReporter,
1835- impl->permanentException );
1841+ impl->permanentException , currentSpan );
18361842 }
18371843 });
18381844 });
0 commit comments