fix(resource-timing): prevent feedback loop by adding ignoreUrls#248
fix(resource-timing): prevent feedback loop by adding ignoreUrls#248mquentin wants to merge 4 commits intoopen-telemetry:mainfrom
Conversation
… in case of regexParsing error and other isUrlIgnored side effect
| } catch { | ||
| this._diag.warn( | ||
| 'PerformanceObserver not supported, resource timings will not be collected', | ||
| ); | ||
| this._observer = undefined; |
There was a problem hiding this comment.
Since this is narrowed, consider making it more specific:
| } catch { | |
| this._diag.warn( | |
| 'PerformanceObserver not supported, resource timings will not be collected', | |
| ); | |
| this._observer = undefined; | |
| } catch (e) { | |
| this._diag.warn( | |
| 'Failed to start resource PerformanceObserver', e | |
| ); | |
| this._observer = undefined; |
There was a problem hiding this comment.
We could also log the actual error (using the diagnostics logger).
|
|
||
| /** | ||
| * URLs to ignore. Entries whose URL matches any of the patterns will not be | ||
| * captured. Strings are matched exactly; RegExps are tested against the full URL. |
There was a problem hiding this comment.
| * captured. Strings are matched exactly; RegExps are tested against the full URL. | |
| * captured. Strings are matched exactly; RegExps are matched against the full URL. |
| /** | ||
| * URLs to ignore. Entries whose URL matches any of the patterns will not be | ||
| * captured. Strings are matched exactly; RegExps are tested against the full URL. | ||
| * Avoid RegExps with the `g` or `y` flag — their stateful `lastIndex` causes |
There was a problem hiding this comment.
I think y here causes alternating matches, but not g
|
|
||
| /** | ||
| * URLs to ignore. Entries whose URL matches any of the patterns will not be | ||
| * captured. Strings are matched exactly; RegExps are tested against the full URL. |
There was a problem hiding this comment.
This says "matched exactly" but I think we should be a bit louder. Because OTel uses a strict equality, this is case-sensitive and not normalized so a trailing slash or query string reintroduces the loop.
Maybe suggest an example like[/\/v1\/traces$/, /\/v1\/logs$/] at the bottom.
| this._flush(); | ||
| } | ||
| this._pendingEntries.push(entry); | ||
| if (isUrlIgnored(entry.name, this._config.ignoreUrls)) { |
There was a problem hiding this comment.
If this throws because of a bad regex, then the instrumentation does not recover - _scheduleProcessing is never called, and also no log that this has happened. I would either wrap the isUrlIgnored in try/catch or at least log an error.
Which problem is this PR solving?
The resource timing instrumentation does not have ignored URL API like the other core instrumentation (cf. XMLHttpRequestInstrumentation, FetchInstrumentation)
As a result, when the SDK post the signals to intakes, it is caught as a resource which has a timing which create a new signal to post to intake...
This PR adds an ignoreURL API to the
ResourceTimingInstrumentationimplemented like the XMLHttpRequestInstrumentation one.I also configure this existing API for XMLHttpRequestInstrumentation, FetchInstrumentation and this new API for ResourceTimingInstrumentation in the Sandbox env to prevent infinite loop to happens.
Before
Screen.Recording.2026-04-27.at.08.42.17.mov
### After
Screen.Recording.2026-04-27.at.08.41.03.mov
Short description of the changes
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: