Skip to content

Commit

Permalink
fix recording errors for PHPs 8.0+
Browse files Browse the repository at this point in the history
When user exception handler is installed it can call restore_exception_handler,
and that will reset is_exception_handler flag in the wraprec which will cause
the agent not to use the correct code path after user exception handler returns.
The information that `nr_php_instrument_func_end` is handling return from user
exception handler needs to be stored in the segment associated with the user
exception handler.
  • Loading branch information
lavarou committed Apr 12, 2024
1 parent b6191bd commit 12f8ce7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion agent/php_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,14 @@ static void nr_php_instrument_func_begin(NR_EXECUTE_PROTO) {
if (NULL == wraprec) {
return;
}

/* Store information that the segment is exception handler segment directly in
* the segment, because exception handler can call restore_exception_handler,
* and that will reset is_exception_handler flag in the wraprec */
if (wraprec->is_exception_handler) {
segment->is_exception_handler = 1;
}

/*
* If a function needs to have arguments modified, do so in
* nr_zend_call_oapi_special_before.
Expand Down Expand Up @@ -2027,7 +2035,7 @@ static void nr_php_instrument_func_end(NR_EXECUTE_PROTO) {

wraprec = segment->wraprec;

if (wraprec && wraprec->is_exception_handler) {
if (wraprec && segment->is_exception_handler) {
/*
* After running the exception handler segment, create an error from
* the exception it handled, and save the error in the transaction.
Expand Down
2 changes: 2 additions & 0 deletions axiom/nr_segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ typedef struct _nr_segment_t {
*/
void* wraprec; /* wraprec, if one is associated with this segment, to reduce
wraprec lookups */
int is_exception_handler; /* 1 if segment is associated with exception
handler, 0 otherwise */
#endif

} nr_segment_t;
Expand Down

0 comments on commit 12f8ce7

Please sign in to comment.