|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright 2020 New Relic Corporation. All rights reserved. |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/*DESCRIPTION |
| 8 | +Test that Distributed Tracing works with guzzle 7. |
| 9 | + */ |
| 10 | + |
| 11 | +/*SKIPIF |
| 12 | +<?php |
| 13 | +require_once(realpath(dirname(__FILE__)) . '/../../../include/unpack_guzzle.php'); |
| 14 | +
|
| 15 | +if (version_compare(phpversion(), '7.2.0', '<=')) { |
| 16 | + die("skip: PHP > 7.2.0 required\n"); |
| 17 | +} |
| 18 | +
|
| 19 | +if (!unpack_guzzle(7)) { |
| 20 | + die("skip: guzzle 7 installation required\n"); |
| 21 | +} |
| 22 | +*/ |
| 23 | + |
| 24 | +/*INI |
| 25 | +newrelic.distributed_tracing_enabled = true |
| 26 | +newrelic.cross_application_tracer.enabled = false |
| 27 | + */ |
| 28 | + |
| 29 | +/*EXPECT |
| 30 | +traceparent=found tracestate=found newrelic=found X-NewRelic-ID=missing X-NewRelic-Transaction=missing tracing endpoint reached |
| 31 | +traceparent=found tracestate=found newrelic=found X-NewRelic-ID=missing X-NewRelic-Transaction=missing tracing endpoint reached |
| 32 | +traceparent=found tracestate=found newrelic=found X-NewRelic-ID=missing X-NewRelic-Transaction=missing Customer-Header=found tracing endpoint reached |
| 33 | +*/ |
| 34 | + |
| 35 | +/*EXPECT_RESPONSE_HEADERS |
| 36 | +*/ |
| 37 | + |
| 38 | +/*EXPECT_METRICS |
| 39 | +[ |
| 40 | + "?? agent run id", |
| 41 | + "?? timeframe start", |
| 42 | + "?? timeframe stop", |
| 43 | + [ |
| 44 | + [{"name":"External/127.0.0.1/all"}, [3, "??", "??", "??", "??", "??"]], |
| 45 | + [{"name":"External/127.0.0.1/all", |
| 46 | + "scope":"OtherTransaction/php__FILE__"}, [3, "??", "??", "??", "??", "??"]], |
| 47 | + [{"name":"External/all"}, [3, "??", "??", "??", "??", "??"]], |
| 48 | + [{"name":"External/allOther"}, [3, "??", "??", "??", "??", "??"]], |
| 49 | + [{"name":"OtherTransaction/all"}, [1, "??", "??", "??", "??", "??"]], |
| 50 | + [{"name":"OtherTransaction/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], |
| 51 | + [{"name":"OtherTransactionTotalTime"}, [1, "??", "??", "??", "??", "??"]], |
| 52 | + [{"name":"OtherTransactionTotalTime/php__FILE__"}, [1, "??", "??", "??", "??", "??"]], |
| 53 | + [{"name":"Supportability/library/Guzzle 4-5/detected"}, |
| 54 | + [2, 0, 0, 0, 0, 0]], |
| 55 | + [{"name":"Supportability/library/Guzzle 6/detected"}, [1, 0, 0, 0, 0, 0]], |
| 56 | + [{"name":"Supportability/library/Guzzle 7/detected"}, [1, 0, 0, 0, 0, 0]], |
| 57 | + [{"name":"Supportability/Unsupported/curl_setopt/CURLOPT_HEADERFUNCTION/closure"}, |
| 58 | + [3, 0, 0, 0, 0, 0]], |
| 59 | + [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/all"}, |
| 60 | + [1, "??", "??", "??", "??", "??"]], |
| 61 | + [{"name":"DurationByCaller/Unknown/Unknown/Unknown/Unknown/allOther"}, |
| 62 | + [1, "??", "??", "??", "??", "??"]], |
| 63 | + [{"name":"Supportability/TraceContext/Create/Success"}, |
| 64 | + [3, "??", "??", "??", "??", "??"]], |
| 65 | + [{"name":"Supportability/DistributedTrace/CreatePayload/Success"}, |
| 66 | + [3, "??", "??", "??", "??", "??"]] |
| 67 | + ] |
| 68 | +] |
| 69 | +*/ |
| 70 | + |
| 71 | +?> |
| 72 | +<?php |
| 73 | +require_once(realpath(dirname(__FILE__)) . '/../../../include/config.php'); |
| 74 | +require_once(realpath(dirname(__FILE__)) . '/../../../include/unpack_guzzle.php'); |
| 75 | +require_guzzle(7); |
| 76 | + |
| 77 | +/* Create URL. */ |
| 78 | +$url = "http://" . make_tracing_url(realpath(dirname(__FILE__)) . '/../../../include/tracing_endpoint.php'); |
| 79 | +//echo "\n"; |
| 80 | +//echo $url."\n"; |
| 81 | + |
| 82 | +/* Use guzzle 7 to make an http request. */ |
| 83 | +use GuzzleHttp\Client; |
| 84 | + |
| 85 | +$client = new Client(); |
| 86 | +$response = $client->get($url); |
| 87 | +echo $response->getBody(); |
| 88 | + |
| 89 | +$response = $client->get($url, [ |
| 90 | + 'headers' => [ |
| 91 | + 'zip' => 'zap']]); |
| 92 | +echo $response->getBody(); |
| 93 | + |
| 94 | +$response = $client->get($url, [ |
| 95 | + 'headers' => [ |
| 96 | + 'zip' => 'zap', |
| 97 | + CUSTOMER_HEADER => 'zap']]); |
| 98 | +echo $response->getBody(); |
0 commit comments