From 0fcbec7ae03c99126e4f3de7f7097febdd780e1d Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 17 Aug 2023 15:23:29 -0700 Subject: [PATCH 01/35] chore(tests): Convert forked PR branch to main repo branch. So the ci/cd will run... --- src/newrelic/integration/parse.go | 30 ++ src/newrelic/integration/test.go | 11 +- tests/integration/jit/function/skipif.inc | 16 + .../jit/function/test_computations.php | 78 +++++ .../jit/function/test_even_odd_count.php | 84 ++++++ .../function/test_recursion_no_segfault.php | 55 ++++ .../jit/function/test_span_class_function.php | 277 ++++++++++++++++++ ..._span_events_are_created_from_segments.php | 118 ++++++++ ...n_events_are_created_upon_caught_error.php | 161 ++++++++++ ...ents_are_created_upon_caught_exception.php | 142 +++++++++ ...test_span_events_are_created_upon_exit.php | 123 ++++++++ ...events_are_created_upon_uncaught_error.php | 133 +++++++++ ...ts_are_created_upon_uncaught_exception.php | 136 +++++++++ ...t_span_events_error_collector_disabled.php | 127 ++++++++ ...st_span_events_exception_caught_nested.php | 217 ++++++++++++++ ...vents_exception_caught_nested_rethrown.php | 196 +++++++++++++ ...n_events_exception_caught_notice_error.php | 169 +++++++++++ ...s_exception_caught_notice_error_nested.php | 245 ++++++++++++++++ ...span_events_exception_caught_same_span.php | 139 +++++++++ ..._span_events_exception_uncaught_nested.php | 224 ++++++++++++++ ...est_span_events_exist_when_no_segments.php | 65 ++++ .../function/test_span_events_hsm_error.php | 137 +++++++++ .../test_span_events_notice_error.php | 157 ++++++++++ .../test_span_events_on_dt_off_cat_off.php | 50 ++++ .../test_span_events_on_dt_off_cat_on.php | 50 ++++ .../function/test_span_events_root_parent.php | 140 +++++++++ tests/integration/jit/tracing/skipif.inc | 17 ++ .../jit/tracing/test_computations.php | 77 +++++ .../jit/tracing/test_even_odd_count.php | 84 ++++++ .../tracing/test_recursion_no_segfault.php | 55 ++++ .../jit/tracing/test_span_class_function.php | 276 +++++++++++++++++ ..._span_events_are_created_from_segments.php | 118 ++++++++ ...n_events_are_created_upon_caught_error.php | 161 ++++++++++ ...ents_are_created_upon_caught_exception.php | 142 +++++++++ ...test_span_events_are_created_upon_exit.php | 123 ++++++++ ...events_are_created_upon_uncaught_error.php | 133 +++++++++ ...ts_are_created_upon_uncaught_exception.php | 136 +++++++++ ...t_span_events_error_collector_disabled.php | 127 ++++++++ ...st_span_events_exception_caught_nested.php | 217 ++++++++++++++ ...vents_exception_caught_nested_rethrown.php | 196 +++++++++++++ ...n_events_exception_caught_notice_error.php | 169 +++++++++++ ...s_exception_caught_notice_error_nested.php | 246 ++++++++++++++++ ...span_events_exception_caught_same_span.php | 139 +++++++++ ..._span_events_exception_uncaught_nested.php | 225 ++++++++++++++ ...est_span_events_exist_when_no_segments.php | 65 ++++ .../tracing/test_span_events_hsm_error.php | 137 +++++++++ .../tracing/test_span_events_notice_error.php | 157 ++++++++++ .../test_span_events_on_dt_off_cat_off.php | 50 ++++ .../test_span_events_on_dt_off_cat_on.php | 50 ++++ .../tracing/test_span_events_root_parent.php | 140 +++++++++ 50 files changed, 6516 insertions(+), 4 deletions(-) create mode 100644 tests/integration/jit/function/skipif.inc create mode 100644 tests/integration/jit/function/test_computations.php create mode 100644 tests/integration/jit/function/test_even_odd_count.php create mode 100644 tests/integration/jit/function/test_recursion_no_segfault.php create mode 100644 tests/integration/jit/function/test_span_class_function.php create mode 100644 tests/integration/jit/function/test_span_events_are_created_from_segments.php create mode 100644 tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php create mode 100644 tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php create mode 100644 tests/integration/jit/function/test_span_events_are_created_upon_exit.php create mode 100644 tests/integration/jit/function/test_span_events_are_created_upon_uncaught_error.php create mode 100644 tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php create mode 100644 tests/integration/jit/function/test_span_events_error_collector_disabled.php create mode 100644 tests/integration/jit/function/test_span_events_exception_caught_nested.php create mode 100644 tests/integration/jit/function/test_span_events_exception_caught_nested_rethrown.php create mode 100644 tests/integration/jit/function/test_span_events_exception_caught_notice_error.php create mode 100644 tests/integration/jit/function/test_span_events_exception_caught_notice_error_nested.php create mode 100644 tests/integration/jit/function/test_span_events_exception_caught_same_span.php create mode 100644 tests/integration/jit/function/test_span_events_exception_uncaught_nested.php create mode 100644 tests/integration/jit/function/test_span_events_exist_when_no_segments.php create mode 100644 tests/integration/jit/function/test_span_events_hsm_error.php create mode 100644 tests/integration/jit/function/test_span_events_notice_error.php create mode 100644 tests/integration/jit/function/test_span_events_on_dt_off_cat_off.php create mode 100644 tests/integration/jit/function/test_span_events_on_dt_off_cat_on.php create mode 100644 tests/integration/jit/function/test_span_events_root_parent.php create mode 100644 tests/integration/jit/tracing/skipif.inc create mode 100644 tests/integration/jit/tracing/test_computations.php create mode 100644 tests/integration/jit/tracing/test_even_odd_count.php create mode 100644 tests/integration/jit/tracing/test_recursion_no_segfault.php create mode 100644 tests/integration/jit/tracing/test_span_class_function.php create mode 100644 tests/integration/jit/tracing/test_span_events_are_created_from_segments.php create mode 100644 tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php create mode 100644 tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php create mode 100644 tests/integration/jit/tracing/test_span_events_are_created_upon_exit.php create mode 100644 tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_error.php create mode 100644 tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php create mode 100644 tests/integration/jit/tracing/test_span_events_error_collector_disabled.php create mode 100644 tests/integration/jit/tracing/test_span_events_exception_caught_nested.php create mode 100644 tests/integration/jit/tracing/test_span_events_exception_caught_nested_rethrown.php create mode 100644 tests/integration/jit/tracing/test_span_events_exception_caught_notice_error.php create mode 100644 tests/integration/jit/tracing/test_span_events_exception_caught_notice_error_nested.php create mode 100644 tests/integration/jit/tracing/test_span_events_exception_caught_same_span.php create mode 100644 tests/integration/jit/tracing/test_span_events_exception_uncaught_nested.php create mode 100644 tests/integration/jit/tracing/test_span_events_exist_when_no_segments.php create mode 100644 tests/integration/jit/tracing/test_span_events_hsm_error.php create mode 100644 tests/integration/jit/tracing/test_span_events_notice_error.php create mode 100644 tests/integration/jit/tracing/test_span_events_on_dt_off_cat_off.php create mode 100644 tests/integration/jit/tracing/test_span_events_on_dt_off_cat_on.php create mode 100644 tests/integration/jit/tracing/test_span_events_root_parent.php diff --git a/src/newrelic/integration/parse.go b/src/newrelic/integration/parse.go index 43af09391..c7123daff 100644 --- a/src/newrelic/integration/parse.go +++ b/src/newrelic/integration/parse.go @@ -23,6 +23,7 @@ var ( "HEADERS": parseHeaders, "SKIPIF": parseRawSkipIf, "INI": parseSettings, + "PHPMODULES": parsePHPModules, "CONFIG": parseConfig, "DESCRIPTION": parseDescription, "EXPECT_ANALYTICS_EVENTS": parseAnalyticEvents, @@ -195,6 +196,35 @@ func parseSettings(t *Test, content []byte) error { return nil } +func parsePHPModules(t *Test, content []byte) error { + trimmed := bytes.TrimSpace(content) + settings := make(map[string]string) + scanner := bufio.NewScanner(bytes.NewReader(trimmed)) + delim := []byte("=") + + for scanner.Scan() { + parts := bytes.SplitN(scanner.Bytes(), delim, 2) + switch len(parts) { + case 2: + key, value := bytes.TrimSpace(parts[0]), bytes.TrimSpace(parts[1]) + if len(key) > 0 { + settings[string(key)] = string(value) + } else { + return errBadSetting + } + case 1: + return errBadSetting + } + } + + if err := scanner.Err(); err != nil { + return err + } + t.PhpModules = settings + return nil +} + + func parseAnalyticEvents(test *Test, content []byte) error { test.analyticEvents = content return nil diff --git a/src/newrelic/integration/test.go b/src/newrelic/integration/test.go index 14d66bddc..3aaa98e0f 100644 --- a/src/newrelic/integration/test.go +++ b/src/newrelic/integration/test.go @@ -50,10 +50,11 @@ type Test struct { // Raw parsed test information used to construct the Tx. // The settings and env do not include global env and // global settings. - rawSkipIf []byte - Env map[string]string - Settings map[string]string - headers http.Header + rawSkipIf []byte + Env map[string]string + Settings map[string]string + PhpModules map[string]string + headers http.Header // When non-empty describes why failed should be true after the test // is run. This field may be set in the test definition to indicate @@ -194,6 +195,8 @@ func (t *Test) MakeRun(ctx *Context) (Tx, error) { } } + settings = merge(settings, t.PhpModules) + if t.IsC() { return CTx(ScriptFile(t.Path), env, settings, headers, ctx) } diff --git a/tests/integration/jit/function/skipif.inc b/tests/integration/jit/function/skipif.inc new file mode 100644 index 000000000..c7f0ce357 --- /dev/null +++ b/tests/integration/jit/function/skipif.inc @@ -0,0 +1,16 @@ +functionName(); + } +} + +for($i = 0; $i < 5; ++$i){ + new LittleClass; +} +echo "OK\n"; diff --git a/tests/integration/jit/function/test_span_events_are_created_from_segments.php b/tests/integration/jit/function/test_span_events_are_created_from_segments.php new file mode 100644 index 000000000..b543794bd --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_from_segments.php @@ -0,0 +1,118 @@ + 'FakeDB', +)); diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php new file mode 100644 index 000000000..7eb35c819 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php @@ -0,0 +1,161 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php new file mode 100644 index 000000000..13e09a87b --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php @@ -0,0 +1,142 @@ + 'FakeDB', + ) +); + +try { +a(); +} catch (RuntimeException $e) { +} diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_exit.php b/tests/integration/jit/function/test_span_events_are_created_upon_exit.php new file mode 100644 index 000000000..3274bf154 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_exit.php @@ -0,0 +1,123 @@ + 'FakeDB', + ) +); +a(); diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_error.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_error.php new file mode 100644 index 000000000..c3f064b6d --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_error.php @@ -0,0 +1,133 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php new file mode 100644 index 000000000..3c0744dbf --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php @@ -0,0 +1,136 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_error_collector_disabled.php b/tests/integration/jit/function/test_span_events_error_collector_disabled.php new file mode 100644 index 000000000..08a872629 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_error_collector_disabled.php @@ -0,0 +1,127 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_exception_caught_nested.php b/tests/integration/jit/function/test_span_events_exception_caught_nested.php new file mode 100644 index 000000000..2433f1289 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_nested.php @@ -0,0 +1,217 @@ +getMessage() . "\n"); + } +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +b(); diff --git a/tests/integration/jit/function/test_span_events_exception_caught_nested_rethrown.php b/tests/integration/jit/function/test_span_events_exception_caught_nested_rethrown.php new file mode 100644 index 000000000..036b6a55e --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_nested_rethrown.php @@ -0,0 +1,196 @@ +getMessage()); + } +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +b(); diff --git a/tests/integration/jit/function/test_span_events_exception_caught_notice_error.php b/tests/integration/jit/function/test_span_events_exception_caught_notice_error.php new file mode 100644 index 000000000..202479b19 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_notice_error.php @@ -0,0 +1,169 @@ +getMessage() . "\n"); + } + newrelic_notice_error(new Exception('Notice me')); +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +fraction(); diff --git a/tests/integration/jit/function/test_span_events_exception_caught_notice_error_nested.php b/tests/integration/jit/function/test_span_events_exception_caught_notice_error_nested.php new file mode 100644 index 000000000..f182090d3 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_notice_error_nested.php @@ -0,0 +1,245 @@ +getMessage() . "\n"); + } + newrelic_notice_error(new Exception('Notice me')); +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +b(); diff --git a/tests/integration/jit/function/test_span_events_exception_caught_same_span.php b/tests/integration/jit/function/test_span_events_exception_caught_same_span.php new file mode 100644 index 000000000..943b908ba --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_caught_same_span.php @@ -0,0 +1,139 @@ +getMessage() . "\n"); + } +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +fraction(); diff --git a/tests/integration/jit/function/test_span_events_exception_uncaught_nested.php b/tests/integration/jit/function/test_span_events_exception_uncaught_nested.php new file mode 100644 index 000000000..d3c317994 --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exception_uncaught_nested.php @@ -0,0 +1,224 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_exist_when_no_segments.php b/tests/integration/jit/function/test_span_events_exist_when_no_segments.php new file mode 100644 index 000000000..ce7cb296f --- /dev/null +++ b/tests/integration/jit/function/test_span_events_exist_when_no_segments.php @@ -0,0 +1,65 @@ +functionName(); + } +} + +for($i = 0; $i < 5; ++$i){ + new LittleClass; +} +echo "OK\n"; diff --git a/tests/integration/jit/tracing/test_span_events_are_created_from_segments.php b/tests/integration/jit/tracing/test_span_events_are_created_from_segments.php new file mode 100644 index 000000000..cc2a52753 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_from_segments.php @@ -0,0 +1,118 @@ + 'FakeDB', +)); diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php new file mode 100644 index 000000000..c01951750 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php @@ -0,0 +1,161 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php new file mode 100644 index 000000000..0b4444679 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php @@ -0,0 +1,142 @@ + 'FakeDB', + ) +); + +try { +a(); +} catch (RuntimeException $e) { +} \ No newline at end of file diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_exit.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_exit.php new file mode 100644 index 000000000..176730a7f --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_exit.php @@ -0,0 +1,123 @@ + 'FakeDB', + ) +); +a(); diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_error.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_error.php new file mode 100644 index 000000000..ee1a578ae --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_error.php @@ -0,0 +1,133 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php new file mode 100644 index 000000000..6141bdef4 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php @@ -0,0 +1,136 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php b/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php new file mode 100644 index 000000000..5cb38dcc3 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php @@ -0,0 +1,127 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_nested.php b/tests/integration/jit/tracing/test_span_events_exception_caught_nested.php new file mode 100644 index 000000000..4ff854cf2 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_nested.php @@ -0,0 +1,217 @@ +getMessage() . "\n"); + } +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +b(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_nested_rethrown.php b/tests/integration/jit/tracing/test_span_events_exception_caught_nested_rethrown.php new file mode 100644 index 000000000..1ec6df51b --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_nested_rethrown.php @@ -0,0 +1,196 @@ +getMessage()); + } +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +b(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error.php b/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error.php new file mode 100644 index 000000000..5b42d5280 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error.php @@ -0,0 +1,169 @@ +getMessage() . "\n"); + } + newrelic_notice_error(new Exception('Notice me')); +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +fraction(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error_nested.php b/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error_nested.php new file mode 100644 index 000000000..aaeb5a278 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_notice_error_nested.php @@ -0,0 +1,246 @@ +getMessage() . "\n"); + } + newrelic_notice_error(new Exception('Notice me')); +} + +function fraction($x) { + time_nanosleep(0, 100000000); + if (!$x) { + throw new RuntimeException('Division by zero'); + } + return 1/$x; +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +b(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_caught_same_span.php b/tests/integration/jit/tracing/test_span_events_exception_caught_same_span.php new file mode 100644 index 000000000..d92e22d16 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_caught_same_span.php @@ -0,0 +1,139 @@ +getMessage() . "\n"); + } +} + +function a() +{ + time_nanosleep(0, 100000000); + echo "Hello\n"; +}; + +a(); +fraction(); diff --git a/tests/integration/jit/tracing/test_span_events_exception_uncaught_nested.php b/tests/integration/jit/tracing/test_span_events_exception_uncaught_nested.php new file mode 100644 index 000000000..d352b174e --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exception_uncaught_nested.php @@ -0,0 +1,225 @@ + 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_exist_when_no_segments.php b/tests/integration/jit/tracing/test_span_events_exist_when_no_segments.php new file mode 100644 index 000000000..a3c7c6a11 --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_exist_when_no_segments.php @@ -0,0 +1,65 @@ + Date: Thu, 17 Aug 2023 16:59:09 -0700 Subject: [PATCH 02/35] fix(tests): test_span_class_function fix. --- .../jit/function/test_span_class_function.php | 11 ++++++----- .../jit/tracing/test_span_class_function.php | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/integration/jit/function/test_span_class_function.php b/tests/integration/jit/function/test_span_class_function.php index cd4b34d5b..5dbce791c 100644 --- a/tests/integration/jit/function/test_span_class_function.php +++ b/tests/integration/jit/function/test_span_class_function.php @@ -237,7 +237,7 @@ */ /*EXPECT -HelloHelloHelloOK +HelloHelloHellofunctionNamefunctionNamefunctionNamefunctionNamefunctionNameOK */ newrelic_add_custom_tracer('main'); @@ -253,10 +253,11 @@ function main() abstract class Classname{ protected function functionName() : void { - for($i = 0; $i < 500; ++$i){ - /* Spin wheels. */ - $x = 10 + 10; - } + echo 'functionName'; + for($i = 0; $i < 500; ++$i) { + /* Spin wheels. */ + $x = 10 + 10; + } } final public function __destruct(){ diff --git a/tests/integration/jit/tracing/test_span_class_function.php b/tests/integration/jit/tracing/test_span_class_function.php index f3ece5eb1..835d7649a 100644 --- a/tests/integration/jit/tracing/test_span_class_function.php +++ b/tests/integration/jit/tracing/test_span_class_function.php @@ -236,7 +236,7 @@ */ /*EXPECT -HelloHelloHelloOK +HelloHelloHellofunctionNamefunctionNamefunctionNamefunctionNamefunctionNameOK */ newrelic_add_custom_tracer('main'); @@ -252,12 +252,12 @@ function main() abstract class Classname{ protected function functionName() : void { - for($i = 0; $i < 500; ++$i){ - /* Spin wheels. */ - $x = 10 + 10; + echo 'functionName'; + for($i = 0; $i < 500; ++$i) { + /* Spin wheels. */ + $x = 10 + 10; + } } - } - final public function __destruct(){ } From 153fea09323e7b48f3fafabad52c571ee067e1fd Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Tue, 22 Aug 2023 08:30:06 -0700 Subject: [PATCH 03/35] small commit to trigger PR runner --- tests/integration/jit/function/test_computations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/jit/function/test_computations.php b/tests/integration/jit/function/test_computations.php index 9a842f78a..0d46073ca 100644 --- a/tests/integration/jit/function/test_computations.php +++ b/tests/integration/jit/function/test_computations.php @@ -1,6 +1,6 @@ Date: Thu, 12 Oct 2023 11:42:41 -0700 Subject: [PATCH 04/35] Update test_span_events_are_created_upon_caught_exception.php --- ...ents_are_created_upon_caught_exception.php | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php index 13e09a87b..628f5f66e 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php @@ -5,15 +5,15 @@ */ /*DESCRIPTION -Test that span events are correctly created from any eligible segment when a caught exception occurs. -Putting in a try/catch block means an exception is NOT handled by the exception handler. +Test that span events are correctly created from any eligible segment, even +when an exception is handled by the exception handler. */ /*SKIPIF 'FakeDB', ) ); - -try { a(); -} catch (RuntimeException $e) { -} + +echo 'this should never be printed'; From 2a47c6cb820f730a3ccf2398dcd75e908c6f45c6 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 11:50:56 -0700 Subject: [PATCH 05/35] Update test_span_events_are_created_upon_caught_exception.php Match code to previous version. Name change to _handled and new _caught test in another PR. --- ...ents_are_created_upon_caught_exception.php | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php index 0b4444679..f77168b6b 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php @@ -5,8 +5,8 @@ */ /*DESCRIPTION -Test that span events are correctly created from any eligible segment when a caught exception occurs. -Putting in a try/catch block means an exception is NOT handled by the exception handler. +Test that span events are correctly created from any eligible segment, even +when an exception is handled by the exception handler. */ /*SKIPIF @@ -33,6 +33,7 @@ zend_extension=opcache.so */ + /*EXPECT_ERROR_EVENTS null */ @@ -42,7 +43,7 @@ "?? agent run id", { "reservoir_size": 10000, - "events_seen": 3 + "events_seen": 4 }, [ [ @@ -102,9 +103,32 @@ }, {}, { - "code.lineno": "??", - "code.filepath": "__FILE__", - "code.function": "a" + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "error.class": "RuntimeException", + "code.lineno": 137, + "code.filepath": "__FILE__", + "code.function": "a" + } + ], + [ + { + "type": "Span", + "traceId": "??", + "transactionId": "??", + "sampled": true, + "priority": "??", + "name": "Custom\/{closure}", + "guid": "??", + "timestamp": "??", + "duration": "??", + "category": "generic", + "parentId": "??" + }, + {}, + { + "code.lineno": 131, + "code.filepath": "__FILE__", + "code.function": "{closure}" } ] ] @@ -117,8 +141,7 @@ set_exception_handler( function () { time_nanosleep(0, 100000000); - echo 'this should never be printed'; - exit(0); + exit(0); } ); @@ -135,8 +158,6 @@ function () { 'product' => 'FakeDB', ) ); - -try { a(); -} catch (RuntimeException $e) { -} \ No newline at end of file + +echo 'this should never be printed'; From 62e699b387d4013910431130bda4038b1cec8f9e Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 11:55:10 -0700 Subject: [PATCH 06/35] Update test_span_events_are_created_upon_caught_exception.php Revert changes. Adding _handled, _unhandled labels and new _caught test will be handled in another PR. --- ...ents_are_created_upon_caught_exception.php | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php index 628f5f66e..5277ac75b 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php @@ -3,7 +3,7 @@ * Copyright 2020 New Relic Corporation. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ - + /*DESCRIPTION Test that span events are correctly created from any eligible segment, even when an exception is handled by the exception handler. @@ -11,9 +11,9 @@ /*SKIPIF Date: Thu, 12 Oct 2023 11:58:56 -0700 Subject: [PATCH 07/35] Update tests/integration/jit/function/skipif.inc Co-authored-by: Michal Nowacki --- tests/integration/jit/function/skipif.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/jit/function/skipif.inc b/tests/integration/jit/function/skipif.inc index c7f0ce357..ac88b510a 100644 --- a/tests/integration/jit/function/skipif.inc +++ b/tests/integration/jit/function/skipif.inc @@ -10,7 +10,6 @@ if (version_compare(PHP_VERSION, "8.0", "<")) { } /* Test cannot run without opache */ -/* This should be changed to a 'warn' result when supported */ if (!extension_loaded('Zend OPcache')) { die("warn: Zend OPcache extension required\n"); } From 7a5357e467e55462c94abe6d07efe9b91ee72ce6 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 11:59:49 -0700 Subject: [PATCH 08/35] Update tests/integration/jit/tracing/skipif.inc Co-authored-by: Michal Nowacki --- tests/integration/jit/tracing/skipif.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/jit/tracing/skipif.inc b/tests/integration/jit/tracing/skipif.inc index 3a0d83424..c258e038d 100644 --- a/tests/integration/jit/tracing/skipif.inc +++ b/tests/integration/jit/tracing/skipif.inc @@ -11,7 +11,6 @@ if (version_compare(PHP_VERSION, "8.0", "<")) { } /* Test cannot run without opcache */ -/* This should be changed to a 'warn' result when supported */ if (!extension_loaded('Zend OPcache')) { die("warn: Zend OPcache extension required\n"); } From 9feccfab3f76415c0f54ccdd54337cfb2f54be3a Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 13:27:48 -0700 Subject: [PATCH 09/35] Update test_span_events_are_created_upon_caught_exception.php --- ...ents_are_created_upon_caught_exception.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php index 5277ac75b..461c83f01 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php @@ -38,7 +38,35 @@ /*EXPECT_ERROR_EVENTS -null +[ + "?? agent run id", + { + "reservoir_size": "??", + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "RuntimeException", + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": "??", + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] */ /*EXPECT_SPAN_EVENTS From 496cae514e8e8b2f6ac94facf1d46e2552466619 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 13:30:03 -0700 Subject: [PATCH 10/35] Update test_span_events_are_created_upon_caught_exception.php --- ...ents_are_created_upon_caught_exception.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php index f77168b6b..185dd259d 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php @@ -35,7 +35,35 @@ /*EXPECT_ERROR_EVENTS -null +[ + "?? agent run id", + { + "reservoir_size": "??", + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "RuntimeException", + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": "??", + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] */ /*EXPECT_SPAN_EVENTS From 124ddd043b0de7f9a7b10347253440331e4264a5 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 15:20:48 -0700 Subject: [PATCH 11/35] Update test_span_events_are_created_upon_caught_exception.php --- .../test_span_events_are_created_upon_caught_exception.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php index 461c83f01..7d41c38e0 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php @@ -136,7 +136,7 @@ { "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", "error.class": "RuntimeException", - "code.lineno": 137, + "code.lineno": "??", "code.filepath": "__FILE__", "code.function": "a" } @@ -157,7 +157,7 @@ }, {}, { - "code.lineno": 131, + "code.lineno": "??", "code.filepath": "__FILE__", "code.function": "{closure}" } From 3f9df05774c74c99069a3cf3710b8a4571e6cfd1 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 15:22:18 -0700 Subject: [PATCH 12/35] Update test_span_events_are_created_upon_caught_exception.php --- .../test_span_events_are_created_upon_caught_exception.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php index 185dd259d..2c1f8254b 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php @@ -133,7 +133,7 @@ { "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", "error.class": "RuntimeException", - "code.lineno": 137, + "code.lineno": "??", "code.filepath": "__FILE__", "code.function": "a" } @@ -154,7 +154,7 @@ }, {}, { - "code.lineno": 131, + "code.lineno": "??", "code.filepath": "__FILE__", "code.function": "{closure}" } From 77622bf4e7bb47f432ca7a9f8e963383b7b7857b Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 19:51:45 -0700 Subject: [PATCH 13/35] Update test_span_events_are_created_upon_caught_exception.php --- ...ents_are_created_upon_caught_exception.php | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php index 7d41c38e0..7c48fa1eb 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php @@ -36,39 +36,6 @@ zend_extension=opcache.so */ - -/*EXPECT_ERROR_EVENTS -[ - "?? agent run id", - { - "reservoir_size": "??", - "events_seen": 1 - }, - [ - [ - { - "type": "TransactionError", - "timestamp": "??", - "error.class": "RuntimeException", - "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", - "transactionName": "OtherTransaction\/php__FILE__", - "duration": "??", - "databaseDuration": "??", - "databaseCallCount": "??", - "nr.transactionGuid": "??", - "guid": "??", - "sampled": true, - "priority": "??", - "traceId": "??", - "spanId": "??" - }, - {}, - {} - ] - ] -] -*/ - /*EXPECT_SPAN_EVENTS [ "?? agent run id", From acc7942cb672999fd87537be9aae508915bcc916 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Thu, 12 Oct 2023 19:52:48 -0700 Subject: [PATCH 14/35] Update test_span_events_are_created_upon_caught_exception.php --- ...ents_are_created_upon_caught_exception.php | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php index 2c1f8254b..09698b110 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php @@ -33,39 +33,6 @@ zend_extension=opcache.so */ - -/*EXPECT_ERROR_EVENTS -[ - "?? agent run id", - { - "reservoir_size": "??", - "events_seen": 1 - }, - [ - [ - { - "type": "TransactionError", - "timestamp": "??", - "error.class": "RuntimeException", - "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", - "transactionName": "OtherTransaction\/php__FILE__", - "duration": "??", - "databaseDuration": "??", - "databaseCallCount": "??", - "nr.transactionGuid": "??", - "guid": "??", - "sampled": true, - "priority": "??", - "traceId": "??", - "spanId": "??" - }, - {}, - {} - ] - ] -] -*/ - /*EXPECT_SPAN_EVENTS [ "?? agent run id", From 38eb42d6cde9d20bdaa579d715e828f775406a98 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Mon, 16 Oct 2023 12:57:04 -0700 Subject: [PATCH 15/35] fix(tests): Split tests to account for difference in PHP provided information. * Split tests since: Unlike the case of PHP 8.0/8.1 where PHP OAPI additionally passes exception information in the zend_execute_data for the agent to use to create an error_event, PHP 8.2 passes no additional information for the error event to be recorded. * Updated description to explicitly determine if error events are created since previous description only cared if span events were created. * Updated names to more accurately reflect test behavior. --- ...reated_upon_uncaught_handled_exception.php | 201 ++++++++++++++++++ ...upon_uncaught_handled_exception.php82.php} | 15 +- ...ted_upon_uncaught_unhandled_exception.php} | 0 ...reated_upon_uncaught_handled_exception.php | 197 +++++++++++++++++ ...upon_uncaught_handled_exception.php82.php} | 14 +- ...ted_upon_uncaught_unhandled_exception.php} | 0 6 files changed, 424 insertions(+), 3 deletions(-) create mode 100644 tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php rename tests/integration/jit/function/{test_span_events_are_created_upon_caught_exception.php => test_span_events_are_created_upon_uncaught_handled_exception.php82.php} (87%) rename tests/integration/jit/function/{test_span_events_are_created_upon_uncaught_exception.php => test_span_events_are_created_upon_uncaught_unhandled_exception.php} (100%) create mode 100644 tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php rename tests/integration/jit/tracing/{test_span_events_are_created_upon_caught_exception.php => test_span_events_are_created_upon_uncaught_handled_exception.php82.php} (87%) rename tests/integration/jit/tracing/{test_span_events_are_created_upon_uncaught_exception.php => test_span_events_are_created_upon_uncaught_unhandled_exception.php} (100%) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php new file mode 100644 index 000000000..2c2c8218f --- /dev/null +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php @@ -0,0 +1,201 @@ +=")) { + die("skip: PHP > 8.1 not supported\n"); +} + +*/ + +/*INI +newrelic.distributed_tracing_enabled=1 +newrelic.transaction_tracer.threshold = 0 +newrelic.span_events_enabled=1 +newrelic.cross_application_tracer.enabled = false +display_errors=1 +log_errors=0 +error_reporting = E_ALL +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=32M +opcache.jit=function +*/ + + +/*PHPMODULES +zend_extension=opcache.so +*/ + +/*EXPECT_ERROR_EVENTS +[ + "?? agent run id", + { + "reservoir_size": "??", + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "RuntimeException", + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": "??", + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] +*/ + + +/*EXPECT_SPAN_EVENTS +[ + "?? agent run id", + { + "reservoir_size": 10000, + "events_seen": 4 + }, + [ + [ + { + "traceId": "??", + "duration": "??", + "transactionId": "??", + "name": "OtherTransaction\/php__FILE__", + "guid": "??", + "type": "Span", + "category": "generic", + "priority": "??", + "sampled": true, + "nr.entryPoint": true, + "timestamp": "??", + "transaction.name": "OtherTransaction\/php__FILE__" + }, + {}, + {} + ], + [ + { + "type": "Span", + "traceId": "??", + "transactionId": "??", + "sampled": true, + "priority": "??", + "name": "Datastore\/statement\/FakeDB\/other\/other", + "guid": "??", + "timestamp": "??", + "duration": "??", + "category": "datastore", + "parentId": "??", + "span.kind": "client", + "component": "FakeDB" + }, + {}, + { + "db.instance": "unknown", + "peer.hostname": "unknown", + "peer.address": "unknown:unknown" + } + ], + [ + { + "type": "Span", + "traceId": "??", + "transactionId": "??", + "sampled": true, + "priority": "??", + "name": "Custom\/a", + "guid": "??", + "timestamp": "??", + "duration": "??", + "category": "generic", + "parentId": "??" + }, + {}, + { + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "error.class": "RuntimeException", + "code.lineno": "??", + "code.filepath": "__FILE__", + "code.function": "a" + } + ], + [ + { + "type": "Span", + "traceId": "??", + "transactionId": "??", + "sampled": true, + "priority": "??", + "name": "Custom\/{closure}", + "guid": "??", + "timestamp": "??", + "duration": "??", + "category": "generic", + "parentId": "??" + }, + {}, + { + "code.lineno": "??", + "code.filepath": "__FILE__", + "code.function": "{closure}" + } + ] + ] +] +*/ + +/*EXPECT +*/ + +set_exception_handler( + function () { + time_nanosleep(0, 100000000); + exit(0); + } +); + +function a() +{ + time_nanosleep(0, 100000000); + throw new RuntimeException('oops'); +} + +newrelic_record_datastore_segment( + function () { + time_nanosleep(0, 100000000); + }, array( + 'product' => 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php82.php similarity index 87% rename from tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php rename to tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php82.php index 7c48fa1eb..3e1f6c50c 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php82.php @@ -6,7 +6,11 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. +when an exception is handled by the exception handler. Unlike the case of +PHP 8.0/8.1 where PHP OAPI additionally passes exception information in the +zend_execute_data for the agent to use to create an error_event, PHP 8.2 +passes no additional information for the error event to be recorded. +Check that no error events are created. */ /*SKIPIF @@ -14,6 +18,10 @@ require('skipif.inc'); +if (version_compare(PHP_VERSION, "8.2", "<")) { + die("skip: PHP > 8.2 not supported\n"); +} + */ /*INI @@ -36,6 +44,11 @@ zend_extension=opcache.so */ +/*EXPECT_ERROR_EVENTS +null +*/ + + /*EXPECT_SPAN_EVENTS [ "?? agent run id", diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php similarity index 100% rename from tests/integration/jit/function/test_span_events_are_created_upon_uncaught_exception.php rename to tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php new file mode 100644 index 000000000..6bf0d789c --- /dev/null +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php @@ -0,0 +1,197 @@ +=")) { + die("skip: PHP > 8.1 not supported\n"); +} + +*/ + +/*INI +newrelic.distributed_tracing_enabled=1 +newrelic.transaction_tracer.threshold = 0 +newrelic.span_events_enabled=1 +newrelic.cross_application_tracer.enabled = false +error_reporting = E_ALL +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=32M +opcache.jit=tracing +*/ + +/*PHPMODULES +zend_extension=opcache.so +*/ + +/*EXPECT_ERROR_EVENTS +[ + "?? agent run id", + { + "reservoir_size": "??", + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "RuntimeException", + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": "??", + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] +*/ + +/*EXPECT_SPAN_EVENTS +[ + "?? agent run id", + { + "reservoir_size": 10000, + "events_seen": 4 + }, + [ + [ + { + "traceId": "??", + "duration": "??", + "transactionId": "??", + "name": "OtherTransaction\/php__FILE__", + "guid": "??", + "type": "Span", + "category": "generic", + "priority": "??", + "sampled": true, + "nr.entryPoint": true, + "timestamp": "??", + "transaction.name": "OtherTransaction\/php__FILE__" + }, + {}, + {} + ], + [ + { + "type": "Span", + "traceId": "??", + "transactionId": "??", + "sampled": true, + "priority": "??", + "name": "Datastore\/statement\/FakeDB\/other\/other", + "guid": "??", + "timestamp": "??", + "duration": "??", + "category": "datastore", + "parentId": "??", + "span.kind": "client", + "component": "FakeDB" + }, + {}, + { + "db.instance": "unknown", + "peer.hostname": "unknown", + "peer.address": "unknown:unknown" + } + ], + [ + { + "type": "Span", + "traceId": "??", + "transactionId": "??", + "sampled": true, + "priority": "??", + "name": "Custom\/a", + "guid": "??", + "timestamp": "??", + "duration": "??", + "category": "generic", + "parentId": "??" + }, + {}, + { + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "error.class": "RuntimeException", + "code.lineno": "??", + "code.filepath": "__FILE__", + "code.function": "a" + } + ], + [ + { + "type": "Span", + "traceId": "??", + "transactionId": "??", + "sampled": true, + "priority": "??", + "name": "Custom\/{closure}", + "guid": "??", + "timestamp": "??", + "duration": "??", + "category": "generic", + "parentId": "??" + }, + {}, + { + "code.lineno": "??", + "code.filepath": "__FILE__", + "code.function": "{closure}" + } + ] + ] +] +*/ + +/*EXPECT +*/ + +set_exception_handler( + function () { + time_nanosleep(0, 100000000); + exit(0); + } +); + +function a() +{ + time_nanosleep(0, 100000000); + throw new RuntimeException('oops'); +} + +newrelic_record_datastore_segment( + function () { + time_nanosleep(0, 100000000); + }, array( + 'product' => 'FakeDB', + ) +); +a(); + +echo 'this should never be printed'; diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php82.php similarity index 87% rename from tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php rename to tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php82.php index 09698b110..5280eb50d 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php82.php @@ -6,7 +6,11 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. +when an exception is handled by the exception handler. Unlike the case of +PHP 8.0/8.1 where PHP OAPI additionally passes exception information in the +zend_execute_data for the agent to use to create an error_event, PHP 8.2 +passes no additional information for the error event to be recorded. +Check that no error events are created. */ /*SKIPIF @@ -14,7 +18,9 @@ require('skipif.inc'); -*/ +if (version_compare(PHP_VERSION, "8.2", "<")) { + die("skip: PHP > 8.2 not supported\n"); +} /*INI newrelic.distributed_tracing_enabled=1 @@ -33,6 +39,10 @@ zend_extension=opcache.so */ +/*EXPECT_ERROR_EVENTS +null +*/ + /*EXPECT_SPAN_EVENTS [ "?? agent run id", diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_unhandled_exception.php similarity index 100% rename from tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_exception.php rename to tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_unhandled_exception.php From f0c1b54ec9d12c4f74f73d9519d919fdd3c7a2c1 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Mon, 16 Oct 2023 14:46:51 -0700 Subject: [PATCH 16/35] fix(tests):Update uncaught exception with exception handler tests * Changed tests that verify behavior when an uncaught exception is handled by an exception handler to use correct PHP syntax. Incorrect syntax (without explicitly typing the parameter name and type) had been used previously. For oapi+opcache, this resulted in error events for PHP 8.0 and 8.1, but none for PHP 8.2. * Corrected the syntax of the exception handler definition to have an explicit parameter results in error events for all PHP 8+ versions. * Corrected name of test. * Added an _old_ test to for historical completeness only and not intended for future development. * Changed tests to add error_event detection since oapi agent is now correctly generating error events in the case of uncaught exceptions handled by exception handlers. --- ...reated_upon_uncaught_handled_exception.php | 10 +--- ...d_upon_uncaught_old_handled_exception.php} | 45 +++++++++++++---- ...d_upon_old_uncaught_handled_exception.php} | 48 +++++++++++++++---- ...reated_upon_uncaught_handled_exception.php | 11 ++--- 4 files changed, 81 insertions(+), 33 deletions(-) rename tests/integration/jit/function/{test_span_events_are_created_upon_uncaught_handled_exception.php82.php => test_span_events_are_created_upon_uncaught_old_handled_exception.php} (76%) rename tests/integration/jit/tracing/{test_span_events_are_created_upon_uncaught_handled_exception.php82.php => test_span_events_are_created_upon_old_uncaught_handled_exception.php} (75%) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php index 2c2c8218f..0907b91f6 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php @@ -6,9 +6,7 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. In the case of PHP 8.0/8.1, -PHP OAPI additionally where PHP OAPI additionally passes exception information in the -zend_execute_data for the agent to use to create an error_event. +when an exception is handled by the exception handler. Check that error events are created. */ @@ -17,10 +15,6 @@ require('skipif.inc'); -if (version_compare(PHP_VERSION, "8.2", ">=")) { - die("skip: PHP > 8.1 not supported\n"); -} - */ /*INI @@ -177,7 +171,7 @@ */ set_exception_handler( - function () { + function (Throwable $exception) { time_nanosleep(0, 100000000); exit(0); } diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php82.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php similarity index 76% rename from tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php82.php rename to tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php index 3e1f6c50c..0fb733467 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php82.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php @@ -6,20 +6,19 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. Unlike the case of -PHP 8.0/8.1 where PHP OAPI additionally passes exception information in the -zend_execute_data for the agent to use to create an error_event, PHP 8.2 -passes no additional information for the error event to be recorded. -Check that no error events are created. +when an exception is handled by the exception handler. In the case of PHP 8.0/8.1, +the oldstyle error handler behaved as expected. Stronger typing requires +explicit parameters in the error handler for PHP 8.2+. +Check that error events are created. */ /*SKIPIF =")) { + die("skip: PHP > 8.1 not supported\n"); +} else { require('skipif.inc'); - -if (version_compare(PHP_VERSION, "8.2", "<")) { - die("skip: PHP > 8.2 not supported\n"); } */ @@ -45,7 +44,35 @@ */ /*EXPECT_ERROR_EVENTS -null +[ + "?? agent run id", + { + "reservoir_size": "??", + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "RuntimeException", + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": "??", + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] */ diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php82.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_old_uncaught_handled_exception.php similarity index 75% rename from tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php82.php rename to tests/integration/jit/tracing/test_span_events_are_created_upon_old_uncaught_handled_exception.php index 5280eb50d..83899826a 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php82.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_old_uncaught_handled_exception.php @@ -6,21 +6,23 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. Unlike the case of -PHP 8.0/8.1 where PHP OAPI additionally passes exception information in the -zend_execute_data for the agent to use to create an error_event, PHP 8.2 -passes no additional information for the error event to be recorded. -Check that no error events are created. +when an exception is handled by the exception handler. In the case of PHP 8.0/8.1, +PHP OAPI additionally where PHP OAPI additionally passes exception information in the +zend_execute_data for the agent to use to create an error_event. +Check that error events are created. */ /*SKIPIF =")) { + die("skip: PHP > 8.1 not supported\n"); +} +//else { require('skipif.inc'); +//} -if (version_compare(PHP_VERSION, "8.2", "<")) { - die("skip: PHP > 8.2 not supported\n"); -} +*/ /*INI newrelic.distributed_tracing_enabled=1 @@ -40,7 +42,35 @@ */ /*EXPECT_ERROR_EVENTS -null +[ + "?? agent run id", + { + "reservoir_size": "??", + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "RuntimeException", + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": "??", + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] */ /*EXPECT_SPAN_EVENTS diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php index 6bf0d789c..5f905bf41 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php @@ -6,9 +6,7 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. In the case of PHP 8.0/8.1, -PHP OAPI additionally where PHP OAPI additionally passes exception information in the -zend_execute_data for the agent to use to create an error_event. +when an exception is handled by the exception handler. Check that error events are created. */ @@ -17,9 +15,6 @@ require('skipif.inc'); -if (version_compare(PHP_VERSION, "8.2", ">=")) { - die("skip: PHP > 8.1 not supported\n"); -} */ @@ -34,6 +29,8 @@ opcache.file_update_protection=0 opcache.jit_buffer_size=32M opcache.jit=tracing +newrelic.loglevel = verbosedebug +newrelic.daemon.loglevel = debug */ /*PHPMODULES @@ -173,7 +170,7 @@ */ set_exception_handler( - function () { + function (Throwable $exception) { time_nanosleep(0, 100000000); exit(0); } From a0025e8d07ac5d77db6dca8ad666147f198bf9bd Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:32:54 -0700 Subject: [PATCH 17/35] Update tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php Co-authored-by: Michal Nowacki --- ...an_events_are_created_upon_uncaught_handled_exception.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php index 0907b91f6..2381e2045 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception.php @@ -6,8 +6,9 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. -Check that error events are created. +when an uncaught exception is handled by the user exception handler. The +span that generated the exception should have error attributes. Additionally +error events should be created. */ /*SKIPIF From 249eac48d0a80b5606e86cf9c1b48c6ef7344d72 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:33:27 -0700 Subject: [PATCH 18/35] Update tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php Co-authored-by: Michal Nowacki --- ...eated_upon_uncaught_old_handled_exception.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php index 0fb733467..3963d9904 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php @@ -6,10 +6,18 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. In the case of PHP 8.0/8.1, -the oldstyle error handler behaved as expected. Stronger typing requires -explicit parameters in the error handler for PHP 8.2+. -Check that error events are created. +when an uncaught exception is handled by the user exception handler. The +span that generated the exception should have error attributes. Additionally +error events should be created. + +Caveat: This test uses invalid PHP code which causes undefined behavior. The +test is left only to demonstrate this undefined behavior of an agent. When +user exception handler is defined without explicitly accepting one parameter +(which violates user exception handler's callback contract defined here: +https://www.php.net/manual/en/function.set-exception-handler), when opcache +is enabled, the oapi agent generated error events for PHPs: 8.0 and 8.1, but +didn't generate error events PHP 8.2+ (hence PHPs 8.2+ are excluded from this +test). */ /*SKIPIF From 4bcb16b21175e6385386b0e24591641fc50be26f Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:34:13 -0700 Subject: [PATCH 19/35] Update tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php Co-authored-by: Michal Nowacki --- ...vents_are_created_upon_uncaught_old_handled_exception.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php index 3963d9904..551e67a03 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php @@ -23,10 +23,9 @@ /*SKIPIF =")) { - die("skip: PHP > 8.1 not supported\n"); -} else { require('skipif.inc'); +if (version_compare(PHP_VERSION, "8.2", ">=")) { + die("skip: PHP >= 8.2 behaves differently\n"); } */ From 04843fd81a855d2b82f38727e0d411994b243b22 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:34:42 -0700 Subject: [PATCH 20/35] Update tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php Co-authored-by: Michal Nowacki --- ...n_events_are_created_upon_caught_error.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php index 7eb35c819..2b2a64edb 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php @@ -34,6 +34,37 @@ /*PHPMODULES zend_extension=opcache.so */ +/*EXPECT_ERROR_EVENTS +[ + "?? agent run id", + { + "reservoir_size": 100, + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "E_USER_ERROR", + "error.message": "foo", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": 1, + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] +*/ /*EXPECT_SPAN_EVENTS [ From a1331af899562859d6befe17b9d498d52a18f479 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:34:59 -0700 Subject: [PATCH 21/35] Update tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php Co-authored-by: Michal Nowacki --- .../test_span_events_are_created_upon_caught_error.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php index 2b2a64edb..835146c32 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php @@ -6,7 +6,9 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an error is generated and handled. +when an error is generated and handled by user error handler. The span that +generated the error should have error attributes. Additionally error events +should be created. */ /*SKIPIF From 163c958160ba881e07f41aaa707f4faa87faf955 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:35:13 -0700 Subject: [PATCH 22/35] Update tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php Co-authored-by: Michal Nowacki --- .../test_span_events_are_created_upon_caught_error.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php index c01951750..e8e89fce4 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php @@ -6,7 +6,9 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an error is generated and handled. +when an error is generated and handled by user error handler. The span that +generated the error should have error attributes. Additionally error events +should be created. */ /*SKIPIF From e92c71f82f3aff9fde9662288aa172e2c9787929 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:35:53 -0700 Subject: [PATCH 23/35] Update tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php Co-authored-by: Michal Nowacki --- ...n_events_are_created_upon_caught_error.php | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php index e8e89fce4..c2af3a694 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php @@ -36,7 +36,37 @@ /*PHPMODULES zend_extension=opcache.so */ - +/*EXPECT_ERROR_EVENTS +[ + "?? agent run id", + { + "reservoir_size": 100, + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "E_USER_ERROR", + "error.message": "foo", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": 1, + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] +*/ /*EXPECT_SPAN_EVENTS [ "?? agent run id", From 098f7c6fc1dfe80de205e369d2e7814ecbabfd67 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:36:22 -0700 Subject: [PATCH 24/35] Update tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php Co-authored-by: Michal Nowacki --- .../tracing/test_span_events_are_created_upon_caught_error.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php index c2af3a694..ebde4a26b 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_caught_error.php @@ -169,7 +169,7 @@ */ set_error_handler( - function () { + function (int $errno, string $errstr) { time_nanosleep(0, 100000000); return false; } From f7717a7d4469857c50547f7c408c30e0774464f1 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:38:52 -0700 Subject: [PATCH 25/35] Rename test_span_events_are_created_upon_old_uncaught_handled_exception.php to test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php --- ...e_created_upon_uncaught_handled_exception_invalid_handler.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/integration/jit/tracing/{test_span_events_are_created_upon_old_uncaught_handled_exception.php => test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php} (100%) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_old_uncaught_handled_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php similarity index 100% rename from tests/integration/jit/tracing/test_span_events_are_created_upon_old_uncaught_handled_exception.php rename to tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php From b5b8a9cba3d24e12b2fe3fd6d8aff32df21dd08d Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:40:27 -0700 Subject: [PATCH 26/35] Rename test_span_events_are_created_upon_uncaught_old_handled_exception.php to test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler --- ...s_are_created_upon_uncaught_handled_exception_invalid_handler} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/integration/jit/function/{test_span_events_are_created_upon_uncaught_old_handled_exception.php => test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler} (100%) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler similarity index 100% rename from tests/integration/jit/function/test_span_events_are_created_upon_uncaught_old_handled_exception.php rename to tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler From 32ad3881cd0a11af4a4a7635c8d8b54848205432 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 14:45:10 -0700 Subject: [PATCH 27/35] Rename test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler to test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php --- ...e_created_upon_uncaught_handled_exception_invalid_handler.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/integration/jit/function/{test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler => test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php} (100%) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php similarity index 100% rename from tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler rename to tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php From 4a8f84209914a4a8569fdda0f5ef070d1568ee1f Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 15:31:59 -0700 Subject: [PATCH 28/35] Update test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php --- ...reated_upon_uncaught_handled_exception_invalid_handler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php index 83899826a..9674b998c 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php @@ -18,9 +18,9 @@ if (version_compare(PHP_VERSION, "8.2", ">=")) { die("skip: PHP > 8.1 not supported\n"); } -//else { + require('skipif.inc'); -//} + */ From 9a230de3d4845164277f53dcde9bc762860f03e5 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 15:33:59 -0700 Subject: [PATCH 29/35] Update test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php --- ...ated_upon_uncaught_handled_exception_invalid_handler.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php index 551e67a03..fd00e971c 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php @@ -23,11 +23,13 @@ /*SKIPIF =")) { - die("skip: PHP >= 8.2 behaves differently\n"); + die("skip: PHP > 8.1 not supported\n"); } +require('skipif.inc'); + + */ /*INI From dee7617921f3983e68720b37bdfd8bcbbcba67ac Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 15:40:43 -0700 Subject: [PATCH 30/35] Update tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php Co-authored-by: Michal Nowacki --- ...an_events_are_created_upon_uncaught_handled_exception.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php index 5f905bf41..73f71952c 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php @@ -6,8 +6,9 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. -Check that error events are created. +when an uncaught exception is handled by the user exception handler. The +span that generated the exception should have error attributes. Additionally +error events should be created. */ /*SKIPIF From 6a0e68682efa14b34ec88494c68efb71d941c09d Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 15:41:22 -0700 Subject: [PATCH 31/35] Update tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php Co-authored-by: Michal Nowacki --- ..._span_events_are_created_upon_uncaught_handled_exception.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php index 73f71952c..395b1231f 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception.php @@ -30,8 +30,6 @@ opcache.file_update_protection=0 opcache.jit_buffer_size=32M opcache.jit=tracing -newrelic.loglevel = verbosedebug -newrelic.daemon.loglevel = debug */ /*PHPMODULES From d110d2affcb1c59f15c5cf08c55d95919c39eba2 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 15:41:55 -0700 Subject: [PATCH 32/35] Update tests/integration/jit/function/test_span_events_error_collector_disabled.php Co-authored-by: Michal Nowacki --- .../jit/function/test_span_events_error_collector_disabled.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/jit/function/test_span_events_error_collector_disabled.php b/tests/integration/jit/function/test_span_events_error_collector_disabled.php index 08a872629..2fe8aec52 100644 --- a/tests/integration/jit/function/test_span_events_error_collector_disabled.php +++ b/tests/integration/jit/function/test_span_events_error_collector_disabled.php @@ -5,7 +5,7 @@ */ /*DESCRIPTION -Test that no span events error attributes are captured when error_collector is disabled +Test that no span events error attributes are captured when error_collector is disabled. No error events should be generated either. */ /*SKIPIF From ef32adc85c61eaf45daab680563821ad38aa846a Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 15:42:33 -0700 Subject: [PATCH 33/35] Update tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php Co-authored-by: Michal Nowacki --- ...n_events_are_created_upon_uncaught_unhandled_exception.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php index 3c0744dbf..46685cb23 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php @@ -13,7 +13,9 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an uncaught exception is thrown. +when an uncaught exception is thrown and handling is left to the agent's default +exception handler. The span that generated the exception and the root span should +have error attributes. Additionally error events should be created. */ /*INI From 0fe34e890761780b0ab19ee9111f674317974733 Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 15:47:44 -0700 Subject: [PATCH 34/35] Apply suggestions from code review Co-authored-by: Michal Nowacki --- ...n_events_are_created_upon_caught_error.php | 2 +- ...ated_upon_uncaught_unhandled_exception.php | 32 +++++++++++++++++ ...t_span_events_error_collector_disabled.php | 3 ++ ...ated_upon_uncaught_unhandled_exception.php | 36 ++++++++++++++++++- ...t_span_events_error_collector_disabled.php | 6 +++- 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php index 835146c32..bca70be7e 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_caught_error.php @@ -170,7 +170,7 @@ */ set_error_handler( - function () { + function (int $errno, string $errstr) { time_nanosleep(0, 100000000); return false; } diff --git a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php index 46685cb23..f619cab45 100644 --- a/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php +++ b/tests/integration/jit/function/test_span_events_are_created_upon_uncaught_unhandled_exception.php @@ -37,6 +37,38 @@ zend_extension=opcache.so */ +/*EXPECT_ERROR_EVENTS +[ + "?? agent run id", + { + "reservoir_size": 100, + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "RuntimeException", + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": 1, + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] +*/ + /*EXPECT_SPAN_EVENTS [ "?? agent run id", diff --git a/tests/integration/jit/function/test_span_events_error_collector_disabled.php b/tests/integration/jit/function/test_span_events_error_collector_disabled.php index 2fe8aec52..09a26cd9c 100644 --- a/tests/integration/jit/function/test_span_events_error_collector_disabled.php +++ b/tests/integration/jit/function/test_span_events_error_collector_disabled.php @@ -34,6 +34,9 @@ /*PHPMODULES zend_extension=opcache.so */ +/*EXPECT_ERROR_EVENTS +null +*/ /*EXPECT_SPAN_EVENTS [ diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_unhandled_exception.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_unhandled_exception.php index 6141bdef4..54269f072 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_unhandled_exception.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_unhandled_exception.php @@ -6,7 +6,9 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an uncaught exception is thrown. +when an uncaught exception is thrown and handling is left to the agent's default +exception handler. The span that generated the exception and the root span should +have error attributes. Additionally error events should be created. */ /*SKIPIF @@ -35,6 +37,38 @@ zend_extension=opcache.so */ +/*EXPECT_ERROR_EVENTS +[ + "?? agent run id", + { + "reservoir_size": 100, + "events_seen": 1 + }, + [ + [ + { + "type": "TransactionError", + "timestamp": "??", + "error.class": "RuntimeException", + "error.message": "Uncaught exception 'RuntimeException' with message 'oops' in __FILE__:??", + "transactionName": "OtherTransaction\/php__FILE__", + "duration": "??", + "databaseDuration": "??", + "databaseCallCount": 1, + "nr.transactionGuid": "??", + "guid": "??", + "sampled": true, + "priority": "??", + "traceId": "??", + "spanId": "??" + }, + {}, + {} + ] + ] +] +*/ + /*EXPECT_SPAN_EVENTS [ "?? agent run id", diff --git a/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php b/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php index 5cb38dcc3..0e6fb6db1 100644 --- a/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php +++ b/tests/integration/jit/tracing/test_span_events_error_collector_disabled.php @@ -5,7 +5,8 @@ */ /*DESCRIPTION -Test that no span events error attributes are captured when error_collector is disabled +Test that no span events error attributes are captured when error_collector is disabled. +No error events should be generated either. */ /*SKIPIF @@ -34,6 +35,9 @@ /*PHPMODULES zend_extension=opcache.so */ +/*EXPECT_ERROR_EVENTS +null +*/ /*EXPECT_SPAN_EVENTS [ From 47469dfd368ca6cbb8a8b0540ddf931d998838da Mon Sep 17 00:00:00 2001 From: Amber Sistla Date: Wed, 18 Oct 2023 15:50:30 -0700 Subject: [PATCH 35/35] Update test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php --- ...uncaught_handled_exception_invalid_handler.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php index 9674b998c..bd99855b8 100644 --- a/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php +++ b/tests/integration/jit/tracing/test_span_events_are_created_upon_uncaught_handled_exception_invalid_handler.php @@ -6,10 +6,17 @@ /*DESCRIPTION Test that span events are correctly created from any eligible segment, even -when an exception is handled by the exception handler. In the case of PHP 8.0/8.1, -PHP OAPI additionally where PHP OAPI additionally passes exception information in the -zend_execute_data for the agent to use to create an error_event. -Check that error events are created. +when an uncaught exception is handled by the user exception handler. The +span that generated the exception should have error attributes. Additionally +error events should be created. +Caveat: This test uses invalid PHP code which causes undefined behavior. The +test is left only to demonstrate this undefined behavior of an agent. When +user exception handler is defined without explicitly accepting one parameter +(which violates user exception handler's callback contract defined here: +https://www.php.net/manual/en/function.set-exception-handler), when opcache +is enabled, the oapi agent generated error events for PHPs: 8.0 and 8.1, but +didn't generate error events PHP 8.2+ (hence PHPs 8.2+ are excluded from this +test). */ /*SKIPIF