Skip to content

[BUG]: before:run event is not working with dd-trace-js #5496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mekhron opened this issue Mar 27, 2025 · 5 comments
Open

[BUG]: before:run event is not working with dd-trace-js #5496

mekhron opened this issue Mar 27, 2025 · 5 comments
Assignees
Labels
bug Something isn't working ci-app

Comments

@mekhron
Copy link

mekhron commented Mar 27, 2025

Tracer Version(s)

5.40.0

Node.js Version(s)

20.16.0

Bug Report

When I have return require('dd-trace/ci/cypress/plugin')(on, config); in config, my events are not firing. Whenever I return just the config, events are firing as expected.

Reproduction Code

No response

Error Logs

No response

Tracer Config

No response

Operating System

No response

Bundling

Unsure

@mekhron mekhron added the bug Something isn't working label Mar 27, 2025
@Mariovido Mariovido self-assigned this Apr 3, 2025
@Mariovido
Copy link
Contributor

Hi @mekhron, are you trying to run your tests in interactive mode? If so, we have a Known limitation for that type of case (Docs Datadog). If not, could you share a bit more info about how you're running the tests?

@mekhron
Copy link
Author

mekhron commented Apr 3, 2025

@Mariovido I am running either way. My before:run event is not firing even when I run in headless mode.

Here are the vents I have in cypress.config.js:

            on('before:run', () => {
                console.log('BEFORE RUN');
            });

            on('after:run', (details) => {
                console.log('AFTER RUN');
                // other 'after:run' handlers
                // important that this function call is returned
                return require('dd-trace/ci/cypress/after-run')(details);
            });

            on('after:spec', (...args) => {
                console.log('BEFORE SPEC');
                // other 'after:spec' handlers
                // Important that this function call is returned
                // Important that all the arguments are passed
                return require('dd-trace/ci/cypress/after-spec')(...args);
            });

So the dd-trace events are firing fine (after:run and after:spec), but the before:run is not logging anything.

Here is the command how I run: npx cypress run -e ENVIRONMENT=qa.

Thanks for taking a look at this.

@Mariovido
Copy link
Contributor

@mekhron I tried reproducing your case and I am able to log it (cypress run):

Code sample
module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      require("dd-trace/ci/cypress/plugin")(on, config);
      on("before:run", () => {
        console.log("BEFORE RUN");
      });
      // other plugins
      on("after:run", (details) => {
        console.log("AFTER RUN");
        // other 'after:run' handlers
        // important that this function call is returned
        return require("dd-trace/ci/cypress/after-run")(details);
      });
      on("after:spec", (...args) => {
        console.log("AFTER SPEC");
        // other 'after:spec' handlers
        // Important that this function call is returned
        // Important that all the arguments are passed
        return require("dd-trace/ci/cypress/after-spec")(...args);
      });
    },
    supportFile: "cypress/support/e2e.js",
  },
});

Which Cypress version are you using?

@mekhron
Copy link
Author

mekhron commented Apr 3, 2025

@Mariovido 14.2.1

@Mariovido
Copy link
Contributor

@mekhron I tried with that version and it worked. Let's do one thing, could you reach out to support to be able to share your logs? Mainly what I would like to see after is:

  • The tests running with DD_TRACE_DEBUG=1
  • Your cypress.config.js and support.js files and other configuration that may be interfering with the tests (removing sensitive info)
  • Snippet where the command is being run (GitHub Job,...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ci-app
Projects
None yet
Development

No branches or pull requests

2 participants