-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve testing of oapi exception handlers instrumentation
- Loading branch information
Showing
4 changed files
with
361 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
tests/integration/errors/test_oapi_uncaught_handled_exception_03.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
When a user exception handler unregisters itself as an exception handler when it handles uncaught exception, | ||
the agent should record the error and add error attributes on all spans leading to uncaught exception as | ||
well as the one throwing the exception. Error attributtes are not expected on the root span (because | ||
the exception has been handled) as well as on the span created for exception handler. | ||
*/ | ||
|
||
/*INI | ||
newrelic.distributed_tracing_enabled=1 | ||
newrelic.transaction_tracer.threshold = 0 | ||
newrelic.span_events_enabled=1 | ||
newrelic.code_level_metrics.enabled = 0 | ||
display_errors=1 | ||
log_errors=0 | ||
*/ | ||
|
||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "8.0", "<")) { | ||
die("skip: PHP < 8.0.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
|
||
/*EXPECT_ERROR_EVENTS | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": "??", | ||
"events_seen": 1 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"type": "TransactionError", | ||
"timestamp": "??", | ||
"error.class": "RuntimeException", | ||
"error.message": "Uncaught exception 'RuntimeException' with message 'Expected unexpected happened' in __FILE__:??", | ||
"transactionName": "OtherTransaction\/php__FILE__", | ||
"duration": "??", | ||
"nr.transactionGuid": "??", | ||
"guid": "??", | ||
"sampled": true, | ||
"priority": "??", | ||
"traceId": "??", | ||
"spanId": "??" | ||
}, | ||
{}, | ||
"??" | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
/*EXPECT_SPAN_EVENTS | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": 10000, | ||
"events_seen": 4 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"category": "generic", | ||
"type": "Span", | ||
"guid": "??", | ||
"traceId": "??", | ||
"transactionId": "??", | ||
"name": "OtherTransaction\/php__FILE__", | ||
"timestamp": "??", | ||
"duration": "??", | ||
"priority": "??", | ||
"sampled": true, | ||
"nr.entryPoint": true, | ||
"transaction.name": "OtherTransaction\/php__FILE__" | ||
}, | ||
{}, | ||
{} | ||
], | ||
[ | ||
{ | ||
"category": "generic", | ||
"type": "Span", | ||
"guid": "??", | ||
"traceId": "??", | ||
"transactionId": "??", | ||
"name": "Custom\/call_throw_it", | ||
"timestamp": "??", | ||
"duration": "??", | ||
"priority": "??", | ||
"sampled": true, | ||
"parentId": "??" | ||
}, | ||
{}, | ||
{ | ||
"error.message": "Uncaught exception 'RuntimeException' with message 'Expected unexpected happened' in __FILE__:??", | ||
"error.class": "RuntimeException" | ||
} | ||
], | ||
[ | ||
{ | ||
"category": "generic", | ||
"type": "Span", | ||
"guid": "??", | ||
"traceId": "??", | ||
"transactionId": "??", | ||
"name": "Custom\/throw_it", | ||
"timestamp": "??", | ||
"duration": "??", | ||
"priority": "??", | ||
"sampled": true, | ||
"parentId": "??" | ||
}, | ||
{}, | ||
{ | ||
"error.message": "Uncaught exception 'RuntimeException' with message 'Expected unexpected happened' in __FILE__:??", | ||
"error.class": "RuntimeException" | ||
} | ||
], | ||
[ | ||
{ | ||
"category": "generic", | ||
"type": "Span", | ||
"guid": "??", | ||
"traceId": "??", | ||
"transactionId": "??", | ||
"name": "Custom\/user_exception_handler_02", | ||
"timestamp": "??", | ||
"duration": "??", | ||
"priority": "??", | ||
"sampled": true, | ||
"parentId": "??" | ||
}, | ||
{}, | ||
{} | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
|
||
/*EXPECT_REGEX | ||
02 Handled uncaught exception | ||
*/ | ||
|
||
function user_exception_handler_01(Throwable $ex) { | ||
restore_exception_handler(); | ||
echo "01 Handled uncaught exception"; | ||
} | ||
|
||
function user_exception_handler_02(Throwable $ex) { | ||
restore_exception_handler(); | ||
echo "02 Handled uncaught exception"; | ||
} | ||
|
||
function throw_it() { | ||
throw new RuntimeException('Expected unexpected happened'); | ||
} | ||
|
||
function call_throw_it() { | ||
throw_it(); | ||
} | ||
|
||
set_exception_handler('user_exception_handler_01'); | ||
set_exception_handler('user_exception_handler_02'); | ||
|
||
call_throw_it(); |
180 changes: 180 additions & 0 deletions
180
tests/integration/errors/test_oapi_uncaught_handled_exception_04.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
When a user exception handler unregisters itself as an exception handler when it handles uncaught exception, | ||
the agent should record the error and add error attributes on all spans leading to uncaught exception as | ||
well as the one throwing the exception. Error attributtes are not expected on the root span (because | ||
the exception has been handled) as well as on the span created for exception handler. | ||
*/ | ||
|
||
/*INI | ||
newrelic.distributed_tracing_enabled=1 | ||
newrelic.transaction_tracer.threshold = 0 | ||
newrelic.span_events_enabled=1 | ||
newrelic.code_level_metrics.enabled = 0 | ||
display_errors=1 | ||
log_errors=0 | ||
*/ | ||
|
||
|
||
/*SKIPIF*/ | ||
/* | ||
<?php | ||
if (version_compare(PHP_VERSION, "7.4", "<")) { | ||
die("skip: PHP < 8.0.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
|
||
/*EXPECT_ERROR_EVENTS*/ | ||
/* | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": "??", | ||
"events_seen": 1 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"type": "TransactionError", | ||
"timestamp": "??", | ||
"error.class": "RuntimeException", | ||
"error.message": "Uncaught exception 'RuntimeException' with message 'Expected unexpected happened' in __FILE__:??", | ||
"transactionName": "OtherTransaction\/php__FILE__", | ||
"duration": "??", | ||
"nr.transactionGuid": "??", | ||
"guid": "??", | ||
"sampled": true, | ||
"priority": "??", | ||
"traceId": "??", | ||
"spanId": "??" | ||
}, | ||
{}, | ||
"??" | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
/*EXPECT_SPAN_EVENTS*/ | ||
/* | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": 10000, | ||
"events_seen": 4 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"category": "generic", | ||
"type": "Span", | ||
"guid": "??", | ||
"traceId": "??", | ||
"transactionId": "??", | ||
"name": "OtherTransaction\/php__FILE__", | ||
"timestamp": "??", | ||
"duration": "??", | ||
"priority": "??", | ||
"sampled": true, | ||
"nr.entryPoint": true, | ||
"transaction.name": "OtherTransaction\/php__FILE__" | ||
}, | ||
{}, | ||
{} | ||
], | ||
[ | ||
{ | ||
"category": "generic", | ||
"type": "Span", | ||
"guid": "??", | ||
"traceId": "??", | ||
"transactionId": "??", | ||
"name": "Custom\/call_throw_it", | ||
"timestamp": "??", | ||
"duration": "??", | ||
"priority": "??", | ||
"sampled": true, | ||
"parentId": "??" | ||
}, | ||
{}, | ||
{ | ||
"error.message": "Uncaught exception 'RuntimeException' with message 'Expected unexpected happened' in __FILE__:??", | ||
"error.class": "RuntimeException" | ||
} | ||
], | ||
[ | ||
{ | ||
"category": "generic", | ||
"type": "Span", | ||
"guid": "??", | ||
"traceId": "??", | ||
"transactionId": "??", | ||
"name": "Custom\/throw_it", | ||
"timestamp": "??", | ||
"duration": "??", | ||
"priority": "??", | ||
"sampled": true, | ||
"parentId": "??" | ||
}, | ||
{}, | ||
{ | ||
"error.message": "Uncaught exception 'RuntimeException' with message 'Expected unexpected happened' in __FILE__:??", | ||
"error.class": "RuntimeException" | ||
} | ||
], | ||
[ | ||
{ | ||
"category": "generic", | ||
"type": "Span", | ||
"guid": "??", | ||
"traceId": "??", | ||
"transactionId": "??", | ||
"name": "Custom\/user_exception_handler_02", | ||
"timestamp": "??", | ||
"duration": "??", | ||
"priority": "??", | ||
"sampled": true, | ||
"parentId": "??" | ||
}, | ||
{}, | ||
{} | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
|
||
/*EXPECT_REGEX | ||
Fatal error: Uncaught RuntimeException: Not able to handle, throwing another exception from handler | ||
*/ | ||
|
||
function user_exception_handler_01(Throwable $ex) { | ||
//restore_exception_handler(); | ||
echo "01 Handled uncaught exception"; | ||
} | ||
|
||
function user_exception_handler_02(Throwable $ex) { | ||
restore_exception_handler(); | ||
throw new RuntimeException("Not able to handle, throwing another exception from handler"); | ||
echo "Should never see this"; | ||
} | ||
|
||
function throw_it() { | ||
throw new RuntimeException('Expected unexpected happened'); | ||
} | ||
|
||
function call_throw_it() { | ||
throw_it(); | ||
} | ||
|
||
set_exception_handler('user_exception_handler_01'); | ||
set_exception_handler('user_exception_handler_02'); | ||
//restore_exception_handler(); | ||
|
||
call_throw_it(); |