Skip to content

Commit cde843b

Browse files
committed
feat(agent): Adds newrelic_notice_error tests as handler
1 parent bfdbce1 commit cde843b

File tree

3 files changed

+361
-0
lines changed

3 files changed

+361
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should record a traced error when newrelic_notice_error is
9+
called with 1 argument which is an exception.
10+
*/
11+
12+
/*EXPECT_TRACED_ERRORS
13+
[
14+
"?? agent run id",
15+
[
16+
[
17+
"?? when",
18+
"OtherTransaction/php__FILE__",
19+
"Noticed exception 'Exception' with message '1 arg exception' in __FILE__:??",
20+
"Exception",
21+
{
22+
"stack_trace": [
23+
" in a called at __FILE__ (??)"
24+
],
25+
"agentAttributes": "??",
26+
"intrinsics": "??"
27+
},
28+
"?? transaction ID"
29+
]
30+
]
31+
]
32+
*/
33+
34+
/*EXPECT_ERROR_EVENTS
35+
[
36+
"?? agent run id",
37+
{
38+
"reservoir_size": "??",
39+
"events_seen": 1
40+
},
41+
[
42+
[
43+
{
44+
"type": "TransactionError",
45+
"timestamp": "??",
46+
"error.class": "Exception",
47+
"error.message": "Noticed exception 'Exception' with message '1 arg exception' in __FILE__:??",
48+
"transactionName": "OtherTransaction\/php__FILE__",
49+
"duration": "??",
50+
"nr.transactionGuid": "??",
51+
"guid": "??",
52+
"sampled": true,
53+
"priority": "??",
54+
"traceId": "??",
55+
"spanId": "??"
56+
},
57+
{},
58+
{}
59+
]
60+
]
61+
]
62+
*/
63+
64+
/*EXPECT_SPAN_EVENTS_LIKE
65+
[
66+
[
67+
{
68+
"traceId": "??",
69+
"duration": "??",
70+
"transactionId": "??",
71+
"name": "OtherTransaction\/php__FILE__",
72+
"guid": "??",
73+
"type": "Span",
74+
"category": "generic",
75+
"priority": "??",
76+
"sampled": true,
77+
"timestamp": "??",
78+
"nr.entryPoint": true,
79+
"transaction.name": "OtherTransaction\/php__FILE__"
80+
},
81+
{},
82+
{
83+
"error.message": "Noticed exception 'Exception' with message '1 arg exception' in __FILE__:??",
84+
"error.class": "Exception"
85+
}
86+
],
87+
[
88+
{
89+
"traceId": "??",
90+
"duration": "??",
91+
"transactionId": "??",
92+
"name": "Custom\/a",
93+
"guid": "??",
94+
"type": "Span",
95+
"category": "generic",
96+
"priority": "??",
97+
"sampled": true,
98+
"timestamp": "??",
99+
"parentId": "??"
100+
},
101+
{},
102+
{
103+
"error.message": "Uncaught exception 'Exception' with message '1 arg exception' in __FILE__:??",
104+
"error.class": "Exception",
105+
"code.lineno": "??",
106+
"code.filepath": "__FILE__",
107+
"code.function": "a"
108+
}
109+
]
110+
]
111+
*/
112+
113+
require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');
114+
115+
function a()
116+
{
117+
throw new Exception("1 arg exception");
118+
}
119+
120+
set_exception_handler('newrelic_notice_error');
121+
a();
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should record a traced error when newrelic_notice_error is
9+
called with 4 parameters.
10+
*/
11+
12+
/*EXPECT_TRACED_ERRORS
13+
[
14+
"?? agent run id",
15+
[
16+
[
17+
"?? when",
18+
"OtherTransaction/php__FILE__",
19+
"4 arg error",
20+
"NoticedError",
21+
{
22+
"stack_trace": [
23+
" in newrelic_notice_error called at ? (?)",
24+
" in trigger_error called at __FILE__ (??)",
25+
" in a called at __FILE__ (??)"
26+
],
27+
"agentAttributes": "??",
28+
"intrinsics": "??"
29+
},
30+
"?? transaction ID"
31+
]
32+
]
33+
]
34+
*/
35+
36+
/*EXPECT_ERROR_EVENTS
37+
[
38+
"?? agent run id",
39+
{
40+
"reservoir_size": "??",
41+
"events_seen": 1
42+
},
43+
[
44+
[
45+
{
46+
"type": "TransactionError",
47+
"timestamp": "??",
48+
"error.class": "NoticedError",
49+
"error.message": "4 arg error",
50+
"transactionName": "OtherTransaction\/php__FILE__",
51+
"duration": "??",
52+
"nr.transactionGuid": "??",
53+
"guid": "??",
54+
"sampled": true,
55+
"priority": "??",
56+
"traceId": "??",
57+
"spanId": "??"
58+
},
59+
{},
60+
{}
61+
]
62+
]
63+
]
64+
*/
65+
66+
/*EXPECT_SPAN_EVENTS_LIKE
67+
[
68+
[
69+
{
70+
"traceId": "??",
71+
"duration": "??",
72+
"transactionId": "??",
73+
"name": "OtherTransaction\/php__FILE__",
74+
"guid": "??",
75+
"type": "Span",
76+
"category": "generic",
77+
"priority": "??",
78+
"sampled": true,
79+
"timestamp": "??",
80+
"nr.entryPoint": true,
81+
"transaction.name": "OtherTransaction\/php__FILE__"
82+
},
83+
{},
84+
{
85+
}
86+
],
87+
[
88+
{
89+
"traceId": "??",
90+
"duration": "??",
91+
"transactionId": "??",
92+
"name": "Custom\/a",
93+
"guid": "??",
94+
"type": "Span",
95+
"category": "generic",
96+
"priority": "??",
97+
"sampled": true,
98+
"timestamp": "??",
99+
"parentId": "??"
100+
},
101+
{},
102+
{
103+
"error.message": "4 arg error",
104+
"error.class": "NoticedError",
105+
"code.lineno": "??",
106+
"code.filepath": "__FILE__",
107+
"code.function": "a"
108+
}
109+
]
110+
]
111+
*/
112+
113+
require_once(realpath(dirname( __FILE__ )) . '/../../../include/tap.php');
114+
115+
function a() {
116+
trigger_error("4 arg error", E_USER_ERROR);
117+
}
118+
119+
set_error_handler('newrelic_notice_error', E_USER_ERROR);
120+
a();
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
The agent should record a traced error when newrelic_notice_error is
9+
called with 5 parameters.
10+
*/
11+
12+
/*EXPECT_TRACED_ERRORS
13+
[
14+
"?? agent run id",
15+
[
16+
[
17+
"?? when",
18+
"OtherTransaction/php__FILE__",
19+
"5 arg error",
20+
"NoticedError",
21+
{
22+
"stack_trace": [
23+
" in newrelic_notice_error called at ? (?)",
24+
" in trigger_error called at __FILE__ (??)",
25+
" in a called at __FILE__ (??)"
26+
],
27+
"agentAttributes": "??",
28+
"intrinsics": "??"
29+
},
30+
"?? transaction ID"
31+
]
32+
]
33+
]
34+
*/
35+
36+
/*EXPECT_ERROR_EVENTS
37+
[
38+
"?? agent run id",
39+
{
40+
"reservoir_size": "??",
41+
"events_seen": 1
42+
},
43+
[
44+
[
45+
{
46+
"type": "TransactionError",
47+
"timestamp": "??",
48+
"error.class": "NoticedError",
49+
"error.message": "5 arg error",
50+
"transactionName": "OtherTransaction\/php__FILE__",
51+
"duration": "??",
52+
"nr.transactionGuid": "??",
53+
"guid": "??",
54+
"sampled": true,
55+
"priority": "??",
56+
"traceId": "??",
57+
"spanId": "??"
58+
},
59+
{},
60+
{}
61+
]
62+
]
63+
]
64+
*/
65+
66+
/*EXPECT_SPAN_EVENTS_LIKE
67+
[
68+
[
69+
{
70+
"traceId": "??",
71+
"duration": "??",
72+
"transactionId": "??",
73+
"name": "OtherTransaction\/php__FILE__",
74+
"guid": "??",
75+
"type": "Span",
76+
"category": "generic",
77+
"priority": "??",
78+
"sampled": true,
79+
"timestamp": "??",
80+
"nr.entryPoint": true,
81+
"transaction.name": "OtherTransaction\/php__FILE__"
82+
},
83+
{},
84+
{
85+
}
86+
],
87+
[
88+
{
89+
"traceId": "??",
90+
"duration": "??",
91+
"transactionId": "??",
92+
"name": "Custom\/a",
93+
"guid": "??",
94+
"type": "Span",
95+
"category": "generic",
96+
"priority": "??",
97+
"sampled": true,
98+
"timestamp": "??",
99+
"parentId": "??"
100+
},
101+
{},
102+
{
103+
"error.message": "5 arg error",
104+
"error.class": "NoticedError",
105+
"code.lineno": "??",
106+
"code.filepath": "__FILE__",
107+
"code.function": "a"
108+
}
109+
]
110+
]
111+
*/
112+
113+
require_once(realpath(dirname( __FILE__ )) . '/../../../include/tap.php');
114+
115+
function a() {
116+
trigger_error("5 arg error", E_USER_ERROR);
117+
}
118+
119+
set_error_handler('newrelic_notice_error', E_USER_ERROR);
120+
a();

0 commit comments

Comments
 (0)