-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathmetrics_spans_created.phpt
More file actions
247 lines (230 loc) · 6.17 KB
/
Copy pathmetrics_spans_created.phpt
File metadata and controls
247 lines (230 loc) · 6.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
--TEST--
'spans_created' internal metric
--SKIPIF--
<?php
if (getenv('PHP_PEAR_RUNTESTS') === '1') die("skip: pecl run-tests does not support {PWD}");
if (PHP_OS === "WINNT" && PHP_VERSION_ID < 70400) die("skip: Windows on PHP 7.2 and 7.3 have permission issues with synchronous access to telemetry");
if (getenv('USE_ZEND_ALLOC') === '0' && !getenv("SKIP_ASAN")) die('skip timing sensitive test - valgrind is too slow');
require __DIR__ . '/../includes/clear_skipif_telemetry.inc'
?>
--ENV--
DD_TRACE_GENERATE_ROOT_SPAN=0
_DD_LOAD_TEST_INTEGRATIONS=1
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
DD_TRACE_AGENT_TIMEOUT=200
DD_TRACE_RETRY_INTERVAL=1
--INI--
datadog.trace.agent_url="file://{PWD}/metrics-spans_created-telemetry.out"
zend.assertions=1
--FILE--
<?php
namespace DDTrace\Test
{
class TestSandboxedIntegration implements \DDTrace\Integration
{
static function init(): int
{
dd_trace_method("Test", "create_span_from_anomymous_source", function() {
});
dd_trace_method("Test", "create_span_from_named_integration", function(\DDTrace\SpanData $span, array $args) {
$span->meta['component'] = $args[0];
});
dd_trace_method("Test", "create_span_with_flag", function(\DDTrace\SpanData $span, array $args) {
\DDTrace\Internal\add_span_flag($span, $args[0]);
});
return self::LOADED;
}
}
}
namespace
{
class Test
{
// Must be called to trigger the call of TestSandboxedIntegration::init()
public static function public_static_method()
{
echo __METHOD__."\n";
}
public static function create_span_from_anomymous_source()
{
echo __METHOD__."\n";
}
public static function create_span_from_named_integration($integrationName)
{
echo __METHOD__."({$integrationName})\n";
}
public static function create_span_with_flag()
{
echo __METHOD__."\n";
}
}
// Don't create a span
Test::public_static_method();
Test::create_span_from_anomymous_source();
Test::create_span_from_anomymous_source();
Test::create_span_from_named_integration('testintegration');
Test::create_span_from_named_integration('testintegration');
Test::create_span_from_named_integration('testintegration');
Test::create_span_from_named_integration('foo');
Test::create_span_with_flag(\DDTRACE\Internal\SPAN_FLAG_OPENTELEMETRY);
dd_trace_internal_fn("finalize_telemetry");
for ($i = 0; $i < 300; ++$i) {
("us" . "leep")(100000);
if (file_exists(__DIR__ . '/metrics-spans_created-telemetry.out')) {
foreach (file(__DIR__ . '/metrics-spans_created-telemetry.out') as $l) {
if ($l) {
$json = json_decode($l, true);
if (($json["application"]["language_version"] ?? "") == "SIDECAR") {
continue;
}
$batch = $json["request_type"] == "message-batch" ? $json["payload"] : [$json];
foreach ($batch as $json) {
if ($json["request_type"] == "generate-metrics") {
$series = [];
foreach ($json['payload']['series'] as $serie) {
if ($serie['metric'] !== 'spans_created') {
continue;
}
$key = $serie['namespace'].$serie['metric'].implode(',', $serie['tags']);
$series[$key] = $serie;
};
ksort($series);
var_dump(array_values($series));
break 3;
}
}
}
}
}
}
if ($i == 300) {
var_dump(file(__DIR__ . '/metrics-spans_created-telemetry.out'));
}
}
?>
--EXPECTF--
Test::public_static_method
Test::create_span_from_anomymous_source
Test::create_span_from_anomymous_source
Test::create_span_from_named_integration(testintegration)
Test::create_span_from_named_integration(testintegration)
Test::create_span_from_named_integration(testintegration)
Test::create_span_from_named_integration(foo)
Test::create_span_with_flag
array(4) {
[0]=>
array(7) {
["namespace"]=>
string(7) "tracers"
["metric"]=>
string(13) "spans_created"
["points"]=>
array(1) {
[0]=>
array(2) {
[0]=>
int(%d)
[1]=>
float(2)
}
}
["tags"]=>
array(1) {
[0]=>
string(24) "integration_name:datadog"
}
["common"]=>
bool(true)
["type"]=>
string(5) "count"
["interval"]=>
int(10)
}
[1]=>
array(7) {
["namespace"]=>
string(7) "tracers"
["metric"]=>
string(13) "spans_created"
["points"]=>
array(1) {
[0]=>
array(2) {
[0]=>
int(%d)
[1]=>
float(1)
}
}
["tags"]=>
array(1) {
[0]=>
string(20) "integration_name:foo"
}
["common"]=>
bool(true)
["type"]=>
string(5) "count"
["interval"]=>
int(10)
}
[2]=>
array(7) {
["namespace"]=>
string(7) "tracers"
["metric"]=>
string(13) "spans_created"
["points"]=>
array(1) {
[0]=>
array(2) {
[0]=>
int(%d)
[1]=>
float(1)
}
}
["tags"]=>
array(1) {
[0]=>
string(21) "integration_name:otel"
}
["common"]=>
bool(true)
["type"]=>
string(5) "count"
["interval"]=>
int(10)
}
[3]=>
array(7) {
["namespace"]=>
string(7) "tracers"
["metric"]=>
string(13) "spans_created"
["points"]=>
array(1) {
[0]=>
array(2) {
[0]=>
int(%d)
[1]=>
float(3)
}
}
["tags"]=>
array(1) {
[0]=>
string(32) "integration_name:testintegration"
}
["common"]=>
bool(true)
["type"]=>
string(5) "count"
["interval"]=>
int(10)
}
}
--CLEAN--
<?php
@unlink(__DIR__ . '/metrics-spans_created-telemetry.out');