Skip to content

Commit 52c7683

Browse files
committed
better header tests
1 parent a4febc6 commit 52c7683

4 files changed

+60
-100
lines changed

tests/integration/distributed_tracing/w3c/test_force_keep_headers_not_sampled_non_newrelic.php

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,64 +27,23 @@
2727
CONTENT_LENGTH=348
2828
*/
2929

30-
/*EXPECT_SPAN_EVENTS
31-
[
32-
"?? agent run id",
33-
{
34-
"reservoir_size": 10000,
35-
"events_seen": 1
36-
},
37-
[
38-
[
39-
{
40-
"traceId": "??",
41-
"duration": "??",
42-
"transactionId": "??",
43-
"name": "WebTransaction\/Uri__FILE__",
44-
"guid": "??",
45-
"type": "Span",
46-
"category": "generic",
47-
"priority": "??",
48-
"sampled": true,
49-
"nr.entryPoint": true,
50-
"parentId": "7d3efb1b173fecfa",
51-
"transaction.name": "WebTransaction\/Uri__FILE__",
52-
"timestamp": "??"
53-
},
54-
{},
55-
{
56-
"parent.transportType": "HTTP",
57-
"response.headers.contentLength": 41,
58-
"response.headers.contentType": "text\/html",
59-
"http.statusCode": 200,
60-
"response.statusCode": 200,
61-
"httpResponseCode": "200",
62-
"request.uri": "__FILE__",
63-
"request.method": "POST",
64-
"request.headers.host": "127.0.0.1",
65-
"request.headers.contentType": "text\/html",
66-
"request.headers.accept": "text\/plain",
67-
"request.headers.contentLength": "??"
68-
}
69-
]
70-
]
71-
]
72-
*/
73-
74-
/*EXPECT_REGEX
30+
/*EXPECT
7531
ok - insert function succeeded
76-
[0-9a-f]+-[0-9a-f]+-[0-9a-f]+-01
77-
[0-9a-f]+@nr=0-0-[0-9a-f]+-[0-9a-f]+-[0-9a-e]+-[0-9a-f]+-1-2.000000-[0-9a-f]+
32+
ok - traceparent sampled flag ok
33+
ok - tracestate sampled flag ok
34+
ok - tracestate priority ok
7835
*/
7936

8037
require_once(realpath (dirname ( __FILE__ )) . '/../../../include/tap.php');
8138

8239
header('Content-Type: text/html');
8340
header('Content-Length: 41');
8441

85-
$headers = array('Accept-Language' => 'en-US,en;q=0.5');
86-
tap_assert(newrelic_insert_distributed_trace_headers($headers), 'insert function succeeded');
87-
print($headers['traceparent']);
88-
print("\n");
89-
print($headers['tracestate']);
90-
print("\n");
42+
$outbound_headers = array('Accept-Language' => 'en-US,en;q=0.5');
43+
tap_assert(newrelic_insert_distributed_trace_headers($outbound_headers), 'insert function succeeded');
44+
$traceparent = explode('-', $outbound_headers['traceparent']);
45+
$tracestate = explode('-', explode('=', $outbound_headers['tracestate'])[1]);
46+
47+
tap_equal($traceparent[3], '01', 'traceparent sampled flag ok');
48+
tap_equal($tracestate[6], '1', 'tracestate sampled flag ok');
49+
tap_equal($tracestate[7], '2.000000', 'tracestate priority ok');

tests/integration/distributed_tracing/w3c/test_force_keep_headers_sampled_non_newrelic.php

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,50 +27,23 @@
2727
CONTENT_LENGTH=348
2828
*/
2929

30-
/*EXPECT_SPAN_EVENTS
31-
[
32-
"?? agent run id",
33-
{
34-
"reservoir_size": 10000,
35-
"events_seen": 1
36-
},
37-
[
38-
[
39-
{
40-
"traceId": "??",
41-
"duration": "??",
42-
"transactionId": "??",
43-
"name": "WebTransaction\/Uri__FILE__",
44-
"guid": "??",
45-
"type": "Span",
46-
"category": "generic",
47-
"priority": "??",
48-
"sampled": true,
49-
"nr.entryPoint": true,
50-
"parentId": "7d3efb1b173fecfa",
51-
"transaction.name": "WebTransaction\/Uri__FILE__",
52-
"timestamp": "??"
53-
},
54-
{},
55-
{
56-
"parent.transportType": "HTTP",
57-
"response.headers.contentLength": 41,
58-
"response.headers.contentType": "text\/html",
59-
"http.statusCode": 200,
60-
"response.statusCode": 200,
61-
"httpResponseCode": "200",
62-
"request.uri": "__FILE__",
63-
"request.method": "POST",
64-
"request.headers.host": "127.0.0.1",
65-
"request.headers.contentType": "text\/html",
66-
"request.headers.accept": "text\/plain",
67-
"request.headers.contentLength": "??"
68-
}
69-
70-
]
71-
]
72-
]
30+
/*EXPECT
31+
ok - insert function succeeded
32+
ok - traceparent sampled flag ok
33+
ok - tracestate sampled flag ok
34+
ok - tracestate priority ok
7335
*/
7436

37+
require_once(realpath (dirname ( __FILE__ )) . '/../../../include/tap.php');
38+
7539
header('Content-Type: text/html');
7640
header('Content-Length: 41');
41+
42+
$outbound_headers = array('Accept-Language' => 'en-US,en;q=0.5');
43+
tap_assert(newrelic_insert_distributed_trace_headers($outbound_headers), 'insert function succeeded');
44+
$traceparent = explode('-', $outbound_headers['traceparent']);
45+
$tracestate = explode('-', explode('=', $outbound_headers['tracestate'])[1]);
46+
47+
tap_equal($traceparent[3], '01', 'traceparent sampled flag ok');
48+
tap_equal($tracestate[6], '1', 'tracestate sampled flag ok');
49+
tap_equal($tracestate[7], '2.000000', 'tracestate priority ok');

tests/integration/distributed_tracing/w3c/test_force_toss_headers_not_sampled_non_newrelic.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,23 @@
2727
CONTENT_LENGTH=348
2828
*/
2929

30-
/*EXPECT_SPAN_EVENTS
31-
null
30+
/*EXPECT
31+
ok - insert function succeeded
32+
ok - traceparent sampled flag ok
33+
ok - tracestate sampled flag ok
34+
ok - tracestate priority ok
3235
*/
3336

37+
require_once(realpath (dirname ( __FILE__ )) . '/../../../include/tap.php');
38+
3439
header('Content-Type: text/html');
3540
header('Content-Length: 41');
41+
42+
$outbound_headers = array('Accept-Language' => 'en-US,en;q=0.5');
43+
tap_assert(newrelic_insert_distributed_trace_headers($outbound_headers), 'insert function succeeded');
44+
$traceparent = explode('-', $outbound_headers['traceparent']);
45+
$tracestate = explode('-', explode('=', $outbound_headers['tracestate'])[1]);
46+
47+
tap_equal($traceparent[3], '00', 'traceparent sampled flag ok');
48+
tap_equal($tracestate[6], '0', 'tracestate sampled flag ok');
49+
tap_not_equal($tracestate[7], '2.000000', 'tracestate priority ok');

tests/integration/distributed_tracing/w3c/test_force_toss_headers_sampled_non_newrelic.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,23 @@
2727
CONTENT_LENGTH=348
2828
*/
2929

30-
/*EXPECT_SPAN_EVENTS
31-
null
30+
/*EXPECT
31+
ok - insert function succeeded
32+
ok - traceparent sampled flag ok
33+
ok - tracestate sampled flag ok
34+
ok - tracestate priority ok
3235
*/
3336

37+
require_once(realpath (dirname ( __FILE__ )) . '/../../../include/tap.php');
38+
3439
header('Content-Type: text/html');
3540
header('Content-Length: 41');
41+
42+
$outbound_headers = array('Accept-Language' => 'en-US,en;q=0.5');
43+
tap_assert(newrelic_insert_distributed_trace_headers($outbound_headers), 'insert function succeeded');
44+
$traceparent = explode('-', $outbound_headers['traceparent']);
45+
$tracestate = explode('-', explode('=', $outbound_headers['tracestate'])[1]);
46+
47+
tap_equal($traceparent[3], '00', 'traceparent sampled flag ok');
48+
tap_equal($tracestate[6], '0', 'tracestate sampled flag ok');
49+
tap_not_equal($tracestate[7], '2.000000', 'tracestate priority ok');

0 commit comments

Comments
 (0)