fix: defer UserInteractionInstrumentation enable() to prevent _spansData TypeError #SUPERLOG - #415
Open
superlog-app[bot] wants to merge 1 commit into
Open
Conversation
…ata TypeError #SUPERLOG Delivery-Id: 033b6f0846313157502d4e1668328725ba0669fa49896904a88d2afeb565a60f Delivery-Base: main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every page load of superlog.sh was triggering
TypeError: this._spansData is undefinedinsideUserInteractionInstrumentation._shouldCountTask. The error fired when theBatchSpanProcessorscheduled its batch-export timer (_maybeStartTimer → setTimeout) while execution was already inside aZoneContextManagerspan-context zone created byDocumentLoadInstrumentation._collectPerformance. Zone.js intercepted thesetTimeout, ran the patchedscheduleTask, found an active span in the zone, and called_shouldCountTask— wherethis._spansDatawasundefined.Root Cause
InstrumentationBase.constructor(from@opentelemetry/instrumentation@0.220.0) always callsthis.enable()inside its constructor, before the ES2022 class-field initializers of the derivedUserInteractionInstrumentationhave run.enable()capturesplugin = thisand patchesZone.prototype.scheduleTask; but_spansData = new WeakMap()is an instance class field that is only initialized aftersuper()returns. When the zone patch fires while inside the document-load context zone and reachesthis._spansData.get(currentSpan),_spansDataisundefinedand the error is thrown. The throw propagates through Zone.js towindow.onerror, where the newwindow.errorlistener (also added in this PR) reports it as abrowser.exceptionspan, creating the production incident.Fix: pass
{ enabled: false }toUserInteractionInstrumentation.InstrumentationBase.constructorthen skipsenable()during construction.registerInstrumentations()callsenable()after construction completes — at which point_spansDatais already the WeakMap — so the zone-patch closure captures a valid_spansData.This PR also brings
instrumentation.tsforward to include:browserTracerProvidervariable +forceFlush()on error reportingserviceVersionresource attribute (stamped by CI viaVITE_OTEL_SERVICE_VERSION)reportBrowserException()helper +window.error/unhandledrejectionlisteners for post-bootstrap crash captureAll of these additions were already deployed to production on a pre-merge branch and are being merged to
mainhere together with the_spansDatafix.Resolves incident ashen-hedgehog.
Was this PR helpful? Leave feedback — goes straight to the Superlog team.
Summary by cubic
Delay enabling of
UserInteractionInstrumentationto stop_spansData is undefinederrors during page load and prevent noisy browser exception reports.{ enabled: false }toUserInteractionInstrumentationsoregisterInstrumentations()enables it after class fields initialize, ensuring the zone patch sees a valid_spansData.setTimeoutduring document load from triggering aTypeErrorin_shouldCountTaskwhen a span is active.Written for commit 02276e2. Summary will update on new commits.