Skip to content
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

Question: Hook for ECONNRESETS #3461

Open
somecho opened this issue Jan 22, 2025 · 2 comments
Open

Question: Hook for ECONNRESETS #3461

somecho opened this issue Jan 22, 2025 · 2 comments

Comments

@somecho
Copy link

somecho commented Jan 22, 2025

The afterResponse hook gets called when a VU receives a response. I want to emit a custom metric during ECONNRESET. In this case, afterResponse does not work since it does not get called. How do I get a hook called (to emit a custom metric or log a request body) after an ECONNRESET?

@hassy
Copy link
Member

hassy commented Jan 22, 2025

There's a scenario-level onError hook for use cases like this. It's not documented, but it's been in the codebase for a while now and is unlikely to be dropped in future (we try to stay backwards-compatible as much as possible). The relevant code is here: https://github.com/artilleryio/artillery/blob/main/packages/core/lib/engine_http.js#L1014

The signature is:

function myOnErrorHandler(error, requestParams, userContext, events, next) {
  events.emit('counter', `error.${error.name}`, 1);
  return next();
}

and it needs to be declared at scenario level:

scenarios:
  - name: my scenario
    onError: myOnErrorHandler
    flow:
      - get:
          url: "/"

@somecho
Copy link
Author

somecho commented Jan 23, 2025

Thank you! This works for me. I would be open to contributing documentation on this if there are any guidelines/instructions on how to contribute to Artillery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants