Skip to content

Commit 8fa73a1

Browse files
committed
chore(agent): Adds happy path newrelic_notice_error() tests
1 parent ca7f0d4 commit 8fa73a1

File tree

5 files changed

+504
-0
lines changed

5 files changed

+504
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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": "Custom\/a",
72+
"guid": "??",
73+
"type": "Span",
74+
"category": "generic",
75+
"priority": "??",
76+
"sampled": true,
77+
"timestamp": "??",
78+
"parentId": "??"
79+
},
80+
{},
81+
{
82+
"error.message": "Noticed exception 'Exception' with message '1 arg exception' in __FILE__:??",
83+
"error.class": "Exception",
84+
"code.lineno": "??",
85+
"code.filepath": "__FILE__",
86+
"code.function": "a"
87+
}
88+
]
89+
]
90+
*/
91+
92+
require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');
93+
94+
function a()
95+
{
96+
// One argument with an exception - this is tricky because most
97+
// values are implicitly convertible to strings. Use a resource to prevent this.
98+
newrelic_notice_error("1 arg", new Exception("1 arg exception"));
99+
}
100+
101+
102+
a();
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 string.
10+
*/
11+
12+
/*EXPECT_TRACED_ERRORS
13+
[
14+
"?? agent run id",
15+
[
16+
[
17+
"?? when",
18+
"OtherTransaction/php__FILE__",
19+
"Exception 1 arg string",
20+
"NoticedError",
21+
{
22+
"stack_trace": [
23+
" in newrelic_notice_error called at __FILE__ (??)",
24+
" in a called at __FILE__ (??)"
25+
],
26+
"agentAttributes": "??",
27+
"intrinsics": "??"
28+
},
29+
"?? transaction ID"
30+
]
31+
]
32+
]
33+
*/
34+
35+
/*EXPECT_ERROR_EVENTS
36+
[
37+
"?? agent run id",
38+
{
39+
"reservoir_size": "??",
40+
"events_seen": 1
41+
},
42+
[
43+
[
44+
{
45+
"type": "TransactionError",
46+
"timestamp": "??",
47+
"error.class": "NoticedError",
48+
"error.message": "Exception 1 arg string",
49+
"transactionName": "OtherTransaction\/php__FILE__",
50+
"duration": "??",
51+
"nr.transactionGuid": "??",
52+
"guid": "??",
53+
"sampled": true,
54+
"priority": "??",
55+
"traceId": "??",
56+
"spanId": "??"
57+
},
58+
{},
59+
{}
60+
]
61+
]
62+
]
63+
*/
64+
65+
/*EXPECT_SPAN_EVENTS_LIKE
66+
[
67+
[
68+
{
69+
"traceId": "??",
70+
"duration": "??",
71+
"transactionId": "??",
72+
"name": "Custom\/a",
73+
"guid": "??",
74+
"type": "Span",
75+
"category": "generic",
76+
"priority": "??",
77+
"sampled": true,
78+
"timestamp": "??",
79+
"parentId": "??"
80+
},
81+
{},
82+
{
83+
"error.message": "Exception 1 arg string",
84+
"error.class": "NoticedError",
85+
"code.lineno": "??",
86+
"code.filepath": "__FILE__",
87+
"code.function": "a"
88+
}
89+
]
90+
]
91+
*/
92+
93+
require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');
94+
95+
function a()
96+
{
97+
// First arg must be a string or an exception.
98+
newrelic_notice_error("Exception 1 arg string");
99+
}
100+
101+
a();
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 2 parameters.
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 '2 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 '2 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": "Custom\/a",
72+
"guid": "??",
73+
"type": "Span",
74+
"category": "generic",
75+
"priority": "??",
76+
"sampled": true,
77+
"timestamp": "??",
78+
"parentId": "??"
79+
},
80+
{},
81+
{
82+
"error.message": "Noticed exception 'Exception' with message '2 arg exception' in __FILE__:??",
83+
"error.class": "Exception",
84+
"code.lineno": "??",
85+
"code.filepath": "__FILE__",
86+
"code.function": "a"
87+
}
88+
]
89+
]
90+
*/
91+
92+
require_once(realpath(dirname(__FILE__)) . '/../../../include/tap.php');
93+
94+
function a()
95+
{
96+
// Args must be string, exception.
97+
newrelic_notice_error("2 arg", new Exception("2 arg exception"));
98+
}
99+
100+
a();

0 commit comments

Comments
 (0)