newrelic / newrelic-browser-agent

New Relic Browser Agent
Apache License 2.0
77 stars 40 forks source link

fix: Unhandled promise rejection for session import #1088

Closed patrickhousley closed 3 months ago

patrickhousley commented 3 months ago

Fixing an issue where an unhandled promise rejection could be thrown from the agent when using the npm package if the session manager async chunk get blocked or fails to setup a session.

Overview

If the session manager chunk is blocked, the agent was throwing an unhandled promise rejection error and the agent was failing to harvest a lot of other data. To fix the issue, a check has been added to prevent the session trace aggregate initialize function from running.

This issue could also happen if the session entity or the session initialization code threw an exception. I have added an ierr for those scenarios so we and customers can get better clarity on if/when/why the session manager is failing.

Related Issue(s)

https://new-relic.atlassian.net/browse/NR-281861

1075

Testing

To test locally, use the vite-react-wrapper and block only the session manager chunk using browser dev tools. Before this change, you should see an unhandled promise rejection in the console logs and the agent will stop harvesting data for anything except page view, page timings, and supportability metrics. With this change, the agent should continue functioning normally but without an session trace harvests. There should also be an ierr reported in the first timeslice payload.

github-actions[bot] commented 3 months ago

Static Badge

Last ran on June 26, 2024 11:26:57 CDT Checking merge of (cb6e64f8020d211a29857abd14180110f53a0de9) into main (9bb69da2cde1ba9daa97e1a80d4f2b54dfeb2e25)

github-actions[bot] commented 3 months ago

Asset Size Report

Merging this pull request will result in the following asset size changes:

Agent Asset Previous Size New Size Diff
lite loader 34.67 kB / 12.11 kB (gzip) 34.73 kB / 12.13 kB (gzip) 0.18% / 0.15% (gzip)
lite async-chunk 50.03 kB / 16.16 kB (gzip) 50.09 kB / 16.18 kB (gzip) 0.12% / 0.15% (gzip)
pro loader 55.23 kB / 18.7 kB (gzip) 55.29 kB / 18.72 kB (gzip) 0.11% / 0.1% (gzip)
pro async-chunk 96.06 kB / 28.83 kB (gzip) 96.12 kB / 28.85 kB (gzip) 0.06% / 0.07% (gzip)
spa loader 63.17 kB / 21.14 kB (gzip) 63.23 kB / 21.15 kB (gzip) 0.1% / 0.07% (gzip)
spa async-chunk 111.17 kB / 33.21 kB (gzip) 111.23 kB / 33.23 kB (gzip) 0.05% / 0.08% (gzip)
lite-polyfills loader 128.36 kB / 41.43 kB (gzip) 128.42 kB / 41.46 kB (gzip) 0.05% / 0.07% (gzip)
lite-polyfills async-chunk 63.93 kB / 18.43 kB (gzip) 63.99 kB / 18.45 kB (gzip) 0.08% / 0.11% (gzip)
pro-polyfills loader 150.55 kB / 47.67 kB (gzip) 150.62 kB / 47.69 kB (gzip) 0.04% / 0.04% (gzip)
pro-polyfills async-chunk 116.14 kB / 31.06 kB (gzip) 116.19 kB / 31.08 kB (gzip) 0.05% / 0.07% (gzip)
spa-polyfills loader 158.75 kB / 49.83 kB (gzip) 158.81 kB / 49.85 kB (gzip) 0.04% / 0.03% (gzip)
spa-polyfills async-chunk 133.11 kB / 35.76 kB (gzip) 133.16 kB / 35.78 kB (gzip) 0.04% / 0.05% (gzip)
codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.62%. Comparing base (9bb69da) to head (cb6e64f).

Files Patch % Lines
src/features/utils/aggregate-base.js 75.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1088 +/- ## ========================================== - Coverage 87.66% 87.62% -0.04% ========================================== Files 162 162 Lines 7245 7249 +4 Branches 1420 1421 +1 ========================================== + Hits 6351 6352 +1 - Misses 778 781 +3 Partials 116 116 ``` | [Flag](https://app.codecov.io/gh/newrelic/newrelic-browser-agent/pull/1088/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | Coverage Δ | | |---|---|---| | [integration-tests](https://app.codecov.io/gh/newrelic/newrelic-browser-agent/pull/1088/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `91.49% <66.66%> (-0.06%)` | :arrow_down: | | [unit-tests](https://app.codecov.io/gh/newrelic/newrelic-browser-agent/pull/1088/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic) | `76.42% <80.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=newrelic#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.