Skip to content

Commit df096d7

Browse files
committed
tests(agent): Adds another test for log forwarded labels using defaults
1 parent cb4eea2 commit df096d7

File tree

1 file changed

+208
-0
lines changed

1 file changed

+208
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
<?php
2+
/*
3+
* Copyright 2022 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Test that Monolog3 instrumentation will NOT forward logs with labels when:
9+
- default INI values are used for logging except logleve set to DEBUG
10+
- newrelic.labels set to "label1:value1;label2:value2"
11+
12+
Expect:
13+
- NO labels to be forwarded with the log events in the "common" attribute
14+
- "Supportability/Logging/Labels/PHP/disabled" to exist and have a value of 1
15+
*/
16+
17+
/*SKIPIF
18+
<?php
19+
20+
require('skipif.inc');
21+
22+
*/
23+
24+
/*INI
25+
newrelic.application_logging.forwarding.log_level = DEBUG
26+
newrelic.labels = "label1:value1;label2:value2"
27+
*/
28+
29+
/*EXPECT
30+
monolog3.DEBUG: debug []
31+
monolog3.INFO: info []
32+
monolog3.NOTICE: notice []
33+
monolog3.WARNING: warning []
34+
monolog3.ERROR: error []
35+
monolog3.CRITICAL: critical []
36+
monolog3.ALERT: alert []
37+
monolog3.EMERGENCY: emergency []
38+
*/
39+
40+
/*EXPECT_METRICS
41+
[
42+
"?? agent run id",
43+
"?? timeframe start",
44+
"?? timeframe stop",
45+
[
46+
[{"name": "DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, [1, "??", "??", "??", "??", "??"]],
47+
[{"name": "DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, [1, "??", "??", "??", "??", "??"]],
48+
[{"name": "Logging/lines"}, [8, "??", "??", "??", "??", "??"]],
49+
[{"name": "Logging/lines/ALERT"}, [1, "??", "??", "??", "??", "??"]],
50+
[{"name": "Logging/lines/CRITICAL"}, [1, "??", "??", "??", "??", "??"]],
51+
[{"name": "Logging/lines/DEBUG"}, [1, "??", "??", "??", "??", "??"]],
52+
[{"name": "Logging/lines/EMERGENCY"}, [1, "??", "??", "??", "??", "??"]],
53+
[{"name": "Logging/lines/ERROR"}, [1, "??", "??", "??", "??", "??"]],
54+
[{"name": "Logging/lines/INFO"}, [1, "??", "??", "??", "??", "??"]],
55+
[{"name": "Logging/lines/NOTICE"}, [1, "??", "??", "??", "??", "??"]],
56+
[{"name": "Logging/lines/WARNING"}, [1, "??", "??", "??", "??", "??"]],
57+
[{"name": "OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]],
58+
[{"name": "OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
59+
[{"name": "OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]],
60+
[{"name": "OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]],
61+
[{"name": "Supportability/Logging/PHP/Monolog/enabled"}, [1, "??", "??", "??", "??", "??"]],
62+
[{"name": "Supportability/PHP/package/monolog/monolog/3/detected"}, [1, "??", "??", "??", "??", "??"]],
63+
[{"name": "Supportability/library/Monolog/detected"}, [1, "??", "??", "??", "??", "??"]],
64+
[{"name": "Supportability/Logging/LocalDecorating/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]],
65+
[{"name": "Supportability/Logging/Forwarding/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
66+
[{"name": "Supportability/Logging/Metrics/PHP/enabled"}, [1, "??", "??", "??", "??", "??"]],
67+
[{"name": "Supportability/Logging/Labels/PHP/disabled"}, [1, "??", "??", "??", "??", "??"]]
68+
]
69+
]
70+
*/
71+
72+
73+
/*EXPECT_LOG_EVENTS
74+
[
75+
{
76+
"common": {
77+
"attributes": {}
78+
},
79+
"logs": [
80+
{
81+
"message": "error",
82+
"level": "ERROR",
83+
"timestamp": "??",
84+
"trace.id": "??",
85+
"span.id": "??",
86+
"entity.guid": "??",
87+
"entity.name": "tests/integration/logging/monolog3__FILE__",
88+
"hostname": "__HOST__"
89+
},
90+
{
91+
"message": "critical",
92+
"level": "CRITICAL",
93+
"timestamp": "??",
94+
"trace.id": "??",
95+
"span.id": "??",
96+
"entity.guid": "??",
97+
"entity.name": "tests/integration/logging/monolog3__FILE__",
98+
"hostname": "__HOST__"
99+
},
100+
{
101+
"message": "notice",
102+
"level": "NOTICE",
103+
"timestamp": "??",
104+
"trace.id": "??",
105+
"span.id": "??",
106+
"entity.guid": "??",
107+
"entity.name": "tests/integration/logging/monolog3__FILE__",
108+
"hostname": "__HOST__"
109+
},
110+
{
111+
"message": "warning",
112+
"level": "WARNING",
113+
"timestamp": "??",
114+
"trace.id": "??",
115+
"span.id": "??",
116+
"entity.guid": "??",
117+
"entity.name": "tests/integration/logging/monolog3__FILE__",
118+
"hostname": "__HOST__"
119+
},
120+
{
121+
"message": "info",
122+
"level": "INFO",
123+
"timestamp": "??",
124+
"trace.id": "??",
125+
"span.id": "??",
126+
"entity.guid": "??",
127+
"entity.name": "tests/integration/logging/monolog3__FILE__",
128+
"hostname": "__HOST__"
129+
},
130+
{
131+
"message": "alert",
132+
"level": "ALERT",
133+
"timestamp": "??",
134+
"trace.id": "??",
135+
"span.id": "??",
136+
"entity.guid": "??",
137+
"entity.name": "tests/integration/logging/monolog3__FILE__",
138+
"hostname": "__HOST__"
139+
},
140+
{
141+
"message": "emergency",
142+
"level": "EMERGENCY",
143+
"timestamp": "??",
144+
"trace.id": "??",
145+
"span.id": "??",
146+
"entity.guid": "??",
147+
"entity.name": "tests/integration/logging/monolog3__FILE__",
148+
"hostname": "__HOST__"
149+
},
150+
{
151+
"message": "debug",
152+
"level": "DEBUG",
153+
"timestamp": "??",
154+
"trace.id": "??",
155+
"span.id": "??",
156+
"entity.guid": "??",
157+
"entity.name": "tests/integration/logging/monolog3__FILE__",
158+
"hostname": "__HOST__"
159+
}
160+
]
161+
}
162+
]
163+
*/
164+
165+
require_once(realpath(dirname(__FILE__)) . '/../../../include/config.php');
166+
require_once(realpath(dirname(__FILE__)) . '/../../../include/monolog.php');
167+
require_monolog(3);
168+
169+
use Monolog\Logger;
170+
use Monolog\Level;
171+
use Monolog\Handler\StreamHandler;
172+
use Monolog\Formatter\LineFormatter;
173+
174+
175+
function test_logging() {
176+
$logger = new Logger('monolog3');
177+
178+
$logfmt = "%channel%.%level_name%: %message% %context%\n";
179+
$formatter = new LineFormatter($logfmt);
180+
181+
$stdoutHandler = new StreamHandler('php://stdout', LOGGER::DEBUG);
182+
$stdoutHandler->setFormatter($formatter);
183+
184+
$logger->pushHandler($stdoutHandler);
185+
186+
// insert delays between log messages to allow priority sampling
187+
// to resolve that later messages have higher precedence
188+
// since timestamps are only millisecond resolution
189+
// without delays sometimes order in output will reflect
190+
// all having the same timestamp.
191+
$logger->debug("debug");
192+
usleep(10000);
193+
$logger->info("info");
194+
usleep(10000);
195+
$logger->notice("notice");
196+
usleep(10000);
197+
$logger->warning("warning");
198+
usleep(10000);
199+
$logger->error("error");
200+
usleep(10000);
201+
$logger->critical("critical");
202+
usleep(10000);
203+
$logger->alert("alert");
204+
usleep(10000);
205+
$logger->emergency("emergency");
206+
}
207+
208+
test_logging();

0 commit comments

Comments
 (0)