@squide/firefly 13.3.1 → 14.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,8 @@
1
1
  import type { Span } from "@opentelemetry/api";
2
2
  import {
3
+ type AddListenerOptions,
4
+ type EventCallbackFunction,
5
+ type EventName,
3
6
  LocalModuleDeferredRegistrationFailedEvent,
4
7
  LocalModuleDeferredRegistrationUpdateFailedEvent,
5
8
  LocalModuleRegistrationFailedEvent,
@@ -49,6 +52,25 @@ import { endActiveSpan, startActiveChildSpan, startChildSpan, startSpan, traceEr
49
52
  // TIPS:
50
53
  // To query those traces in Honeycomb, use the following query filter: "root.name = squide-bootstrapping".
51
54
 
55
+ interface AddProtectedListenerOptions extends AddListenerOptions {
56
+ onError?: (error: unknown) => void;
57
+ }
58
+
59
+ function addProtectedListener(runtime: FireflyRuntime, eventName: EventName, callback: EventCallbackFunction, options?: AddProtectedListenerOptions) {
60
+ const protectedCallback = (...args: unknown[]) => {
61
+ try {
62
+ callback(...args);
63
+ } catch (error: unknown) {
64
+ runtime.logger
65
+ .withText(`[squide] An unmanaged error occurred while handling event "${eventName.toString()}" for Honeycomb instrumentation:`)
66
+ .withError(error as Error)
67
+ .error();
68
+ }
69
+ };
70
+
71
+ runtime.eventBus.addListener(eventName, protectedCallback, options);
72
+ }
73
+
52
74
  type DataFetchState = "none" | "fetching-data" | "public-data-ready" | "protected-data-ready" | "data-ready" | "data-fetch-failed";
53
75
 
54
76
  export function reduceDataFetchEvents(
@@ -59,20 +81,24 @@ export function reduceDataFetchEvents(
59
81
  onPublicDataReady: () => void,
60
82
  onProtectedDataFetchStarted: () => void,
61
83
  onProtectedDataReady: () => void,
62
- onDataFetchFailed: (queriesErrors: Error[]) => void
84
+ onDataFetchFailed: (queriesErrors: Error[]) => void,
85
+ onUnmanagedError: (error: unknown) => void
63
86
  ) {
64
87
  let dataFetchState: DataFetchState = "none";
65
88
 
66
- runtime.eventBus.addListener(PublicDataFetchStartedEvent, () => {
89
+ addProtectedListener(runtime, PublicDataFetchStartedEvent, () => {
67
90
  if (dataFetchState === "none") {
68
91
  dataFetchState = "fetching-data";
69
92
  onDataFetchStarted();
70
93
  }
71
94
 
72
95
  onPublicDataFetchStarted();
73
- }, { once: true });
96
+ }, {
97
+ once: true,
98
+ onError: onUnmanagedError
99
+ });
74
100
 
75
- runtime.eventBus.addListener(PublicDataReadyEvent, payload => {
101
+ addProtectedListener(runtime, PublicDataReadyEvent, payload => {
76
102
  onPublicDataReady();
77
103
 
78
104
  if (dataFetchState === "fetching-data") {
@@ -86,18 +112,24 @@ export function reduceDataFetchEvents(
86
112
  dataFetchState = "data-ready";
87
113
  onDataReady();
88
114
  }
89
- }, { once: true });
115
+ }, {
116
+ once: true,
117
+ onError: onUnmanagedError
118
+ });
90
119
 
91
- runtime.eventBus.addListener(ProtectedDataFetchStartedEvent, () => {
120
+ addProtectedListener(runtime, ProtectedDataFetchStartedEvent, () => {
92
121
  if (dataFetchState === "none") {
93
122
  dataFetchState = "fetching-data";
94
123
  onDataFetchStarted();
95
124
  }
96
125
 
97
126
  onProtectedDataFetchStarted();
98
- }, { once: true });
127
+ }, {
128
+ once: true,
129
+ onError: onUnmanagedError
130
+ });
99
131
 
100
- runtime.eventBus.addListener(ProtectedDataReadyEvent, payload => {
132
+ addProtectedListener(runtime, ProtectedDataReadyEvent, payload => {
101
133
  onProtectedDataReady();
102
134
 
103
135
  if (dataFetchState === "fetching-data") {
@@ -111,7 +143,10 @@ export function reduceDataFetchEvents(
111
143
  dataFetchState = "data-ready";
112
144
  onDataReady();
113
145
  }
114
- }, { once: true });
146
+ }, {
147
+ once: true,
148
+ onError: onUnmanagedError
149
+ });
115
150
 
116
151
  const handleDataFetchFailed = (payload: unknown) => {
117
152
  if (dataFetchState !== "data-fetch-failed") {
@@ -121,12 +156,20 @@ export function reduceDataFetchEvents(
121
156
  }
122
157
  };
123
158
 
124
- runtime.eventBus.addListener(PublicDataFetchFailedEvent, handleDataFetchFailed, { once: true });
125
- runtime.eventBus.addListener(ProtectedDataFetchFailedEvent, handleDataFetchFailed, { once: true });
159
+ addProtectedListener(runtime, PublicDataFetchFailedEvent, handleDataFetchFailed, {
160
+ once: true,
161
+ onError: onUnmanagedError
162
+ });
163
+
164
+ addProtectedListener(runtime, ProtectedDataFetchFailedEvent, handleDataFetchFailed, {
165
+ once: true,
166
+ onError: onUnmanagedError
167
+ });
126
168
  }
127
169
 
128
170
  function registerTrackingListeners(runtime: FireflyRuntime) {
129
171
  let bootstrappingSpan: Span;
172
+ let bootstrappingSpanHasEnded: boolean = false;
130
173
  let localModuleRegistrationSpan: Span;
131
174
  let localModuleDeferredRegistrationSpan: Span;
132
175
  let remoteModuleRegistrationSpan: Span;
@@ -136,23 +179,74 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
136
179
  let localModuleDeferredRegistrationsUpdateSpan: ActiveSpan;
137
180
  let remoteModuleDeferredRegistrationsUpdateSpan: ActiveSpan;
138
181
 
139
- runtime.eventBus.addListener(ApplicationBootstrappingStartedEvent, () => {
182
+ const handleUnmanagedError = (error: unknown) => {
183
+ if (bootstrappingSpan && !bootstrappingSpanHasEnded) {
184
+ traceError(bootstrappingSpan, error as Error);
185
+
186
+ bootstrappingSpan.end();
187
+ bootstrappingSpanHasEnded = true;
188
+ }
189
+
190
+ if (localModuleRegistrationSpan) {
191
+ localModuleRegistrationSpan.end();
192
+ }
193
+
194
+ if (localModuleDeferredRegistrationSpan) {
195
+ localModuleDeferredRegistrationSpan.end();
196
+ }
197
+
198
+ if (remoteModuleRegistrationSpan) {
199
+ remoteModuleRegistrationSpan.end();
200
+ }
201
+
202
+ if (remoteModuleDeferredRegistrationSpan) {
203
+ remoteModuleDeferredRegistrationSpan.end();
204
+ }
205
+
206
+ if (dataFetchSpan) {
207
+ dataFetchSpan.instance.end();
208
+ }
209
+
210
+ if (deferredRegistrationsUpdateSpan) {
211
+ deferredRegistrationsUpdateSpan.end();
212
+ }
213
+
214
+ if (localModuleDeferredRegistrationsUpdateSpan) {
215
+ localModuleDeferredRegistrationsUpdateSpan.instance.end();
216
+ }
217
+
218
+ if (remoteModuleDeferredRegistrationsUpdateSpan) {
219
+ remoteModuleDeferredRegistrationsUpdateSpan.instance.end();
220
+ }
221
+ };
222
+
223
+ addProtectedListener(runtime, ApplicationBootstrappingStartedEvent, () => {
140
224
  bootstrappingSpan = startSpan((options, context) => getTracer().startSpan("squide-bootstrapping", options, context));
141
- }, { once: true });
225
+ }, {
226
+ once: true,
227
+ onError: handleUnmanagedError
228
+ });
142
229
 
143
- runtime.eventBus.addListener(ApplicationBoostrappedEvent, () => {
230
+ addProtectedListener(runtime, ApplicationBoostrappedEvent, () => {
144
231
  if (bootstrappingSpan) {
145
232
  bootstrappingSpan.end();
233
+ bootstrappingSpanHasEnded = true;
146
234
  }
147
- }, { once: true });
235
+ }, {
236
+ once: true,
237
+ onError: handleUnmanagedError
238
+ });
148
239
 
149
- runtime.eventBus.addListener(MswReadyEvent, () => {
240
+ addProtectedListener(runtime, MswReadyEvent, () => {
150
241
  if (bootstrappingSpan) {
151
242
  bootstrappingSpan.addEvent("msw-ready");
152
243
  }
153
- }, { once: true });
244
+ }, {
245
+ once: true,
246
+ onError: handleUnmanagedError
247
+ });
154
248
 
155
- runtime.eventBus.addListener(LocalModulesRegistrationStartedEvent, (payload: unknown) => {
249
+ addProtectedListener(runtime, LocalModulesRegistrationStartedEvent, (payload: unknown) => {
156
250
  const attributes = {
157
251
  "app.squide.module_count": (payload as LocalModulesRegistrationStartedEventPayload).moduleCount
158
252
  };
@@ -164,9 +258,12 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
164
258
  localModuleRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {
165
259
  return getTracer().startSpan("local-module-registration", { ...options, attributes }, context);
166
260
  });
167
- }, { once: true });
261
+ }, {
262
+ once: true,
263
+ onError: handleUnmanagedError
264
+ });
168
265
 
169
- runtime.eventBus.addListener(LocalModulesRegistrationCompletedEvent, (payload: unknown) => {
266
+ addProtectedListener(runtime, LocalModulesRegistrationCompletedEvent, (payload: unknown) => {
170
267
  if (bootstrappingSpan) {
171
268
  bootstrappingSpan.addEvent("local-module-registration-completed", {
172
269
  "app.squide.module_count": (payload as LocalModulesRegistrationCompletedEventPayload).moduleCount
@@ -176,18 +273,23 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
176
273
  if (localModuleRegistrationSpan) {
177
274
  localModuleRegistrationSpan.end();
178
275
  }
179
- }, { once: true });
276
+ }, {
277
+ once: true,
278
+ onError: handleUnmanagedError
279
+ });
180
280
 
181
281
  // Can occur multiple times.
182
- runtime.eventBus.addListener(LocalModuleRegistrationFailedEvent, (payload: unknown) => {
282
+ addProtectedListener(runtime, LocalModuleRegistrationFailedEvent, (payload: unknown) => {
183
283
  const registrationError = payload as ModuleRegistrationError;
184
284
 
185
285
  if (localModuleRegistrationSpan) {
186
286
  traceError(localModuleRegistrationSpan, registrationError);
187
287
  }
288
+ }, {
289
+ onError: handleUnmanagedError
188
290
  });
189
291
 
190
- runtime.eventBus.addListener(LocalModulesDeferredRegistrationStartedEvent, (payload: unknown) => {
292
+ addProtectedListener(runtime, LocalModulesDeferredRegistrationStartedEvent, (payload: unknown) => {
191
293
  const attributes = {
192
294
  "app.squide.registration_count": (payload as LocalModulesDeferredRegistrationStartedEventPayload).registrationCount
193
295
  };
@@ -199,9 +301,12 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
199
301
  localModuleDeferredRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {
200
302
  return getTracer().startSpan("local-module-deferred-registration", { ...options, attributes }, context);
201
303
  });
202
- }, { once: true });
304
+ }, {
305
+ once: true,
306
+ onError: handleUnmanagedError
307
+ });
203
308
 
204
- runtime.eventBus.addListener(LocalModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {
309
+ addProtectedListener(runtime, LocalModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {
205
310
  if (bootstrappingSpan) {
206
311
  bootstrappingSpan.addEvent("local-module-deferred-registration-completed", {
207
312
  "app.squide.registration_count": (payload as LocalModulesDeferredRegistrationCompletedEventPayload).registrationCount
@@ -211,18 +316,23 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
211
316
  if (localModuleDeferredRegistrationSpan) {
212
317
  localModuleDeferredRegistrationSpan.end();
213
318
  }
214
- }, { once: true });
319
+ }, {
320
+ once: true,
321
+ onError: handleUnmanagedError
322
+ });
215
323
 
216
324
  // Can occur multiple times.
217
- runtime.eventBus.addListener(LocalModuleDeferredRegistrationFailedEvent, (payload: unknown) => {
325
+ addProtectedListener(runtime, LocalModuleDeferredRegistrationFailedEvent, (payload: unknown) => {
218
326
  const registrationError = payload as ModuleRegistrationError;
219
327
 
220
328
  if (localModuleDeferredRegistrationSpan) {
221
329
  traceError(localModuleRegistrationSpan, registrationError);
222
330
  }
331
+ }, {
332
+ onError: handleUnmanagedError
223
333
  });
224
334
 
225
- runtime.eventBus.addListener(RemoteModulesRegistrationStartedEvent, (payload: unknown) => {
335
+ addProtectedListener(runtime, RemoteModulesRegistrationStartedEvent, (payload: unknown) => {
226
336
  const attributes = {
227
337
  "app.squide.remote_count": (payload as RemoteModulesRegistrationStartedEventPayload).remoteCount
228
338
  };
@@ -234,9 +344,12 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
234
344
  remoteModuleRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {
235
345
  return getTracer().startSpan("remote-module-registration", { ...options, attributes }, context);
236
346
  });
237
- }, { once: true });
347
+ }, {
348
+ once: true,
349
+ onError: handleUnmanagedError
350
+ });
238
351
 
239
- runtime.eventBus.addListener(RemoteModulesRegistrationCompletedEvent, (payload: unknown) => {
352
+ addProtectedListener(runtime, RemoteModulesRegistrationCompletedEvent, (payload: unknown) => {
240
353
  if (bootstrappingSpan) {
241
354
  bootstrappingSpan.addEvent("remote-module-registration-completed", {
242
355
  "app.squide.remote_count": (payload as RemoteModulesRegistrationCompletedEventPayload).remoteCount
@@ -246,18 +359,23 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
246
359
  if (remoteModuleRegistrationSpan) {
247
360
  remoteModuleRegistrationSpan.end();
248
361
  }
249
- }, { once: true });
362
+ }, {
363
+ once: true,
364
+ onError: handleUnmanagedError
365
+ });
250
366
 
251
367
  // Can occur multiple times.
252
- runtime.eventBus.addListener(RemoteModuleRegistrationFailedEvent, (payload: unknown) => {
368
+ addProtectedListener(runtime, RemoteModuleRegistrationFailedEvent, (payload: unknown) => {
253
369
  const registrationError = payload as RemoteModuleRegistrationError;
254
370
 
255
371
  if (remoteModuleRegistrationSpan) {
256
372
  traceError(remoteModuleRegistrationSpan, registrationError);
257
373
  }
374
+ }, {
375
+ onError: handleUnmanagedError
258
376
  });
259
377
 
260
- runtime.eventBus.addListener(RemoteModulesDeferredRegistrationStartedEvent, (payload: unknown) => {
378
+ addProtectedListener(runtime, RemoteModulesDeferredRegistrationStartedEvent, (payload: unknown) => {
261
379
  const attributes = {
262
380
  "app.squide.registration_count": (payload as RemoteModulesDeferredRegistrationStartedEventPayload).registrationCount
263
381
  };
@@ -269,9 +387,12 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
269
387
  remoteModuleDeferredRegistrationSpan = startChildSpan(bootstrappingSpan, (options, context) => {
270
388
  return getTracer().startSpan("remote-module-deferred-registration", { ...options, attributes }, context);
271
389
  });
272
- }, { once: true });
390
+ }, {
391
+ once: true,
392
+ onError: handleUnmanagedError
393
+ });
273
394
 
274
- runtime.eventBus.addListener(RemoteModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {
395
+ addProtectedListener(runtime, RemoteModulesDeferredRegistrationCompletedEvent, (payload: unknown) => {
275
396
  if (bootstrappingSpan) {
276
397
  bootstrappingSpan.addEvent("remote-module-deferred-registration-completed", {
277
398
  "app.squide.registration_count": (payload as RemoteModulesDeferredRegistrationCompletedEventPayload).registrationCount
@@ -281,15 +402,20 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
281
402
  if (remoteModuleDeferredRegistrationSpan) {
282
403
  remoteModuleDeferredRegistrationSpan.end();
283
404
  }
284
- }, { once: true });
405
+ }, {
406
+ once: true,
407
+ onError: handleUnmanagedError
408
+ });
285
409
 
286
410
  // Can occur multiple times.
287
- runtime.eventBus.addListener(RemoteModuleDeferredRegistrationFailedEvent, (payload: unknown) => {
411
+ addProtectedListener(runtime, RemoteModuleDeferredRegistrationFailedEvent, (payload: unknown) => {
288
412
  const registrationError = payload as RemoteModuleRegistrationError;
289
413
 
290
414
  if (remoteModuleDeferredRegistrationSpan) {
291
415
  traceError(remoteModuleDeferredRegistrationSpan, registrationError);
292
416
  }
417
+ }, {
418
+ onError: handleUnmanagedError
293
419
  });
294
420
 
295
421
  const handleFetchDataStarted = () => {
@@ -346,6 +472,7 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
346
472
  // will be aborted and a react-router error boundary will be rendered.
347
473
  if (bootstrappingSpan) {
348
474
  bootstrappingSpan.end();
475
+ bootstrappingSpanHasEnded = true;
349
476
  }
350
477
  }
351
478
  };
@@ -358,35 +485,46 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
358
485
  handlePublicDataReady,
359
486
  handleProtectedDataFetchStarted,
360
487
  handleProtectedDataReady,
361
- handleDataFetchFailed
488
+ handleDataFetchFailed,
489
+ handleUnmanagedError
362
490
  );
363
491
 
364
- runtime.eventBus.addListener(ModulesRegisteredEvent, () => {
492
+ addProtectedListener(runtime, ModulesRegisteredEvent, () => {
365
493
  if (bootstrappingSpan) {
366
494
  bootstrappingSpan.addEvent("modules-registered");
367
495
  }
368
- }, { once: true });
496
+ }, {
497
+ once: true,
498
+ onError: handleUnmanagedError
499
+ });
369
500
 
370
- runtime.eventBus.addListener(ModulesReadyEvent, () => {
501
+ addProtectedListener(runtime, ModulesReadyEvent, () => {
371
502
  if (bootstrappingSpan) {
372
503
  bootstrappingSpan.addEvent("modules-ready");
373
504
  }
374
- }, { once: true });
505
+ }, {
506
+ once: true,
507
+ onError: handleUnmanagedError
508
+ });
375
509
 
376
510
  // Can occur multiple times.
377
- runtime.eventBus.addListener(DeferredRegistrationsUpdateStartedEvent, () => {
511
+ addProtectedListener(runtime, DeferredRegistrationsUpdateStartedEvent, () => {
378
512
  deferredRegistrationsUpdateSpan = startSpan((options, context) => getTracer().startSpan("squide-deferred-registrations-update", options, context));
513
+ }, {
514
+ onError: handleUnmanagedError
379
515
  });
380
516
 
381
517
  // Can occur multiple times.
382
- runtime.eventBus.addListener(DeferredRegistrationsUpdateCompletedEvent, () => {
518
+ addProtectedListener(runtime, DeferredRegistrationsUpdateCompletedEvent, () => {
383
519
  if (deferredRegistrationsUpdateSpan) {
384
520
  deferredRegistrationsUpdateSpan.end();
385
521
  }
522
+ }, {
523
+ onError: handleUnmanagedError
386
524
  });
387
525
 
388
526
  // Can occur multiple times.
389
- runtime.eventBus.addListener(LocalModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {
527
+ addProtectedListener(runtime, LocalModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {
390
528
  const attributes = {
391
529
  "app.squide.registration_count": (payload as LocalModulesDeferredRegistrationsUpdateStartedEventPayload).registrationCount
392
530
  };
@@ -408,10 +546,12 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
408
546
  span
409
547
  };
410
548
  });
549
+ }, {
550
+ onError: handleUnmanagedError
411
551
  });
412
552
 
413
553
  // Can occur multiple times.
414
- runtime.eventBus.addListener(LocalModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {
554
+ addProtectedListener(runtime, LocalModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {
415
555
  if (deferredRegistrationsUpdateSpan) {
416
556
  deferredRegistrationsUpdateSpan.addEvent("local-module-deferred-registrations-update-completed", {
417
557
  "app.squide.registration_count": (payload as LocalModulesDeferredRegistrationsUpdateCompletedEventPayload).registrationCount
@@ -421,19 +561,23 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
421
561
  if (localModuleDeferredRegistrationsUpdateSpan) {
422
562
  endActiveSpan(localModuleDeferredRegistrationsUpdateSpan);
423
563
  }
564
+ }, {
565
+ onError: handleUnmanagedError
424
566
  });
425
567
 
426
568
  // Can occur multiple times.
427
- runtime.eventBus.addListener(LocalModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {
569
+ addProtectedListener(runtime, LocalModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {
428
570
  const registrationError = payload as ModuleRegistrationError;
429
571
 
430
572
  if (localModuleDeferredRegistrationsUpdateSpan) {
431
573
  traceError(localModuleDeferredRegistrationsUpdateSpan.instance, registrationError);
432
574
  }
575
+ }, {
576
+ onError: handleUnmanagedError
433
577
  });
434
578
 
435
579
  // Can occur multiple times.
436
- runtime.eventBus.addListener(RemoteModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {
580
+ addProtectedListener(runtime, RemoteModulesDeferredRegistrationsUpdateStartedEvent, (payload: unknown) => {
437
581
  const attributes = {
438
582
  "app.squide.registration_count": (payload as RemoteModulesDeferredRegistrationsUpdateStartedEventPayload).registrationCount
439
583
  };
@@ -455,10 +599,12 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
455
599
  span
456
600
  };
457
601
  });
602
+ }, {
603
+ onError: handleUnmanagedError
458
604
  });
459
605
 
460
606
  // Can occur multiple times.
461
- runtime.eventBus.addListener(RemoteModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {
607
+ addProtectedListener(runtime, RemoteModulesDeferredRegistrationsUpdateCompletedEvent, (payload: unknown) => {
462
608
  if (deferredRegistrationsUpdateSpan) {
463
609
  deferredRegistrationsUpdateSpan.addEvent("remote-module-deferred-registrations-update-completed", {
464
610
  "app.squide.registration_count": (payload as RemoteModulesDeferredRegistrationsUpdateCompletedEventPayload).registrationCount
@@ -468,15 +614,19 @@ function registerTrackingListeners(runtime: FireflyRuntime) {
468
614
  if (remoteModuleDeferredRegistrationsUpdateSpan) {
469
615
  endActiveSpan(remoteModuleDeferredRegistrationsUpdateSpan);
470
616
  }
617
+ }, {
618
+ onError: handleUnmanagedError
471
619
  });
472
620
 
473
621
  // Can occur multiple times.
474
- runtime.eventBus.addListener(RemoteModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {
622
+ addProtectedListener(runtime, RemoteModuleDeferredRegistrationUpdateFailedEvent, (payload: unknown) => {
475
623
  const registrationError = payload as RemoteModuleRegistrationError;
476
624
 
477
625
  if (remoteModuleDeferredRegistrationsUpdateSpan) {
478
626
  traceError(remoteModuleDeferredRegistrationsUpdateSpan.instance, registrationError);
479
627
  }
628
+ }, {
629
+ onError: handleUnmanagedError
480
630
  });
481
631
  }
482
632
 
@@ -496,19 +646,26 @@ function getRegisterFetchRequestHookFunction() {
496
646
  }
497
647
 
498
648
  export function registerHoneycombInstrumentation(runtime: FireflyRuntime) {
499
- const registerFetchRequestHookFunction = getRegisterFetchRequestHookFunction();
649
+ try {
650
+ const registerFetchRequestHookFunction = getRegisterFetchRequestHookFunction();
500
651
 
501
- if (registerFetchRequestHookFunction) {
502
- registerActiveSpanStack();
652
+ if (registerFetchRequestHookFunction) {
653
+ registerActiveSpanStack();
503
654
 
504
- const activeSpanOverrideFunction = createOverrideFetchRequestSpanWithActiveSpanContext(runtime.logger);
655
+ const activeSpanOverrideFunction = createOverrideFetchRequestSpanWithActiveSpanContext(runtime.logger);
505
656
 
506
- // Dynamically registering this request hook function to nest the HTTP requests
507
- // of squide bootstrapping under the appropriate Honeycomb span.
508
- registerFetchRequestHookFunction(activeSpanOverrideFunction);
509
- } else {
510
- runtime.logger.warning("[squide] Cannot register Honeycomb fetch request hook because \"globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK__\" is not available. Honeycomb instrumentation is still functional but in degraded mode.");
511
- }
657
+ // Dynamically registering this request hook function to nest the HTTP requests
658
+ // of squide bootstrapping under the appropriate Honeycomb span.
659
+ registerFetchRequestHookFunction(activeSpanOverrideFunction);
660
+ } else {
661
+ runtime.logger.warning("[squide] Cannot register Honeycomb fetch request hook because \"globalThis.__WLP_HONEYCOMB_REGISTER_DYNAMIC_FETCH_REQUEST_HOOK__\" is not available. Honeycomb instrumentation is still functional but in degraded mode.");
662
+ }
512
663
 
513
- registerTrackingListeners(runtime);
664
+ registerTrackingListeners(runtime);
665
+ } catch (error: unknown) {
666
+ runtime.logger
667
+ .withText("[squide] An error occurred while registering Honeycomb instrumentation:")
668
+ .withError(error as Error)
669
+ .error();
670
+ }
514
671
  }