0

We recently installed datadogRUM in our application and now so many DD events kick off in my cypress test that they cause a timeout and failure

I have tried cy.intercept in multiple ways:

 cy.intercept('POST', 'https://rum.browser-intake-datadoghq.com/*', {
       statusCode: 202,
       body: {
       },
     }).as('datadogRUM');

     cy.intercept('POST',  'https://rum-http-intake.logs.datadoghq.com/*',  {});

     cy.intercept(/\.*datadog.*$/, (req) => {
       console.log('DATADOG INTERCEPTED');
       req.reply("console.log('datadog intercept');");
     });

    cy.intercept({
      method: 'POST',
      url: '/\.*datadog.*$/'
    }, req => {
      req.destroy();
    });

    cy.intercept('POST',  'https://rum-http-intake.logs.datadoghq.com/*',  { forceNetworkError: true });

just to start. I feel like I've tried every possible variation. I also created a cypress.json file in my /cypress folder

{
"blockHosts": "*datadoghq.com/*"
}

I get hundreds of calls back in my network tab to https://rum.browser-intake-datadoghq.com/api/v2/rum with the preview of console.log('datadog intercept') as I've intercepted them. They all display the solid blue line as if they are being intercepted and blocked. When I set the intercept to an alias I see the alias in my cypress runner window. But there are no 503s or 404s anywhere. The page still fills up with events, cypress gets overloaded, and my test times out.

I even tried copying the data-dog-rum.ts from the src/utils folder to cypress/utils and either commenting out everything or setting the sampleRate to 0, no dice.

EDIT: I am able to get the test passing by adding

 
Cypress.on('uncaught:exception', () => {
  // returning false here prevents Cypress from
  // failing the test
  return false;
});

to my support/index.js but now whether I add a cy.intercept in my test makes absolutely no difference. The page still fills up with datadog requests regardless, and whether they come back as 200/pending/cancelled, they still delay a single it block in a spec to where it takes 60 seconds to run instead of approx 10 seconds

enter image description here

Pix81
  • 585
  • 3
  • 15
  • 33

1 Answers1

1

You can use javascript to perform the stub inside the routeHandler

cy.intercept('*', (req) => {  // look at everything
  if (req.url.includes('datadoghq')) {      // add more conditions if needed
    req.reply({})                           // prevent request reaching the server
  }
})

blockhosts should work with

Pass only the host

{
  "blockHosts": "*datadoghq.com"
}
TesterDick
  • 3,830
  • 5
  • 18
  • Sorry, still getting the same result :( – Pix81 Oct 06 '22 at 02:53
  • At least now you have a chance to examine the routes in javascript - it's easy to `console.log(req.url)` and see what is being captured. – TesterDick Oct 06 '22 at 03:17
  • If you are not seeing ***anything*** inside the route handler, then you're setting up the intercept too late in the test. – TesterDick Oct 06 '22 at 03:19
  • So the url printed out: https://rum.browser-intake-datadoghq.com/api/v2/rum?ddsource=browser&ddtags=sdk_version%etc.... truncating for proprietary information. I put the intercept in the beforeEach hook.I still see a little black box with white text that says something like 'Waiting for datadog...' and a lot of '[Violation] 'message' handler took ms' in my console – Pix81 Oct 06 '22 at 13:26
  • I also see about 13 POSTS with a 200 response for datadog before seeing the remaining POSTS in status of pending or cancelled – Pix81 Oct 06 '22 at 13:42
  • So, I'm getting the impression that `Waiting for datadog` means you are performing a `cy.wait()` on the intercept alias. Is there a reason for this? – TesterDick Oct 06 '22 at 18:38
  • Nope, definitely not putting a cy.wait() anywhere, it's an anti-pattern I try to avoid at all costs. I think that's probably coming from the source code? – Pix81 Oct 07 '22 at 23:18
  • 2
    Looks like you've confused `cy.wait()` with a fixed time to `cy.wait()` for an alias. Why would you use `.as('datadogRUM')` shown above if you are not going to wait for it? – TesterDick Oct 07 '22 at 23:50
  • Ah! Gotcha. Those are all separate ways I've tried to use cy.intercept. Let me know if one of them looks like could work if I tweaked it somehow. Cy.intercept doesn't seem that complicated, not sure why none of them work – Pix81 Oct 10 '22 at 14:27
  • So this is still a constant issue for me. Waiting does nothing and my cypress console still fills up with requests. Ex) cy.intercept({ method: 'POST', url: '/\.*datadog.*$/' }).as('datadog'); cy.wait('@datadog'); – Pix81 Nov 10 '22 at 18:46
  • @TesterDick can you clarify which files you are supposed to add this code to, and can do you have to do both things or only one? – NANfan Dec 02 '22 at 01:14