Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70639e7

Browse files
2 parents 01b10a0 + 103bd0b commit 70639e7

5 files changed

Lines changed: 103 additions & 3 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace DDTrace\Integrations\Guzzle\V6;
4+
5+
use DDTrace\Configuration;
6+
use DDTrace\Formats;
7+
use DDTrace\Tags;
8+
use DDTrace\Span;
9+
use DDTrace\Types;
10+
use OpenTracing\GlobalTracer;
11+
use DDTrace\Http\Urls;
12+
use DDTrace\Integrations\Integration;
13+
use GuzzleHttp\Message\ResponseInterface;
14+
15+
class GuzzleIntegration extends Integration
16+
{
17+
const NAME = 'guzzle';
18+
const CLASS_NAME = 'GuzzleHttp\Client';
19+
20+
protected static function loadIntegration()
21+
{
22+
self::traceMethod('send', function (Span $span, array $args) {
23+
list($request) = $args;
24+
GuzzleIntegration::injectDistributedTracingHeaders($request, $span);
25+
$span->setTag('http.method', $request->getMethod());
26+
$span->setTag('http.url', Urls::sanitize($request->getUri()));
27+
}, function (Span $span, $response) {
28+
if (!$response instanceof ResponseInterface) {
29+
return;
30+
}
31+
$span->setTag('http.status_code', $response->getStatusCode());
32+
});
33+
}
34+
35+
public static function setDefaultTags(Span $span, $method)
36+
{
37+
parent::setDefaultTags($span, $method);
38+
$span->setTag(Tags\SPAN_TYPE, Types\HTTP_CLIENT);
39+
$span->setTag(Tags\SERVICE_NAME, 'guzzle');
40+
}
41+
42+
/**
43+
* @param \GuzzleHttp\Message\MessageInterface $request
44+
* @param Span $span
45+
*/
46+
public static function injectDistributedTracingHeaders($request, $span)
47+
{
48+
if (!Configuration::get()->isDistributedTracingEnabled()) {
49+
return;
50+
}
51+
52+
if (!is_subclass_of($request, '\GuzzleHttp\Message\MessageInterface')) {
53+
return;
54+
}
55+
56+
// Associative array of header names to values
57+
$headers = $request->getHeaders();
58+
59+
$context = $span->getContext();
60+
$tracer = GlobalTracer::get();
61+
$tracer->inject($context, Formats\HTTP_HEADERS, $headers);
62+
$request->setHeaders($headers);
63+
}
64+
}

src/DDTrace/Integrations/IntegrationsLoader.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
class IntegrationsLoader
2020
{
21+
2122
/**
2223
* @return array A list of supported library integrations. Web frameworks ARE NOT INCLUDED.
2324
*/
@@ -27,7 +28,7 @@ public static function allLibraries()
2728
CurlIntegration::NAME => '\DDTrace\Integrations\Curl\CurlIntegration',
2829
ElasticSearchIntegration::NAME => '\DDTrace\Integrations\ElasticSearch\V1\ElasticSearchIntegration',
2930
EloquentIntegration::NAME => '\DDTrace\Integrations\Eloquent\EloquentIntegration',
30-
GuzzleIntegration::NAME => '\DDTrace\Integrations\Guzzle\V5\GuzzleIntegration',
31+
GuzzleIntegration::NAME => '\DDTrace\Integrations\Guzzle\V6\GuzzleIntegration',
3132
MemcachedIntegration::NAME => '\DDTrace\Integrations\Memcached\MemcachedIntegration',
3233
MongoIntegration::NAME => '\DDTrace\Integrations\Mongo\MongoIntegration',
3334
MysqliIntegration::NAME => '\DDTrace\Integrations\Mysqli\MysqliIntegration',
@@ -36,6 +37,18 @@ public static function allLibraries()
3637
];
3738
}
3839

40+
const LIBRARIES = [
41+
CurlIntegration::NAME => '\DDTrace\Integrations\Curl\CurlIntegration',
42+
ElasticSearchIntegration::NAME => '\DDTrace\Integrations\ElasticSearch\V1\ElasticSearchIntegration',
43+
EloquentIntegration::NAME => '\DDTrace\Integrations\Eloquent\EloquentIntegration',
44+
GuzzleIntegration::NAME => '\DDTrace\Integrations\Guzzle\V6\GuzzleIntegration',
45+
MemcachedIntegration::NAME => '\DDTrace\Integrations\Memcached\MemcachedIntegration',
46+
MongoIntegration::NAME => '\DDTrace\Integrations\Mongo\MongoIntegration',
47+
MysqliIntegration::NAME => '\DDTrace\Integrations\Mysqli\MysqliIntegration',
48+
PDOIntegration::NAME => '\DDTrace\Integrations\PDO\PDOIntegration',
49+
PredisIntegration::NAME => '\DDTrace\Integrations\Predis\PredisIntegration',
50+
];
51+
3952
/**
4053
* Loads all the enabled library integrations.
4154
*/

src/DDTrace/Integrations/Predis/PredisIntegration.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ public static function storeConnectionParams($predis, $args)
171171

172172
if (isset($args[1])) {
173173
$options = $args[1];
174-
if (isset($options['parameters']) && isset($options['parameters']['database'])) {
175-
$tags['out.redis_db'] = $options['parameters']['database'];
174+
175+
$parameters = $options->__get('parameters');
176+
177+
if (is_array($parameters) && isset($parameters['database'])) {
178+
$tags['out.redis_db'] = $parameters['database'];
176179
}
177180
}
178181

src/DDTrace/Integrations/Symfony/V3/SymfonyBundle.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function boot()
6161
$appName = $this->getAppName();
6262
$symfonyRequestSpan = $scope->getSpan();
6363
$symfonyRequestSpan->setTag(Tags\SERVICE_NAME, $appName);
64+
$symfonyRequestSpan->setTag(Tags\ENV, $this->getAppEnv());
6465
$symfonyRequestSpan->setTag(Tags\SPAN_TYPE, Types\WEB_SERVLET);
6566
$request = null;
6667

@@ -218,4 +219,13 @@ private function getAppName()
218219
return 'symfony';
219220
}
220221
}
222+
223+
private function getAppEnv()
224+
{
225+
if ($appName = getenv('ddtrace_app_env')) {
226+
return $appName;
227+
} else {
228+
return 'none';
229+
}
230+
}
221231
}

src/DDTrace/Integrations/Symfony/V4/SymfonyBundle.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function boot()
5858
$scope = $tracer->startActiveSpan('symfony.request');
5959
$symfonyRequestSpan = $scope->getSpan();
6060
$symfonyRequestSpan->setTag(Tags\SERVICE_NAME, $this->getAppName());
61+
$symfonyRequestSpan->setTag(Tags\ENV, $this->getAppEnv());
6162
$symfonyRequestSpan->setTag(Tags\SPAN_TYPE, Types\WEB_SERVLET);
6263

6364
// public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
@@ -154,4 +155,13 @@ private function getAppName()
154155
return 'symfony';
155156
}
156157
}
158+
159+
private function getAppEnv()
160+
{
161+
if ($appName = getenv('ddtrace_app_env')) {
162+
return $appName;
163+
} else {
164+
return 'none';
165+
}
166+
}
157167
}

0 commit comments

Comments
 (0)