Allow passing the event hint to the captureException method and pass it down to the before_send callback - #1138
Conversation
|
Sorry for not answering your question, I forgot it (shame on me). I'm not sure I understand why you cannot set the data on the scope but you can on the event hint. As a side note, it looks like in the JS SDK you can set the |
That would work! For reference, how I solved this for us was a custom integration. class DebugExceptionIntegration extends AbstractErrorListenerIntegration {
/**
* {@inheritdoc}
*/
protected function captureException(HubInterface $hub, Throwable $exception): void {
$hub->withScope(function (Scope $scope) use ($hub, $exception): void {
$scope->addEventProcessor(\Closure::fromCallable([$this, 'addExceptionMechanismToEvent']));
if ($exception instanceof DebugException && $exception->hasDebugInfo()) {
$scope->setExtra('DebugInfo', $exception->getDebugInfoStr());
}
$hub->captureException($exception);
});
}Some background of why I opened this PROur previous error handler expected to get the exception at a similar time as It's possible I am still missing something and the $event does have access to the hint. If I missed It, I suspect other people would as well. tl;drAny way to access the actual exception object just before reporting would be great! |
That was the solution I was going to suggest you as soon as I realized that what I wrote before did not make sense because I confused the
And you were right. The key point is that we forgot to pass the hint to the callback like it's done in the JS SDK. If we did this, we would then be able fill the |
Will do! |
|
There will be a few things to take into account, more specifically the fact that the |
3991abd to
f3d9caf
Compare
f3d9caf to
64e8a7c
Compare
|
@ste93cry I seem to be hitting a weird CI issue with xdebug + code coverage. As you can see, the code changes would have no effect on these. However, I am failing CI on: Would you mind helping me out here? |
|
I believe it's because Xdebug 3 is not compatible with PHPUnit 7.5, but PHP 7.3.25 on Travis uses it. The issue was introduced with php-build/php-build@ac92f4e as a consequence of php-build/php-build#650 |
|
@ste93cry Thanks for the links. I was looking around for some breadcrumbs as to what happened. I saw your fix was merged. Would you mind re triggering a build on this pull? I don't see the option in Travis, I assume I don't have enough permission. |
The fix to revert updating Xdebug 3 on PHP versions lower than 8 has been discarded, I think you are confusing such fix with the one in PHP-Parser. At this point, since the update of PHPUnit is already done in the PR to support PHP8, my suggestion is to wait until it gets merged. Please also remember that these changes are not sufficient yet as you should add the hint to the |
|
|
|
@jarstelfox are you still interested in completing the work? Otherwise, would you mind if I do it for you? |
|
@ste93cry feel free to take it up. Sorry between work and the holidays, I forgot about this |
26d5d86 to
3d86432
Compare
|
Even if the CI is broken (until I merge Side note: I rebased on the wrong branch, in the tentative of fixing my mistake I lost your initial commit. I will anyway ensure to give you the proper credits for your contribution in the commit once it gets merged |
81a4698 to
2fc4530
Compare
Jean85
left a comment
There was a problem hiding this comment.
Sorry for making you backtrack again, but I fear that @ste93cry's suggestion was wrong: adding an argument to the interfaces is a breaking change and you correctly, but nearly (or all?) the implementing classes are final, so adding the argument there without func_get_arg() should be fine.
Do you agree @ste93cry?
Yes, I wasn't aware that adding an argument with a default value even though the signature is different from the interface was fine. I now changed the implementation to get rid of all the calls to |
stayallive
left a comment
There was a problem hiding this comment.
Looks great, thanks all, good addition 👍
6388f03 to
5f30f51
Compare
5f30f51 to
8870d57
Compare
I have a use case where we have extended Exception to have some extra data. Ex:
This is ideologically different from how sentry works. Namely, the behaviour is to wrap with a scope to be able to
$scope->setExtra('data', $data).I am not opposed to this at all. In fact, I like it better than our current approach.
However, I have issues being able to shim in the functionality I need at a global level, as I lose context of the exception right here.
With this change I can do something like:
The main reason for this pull is to allow us to shim our existing code.