Skip to content

Conversation

@cosmastech
Copy link
Contributor

@cosmastech cosmastech commented Aug 12, 2025

This creates a new parameter for configuration: flush_failure_handler. This is a callable or null.

Why this is necessary: we see socket failures happen far too frequently, and it's very annoying to have to wrap each and every stat write in a try-catch. In our code, we can simply pass something like:

$statsClient = new DogStatsd([
  'flush_failure_handler' => static fn (Throwable $e) => Log::warning("Failure to flush metrics.", ['e' => $e])
]);

which will write an error to our logs and carry on.

See #168

@cosmastech cosmastech requested a review from a team as a code owner August 12, 2025 01:40
@cosmastech cosmastech marked this pull request as draft August 12, 2025 01:41
@cosmastech cosmastech marked this pull request as ready for review August 20, 2025 21:30
Copy link
Contributor

@StephenWakely StephenWakely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! I just have a small nit around the test...

}));

$this->getSocketSpy()->errorThrownOnSend = function () {
throw new ErrorException('ErrorException: socket_sendto(): Unable to write to socket [111]: Connection refused');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more accurate to call trigger_error with E_USER_WARNING here. PHPUnit has an error handler that then throws an ErrorException, so it amounts to the same thing, but just makes it a little clearer what is going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@StephenWakely StephenWakely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thank you.

@StephenWakely StephenWakely merged commit 295f750 into DataDog:master Aug 21, 2025
31 checks passed
@cosmastech cosmastech deleted the patch-1 branch August 21, 2025 13:15
@cosmastech
Copy link
Contributor Author

Nice. Thank you.

Thanks for the quick review and merge @StephenWakely 🙇 Do you know when we might expect this functionality to be released in a new version?

I want to make some updates to https://github.com/cosmastech/laravel-statsd-adapter as well as our production systems. 😃

@StephenWakely
Copy link
Contributor

@cosmastech It is now released. Thanks for your contribution!

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

Successfully merging this pull request may close these issues.

2 participants