sentry icon indicating copy to clipboard operation
sentry copied to clipboard

Session Replays Not Working for Front End Errors in AspNetCore

Open karl-gardner opened this issue 1 year ago • 12 comments

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

  1. Create a new project in with visual studio as an AspNetCore Web App (Model-View-Controller): image

  2. Should have the following folder structure: image

  3. Create new project in Sentry with browser javascript:

image

  1. 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:

image

  1. Add the following line of code to the Views/Home/Privacy.cshtml file to trigger an error that is sent to sentry:

image

  1. Run the solution and click on the Privacy tab at the top and the error will be triggered and sent to the Sentry project:

image

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

image

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:

image

Product Area

Replays

Link

No response

DSN

No response

Version

No response

karl-gardner avatar Jun 11 '24 16:06 karl-gardner

Assigning to @getsentry/support for routing ⏲️

getsantry[bot] avatar Jun 11 '24 16:06 getsantry[bot]

Routing to @getsentry/product-owners-replays for triage ⏲️

getsantry[bot] avatar Jun 13 '24 13:06 getsantry[bot]

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

bruno-garcia avatar Jun 13 '24 14:06 bruno-garcia

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:

image

For the console tab I don't see anything in the console tab when I debug it:

image

But I do see this in the output fort the debug in visual studio:

image

karl-gardner avatar Jun 13 '24 15:06 karl-gardner

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.

bruno-garcia avatar Jun 18 '24 08:06 bruno-garcia

Hello @bruno-garcia @bitsandfoxes and @lforst ,

I actually do have session replays coming in:

image

but that is because I have the replaysSessionSampleRate set as 0.1 in the settings:

image

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:

image

Let me know if you need anything else. Thanks,

Karl

karl-gardner avatar Jun 19 '24 16:06 karl-gardner

Could you enable debug mode (in the loader settings page): image

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

bruno-garcia avatar Jun 20 '24 08:06 bruno-garcia

Hello @bruno-garcia & @bitsandfoxes ,

I turned the "Enable Debug Bundles & Logging" option in the gui. Here is what the dev tools console looks like:

image image

Did you want me to click into to any of these specifically?

Thanks,

Karl

karl-gardner avatar Jun 20 '24 18:06 karl-gardner

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

bitsandfoxes avatar Jun 24 '24 12:06 bitsandfoxes

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.

karl-gardner avatar Jun 24 '24 15:06 karl-gardner

Hey @karl-gardner sorry for the delay here. The team will take a deeper look here soon 🙏

bruno-garcia avatar Jun 28 '24 19:06 bruno-garcia

@bruno-garcia ,

Thanks for looking into it!

karl-gardner avatar Jun 29 '24 15:06 karl-gardner

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!

mydea avatar Jul 01 '24 08:07 mydea

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.

mydea avatar Jul 01 '24 08:07 mydea

We will fix this in an upcoming release of the SDK!

mydea avatar Jul 02 '24 09:07 mydea

@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 avatar Jul 03 '24 14:07 karl-gardner

@karl-gardner likely tomorrow!

lforst avatar Jul 03 '24 16:07 lforst

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 avatar Jul 04 '24 11:07 mydea

@mydea Should this be closed?

cmanallen avatar Dec 09 '24 15:12 cmanallen