sentry
sentry copied to clipboard
Session Replays Not Working for Front End Errors in AspNetCore
Environment
SaaS (https://sentry.io/)
Steps to Reproduce
-
Create a new project in with visual studio as an AspNetCore Web App (Model-View-Controller):
-
Should have the following folder structure:
-
Create new project in Sentry with browser javascript:
- Add the following line of code to the header in the Views/Home/Shared/_Layout.cshtml file with the correct dsn number for that project:
- Add the following line of code to the Views/Home/Privacy.cshtml file to trigger an error that is sent to sentry:
- Run the solution and click on the Privacy tab at the top and the error will be triggered and sent to the Sentry project:
Expected Result
Since session replays are on by default with the loader script:
https://docs.sentry.io/platforms/javascript/install/loader/
This should trigger an Error with a session replay as we threw an error in the
After running it a few times however I do see a session replay in the normal replays but do not see any issues attached to that session replay.
Actual Result
Should be seeing it in this tab of the issue since it is an error but I do not:
Product Area
Replays
Link
No response
DSN
No response
Version
No response
Assigning to @getsentry/support for routing ⏲️
Routing to @getsentry/product-owners-replays for triage ⏲️
Could you check what's going on the console tab? Maybe there's an ad-blocker affecting things? That throw Error in JS you wrote, should end up as an error too. Do you get that error?
Also a link to Sentry would be helpful
Hello @bruno-garcia ,
Did you want a link to my sentry account? you wouldn't be able to access the issue with that though?
Yes, I do get that error being sent to sentry just without session replays:
For the console tab I don't see anything in the console tab when I debug it:
But I do see this in the output fort the debug in visual studio:
It seems to me that ASP.NET isn't playing a role there at all.
The page loads and within the render there's a JS error. But the JS SDK is initialized through the loader, and we do capture the JS error. But no Replay. Is there a Replay at all? If you go on the left nav and open Replay, anything there?
But I do see this in the output fort the debug in visual studio:
We'd need to see the logs of the SDK, those are in the browser console, not visual studio.
Hello @bruno-garcia @bitsandfoxes and @lforst ,
I actually do have session replays coming in:
but that is because I have the replaysSessionSampleRate set as 0.1 in the settings:
However, the replaysOnErrorSampleRate is set at 1 so should be getting session replays attached for all errors. Here are the current logs I'm getting from the browser console on edge:
Let me know if you need anything else. Thanks,
Karl
Could you enable debug mode (in the loader settings page):
Then on the browser console you'll see everything that's going on in the SDK. If you could paste that here that'll be very helpful debugging this
Hello @bruno-garcia & @bitsandfoxes ,
I turned the "Enable Debug Bundles & Logging" option in the gui. Here is what the dev tools console looks like:
Did you want me to click into to any of these specifically?
Thanks,
Karl
Thanks for those logs! Could you, for future reference, just paste the logs instead of screenshots? That'd make it way easier to read, thanks! I've create an internal repro and handed that over @lforst. Sorry! cc @mydea
Hello @bitsandfoxes ,
Sorry about that. Here is the full logs:
logger.js:75 Sentry Logger [log]: [Tracing] new activities count 1 logger.js:75 Sentry Logger [log]: [Tracing] Starting 'http.client' span on transaction 'GET http://localhost:57427/6da7461064b9415eb11cecb4c97521c0/browserLinkSignalR/negotiate?requestUrl=https%3A%2F%2Flocalhost%3A7107%2FHome%2FPrivacy&browserName=&userAgent=Mozilla%2F5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML%2C+like+Gecko)+Chrome%2F126.0.0.0+Safari%2F537.36+Edg%2F126.0.0.0&browserIdKey=window.browserLink.initializationData.browserId&browserId=7d2c-502d&clientProtocol=1.3&_=1719243442628' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Measurements] Adding TTFB logger.js:75 Sentry Logger [log]: [Tracing] popActivity a2f80f2f896252de logger.js:75 Sentry Logger [log]: [Tracing] new activities count 0 11Third-party cookie will be blocked in future Microsoft Edge versions as part of unpartitioned third-party cookie deprecation. logger.js:75 Sentry Logger [log]: [Tracing] finishing IdleTransaction 2024-06-24T15:37:23.640Z pageload logger.js:75 Sentry Logger [log]: [Measurements] Adding LCP logger.js:75 Sentry Logger [log]: [Tracing] Adding & adjusting spans using Performance API logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'unloadEvent' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'domContentLoadedEvent' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'loadEvent' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'connect' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'TLS/SSL' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'cache' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'DNS' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'request' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'browser' span on transaction 'response' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.script' span on transaction 'https://js.sentry-cdn.com/3af3a5aec7132f9f02ad65356829bbf4.min.js' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.link' span on transaction '/lib/bootstrap/dist/css/bootstrap.min.css' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.link' span on transaction '/css/site.css?v=pAGv4ietcJNk_EwsQZ5BN9-K4MuNYS2a9wl4Jw-q9D0' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.link' span on transaction '/MVCDefault.styles.css?v=QLxe_xl70ueyh7Ge6QWqxL-YI9DKlky6krU48J4F1Dw' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.script' span on transaction '/lib/jquery/dist/jquery.min.js' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.script' span on transaction '/lib/bootstrap/dist/js/bootstrap.bundle.min.js' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.script' span on transaction '/js/site.js?v=hRQyftXiu1lLX2P9Ly9xa4gHJgLeR1uGN5qegUobtGo' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.script' span on transaction '/_vs/browserLink' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.script' span on transaction '/_framework/aspnetcore-browser-refresh.js' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'resource.script' span on transaction 'https://browser.sentry-cdn.com/7.118.0/bundle.tracing.replay.debug.min.js' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'mark' span on transaction 'sentry-tracing-init' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Tracing] Starting 'paint' span on transaction 'first-paint' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Measurements] Adding FP logger.js:75 Sentry Logger [log]: [Tracing] Starting 'paint' span on transaction 'first-contentful-paint' (873640246887a31e). logger.js:75 Sentry Logger [log]: [Measurements] Adding FCP logger.js:75 Sentry Logger [log]: [Measurements] Adding TTFB Request Time logger.js:75 Sentry Logger [log]: [Measurements] Adding LCP Data logger.js:75 Sentry Logger [log]: [Tracing] flushing IdleTransaction logger.js:75 Sentry Logger [log]: [Measurements] Adding measurements to transaction { "ttfb": { "value": 19.099999994039536, "unit": "millisecond" }, "lcp": { "value": 228.59999999403954, "unit": "millisecond" }, "fp": { "value": 228.59999999403954, "unit": "millisecond" }, "fcp": { "value": 228.59999999403954, "unit": "millisecond" }, "connection.rtt": { "value": 50, "unit": "millisecond" }, "ttfb.requestTime": { "value": 9.700000002980232, "unit": "millisecond" } } logger.js:75 Sentry Logger [log]: [Tracing] Finishing pageload transaction: /Home/Privacy.
Hey @karl-gardner sorry for the delay here. The team will take a deeper look here soon 🙏
@bruno-garcia ,
Thanks for looking into it!
Hey, I looked some more into this and I think I can reproduce this. If an error is thrown before Sentry is loaded, the replay will not be correctly attached to it. This is not ideal, I'll look into how we can improve/fix this!
Looking into this some more, I think this is more of a fundamental problem we have right now. We only initialise replay in the next tick, to ensure we avoid certain race conditions. However, this means that any error immediately thrown will not be associated to the replay.
You'll see that everything works if you replace the error code with e.g. this:
<script>
setTimeout(() => {
throw new Error('test error here');
}, 1);
</script>
Because at this time the replay is loaded. I created a new issue to track this properly: https://github.com/getsentry/sentry-javascript/issues/12707
FWIW this is not related to ASPNetCore or even the loader, the same happens with a plain NPM setup.
We will fix this in an upcoming release of the SDK!
@mydea and @bruno-garcia ,
Tried it with the following
<script> setTimeout(() => { throw new Error('test error here'); }, 1000); </script>
This only worked with the 1,000 ms and not 1 ms for me. Wondering when the next release is for the SDK?
Thanks!
@karl-gardner likely tomorrow!
Hey, so we have fixed this, but only on v8 branch, which is not yet out for the Loader, sadly. We'll keep you posted about this when we release v8 for the loader!
As of now, you should be able to use it generally, the limitation is really just that it will not trigger replay for errors that happen more or less immediately at the page load - so obviously this is not ideal and will miss some stuff, but it should still work for other errors that happen once replay is loaded!
@mydea Should this be closed?