-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [guzzle] Add support for guzzle 6 * update changelog * [tests] Add execution of guzzle 6 tests * [ci] Fix lintings and phpstan * [tests] Fix url of request replayer file * [ci] Fixes to the composer.json scenarios approach * Apply suggestions from code review Co-Authored-By: labbati <luca.abbati@datadoghq.com>
- Loading branch information
Showing
30 changed files
with
686 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/DDTrace/Integrations/Guzzle/AbstractGuzzleIntegrationLoader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace DDTrace\Integrations\Guzzle; | ||
|
||
use DDTrace\Configuration; | ||
use DDTrace\Contracts\Span; | ||
use DDTrace\Format; | ||
use DDTrace\GlobalTracer; | ||
use DDTrace\Integrations\Integration; | ||
use DDTrace\Tag; | ||
use DDTrace\Type; | ||
use DDTrace\Util\CodeTracer; | ||
|
||
/** | ||
* Abstract integration loader for Guzzle integrations. | ||
*/ | ||
abstract class AbstractGuzzleIntegrationLoader | ||
{ | ||
/** | ||
* @var CodeTracer | ||
*/ | ||
private $codeTracer; | ||
|
||
/** | ||
* @param Span $span | ||
* @param mixed $request | ||
*/ | ||
abstract protected function setUrlTag(Span $span, $request); | ||
|
||
/** | ||
* @param Span $span | ||
* @param mixed $response | ||
*/ | ||
abstract protected function setStatusCodeTag(Span $span, $response); | ||
|
||
/** | ||
* @param mixed $request | ||
*/ | ||
abstract protected function extractRequestHeaders($request); | ||
|
||
/** | ||
* @param mixed $request | ||
* @param array $headers | ||
*/ | ||
abstract protected function addRequestHeaders($request, $headers); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract protected function getMethodToTrace(); | ||
|
||
/** | ||
* @param CodeTracer $codeTracer | ||
*/ | ||
public function __construct(CodeTracer $codeTracer) | ||
{ | ||
$this->codeTracer = $codeTracer; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return int | ||
*/ | ||
public function load($name) | ||
{ | ||
$self = $this; | ||
$method = $this->getMethodToTrace(); | ||
|
||
$this->codeTracer->tracePublicMethod( | ||
'GuzzleHttp\Client', | ||
$method, | ||
function (Span $span, array $args) use ($self, $name, $method) { | ||
list($request) = $args; | ||
$self->applyDistributedTracingHeaders($span, $request); | ||
$span->setTag(Tag::SPAN_TYPE, Type::HTTP_CLIENT); | ||
$span->setTag(Tag::SERVICE_NAME, $name); | ||
$span->setTag(Tag::HTTP_METHOD, $request->getMethod()); | ||
$self->setUrlTag($span, $request); | ||
$span->setTag(Tag::RESOURCE_NAME, $method); | ||
}, | ||
function (Span $span, $response) use ($self) { | ||
$self->setStatusCodeTag($span, $response); | ||
} | ||
); | ||
|
||
return Integration::LOADED; | ||
} | ||
|
||
/** | ||
* @param mixed $request | ||
* @param Span $span | ||
*/ | ||
public function applyDistributedTracingHeaders(Span $span, $request) | ||
{ | ||
if (!Configuration::get()->isDistributedTracingEnabled()) { | ||
return; | ||
} | ||
|
||
$headers = $this->extractRequestHeaders($request); | ||
|
||
$context = $span->getContext(); | ||
$tracer = GlobalTracer::get(); | ||
$tracer->inject($context, Format::HTTP_HEADERS, $headers); | ||
$this->addRequestHeaders($request, $headers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
|
||
namespace DDTrace\Integrations\Guzzle; | ||
|
||
use DDTrace\Integrations\Integration; | ||
use DDTrace\Util\CodeTracer; | ||
use DDTrace\Util\Versions; | ||
use DDTrace\Integrations\Guzzle\V5\GuzzleIntegrationLoader as V5Loader; | ||
use DDTrace\Integrations\Guzzle\V6\GuzzleIntegrationLoader as V6Loader; | ||
|
||
final class GuzzleIntegration | ||
{ | ||
const NAME = 'guzzle'; | ||
|
||
public static function load() | ||
{ | ||
if (Versions::phpVersionMatches('5.4')) { | ||
return Integration::NOT_AVAILABLE; | ||
} | ||
|
||
if (!defined('GuzzleHttp\ClientInterface::VERSION')) { | ||
return Integration::NOT_LOADED; | ||
} | ||
|
||
$version = \GuzzleHttp\ClientInterface::VERSION; | ||
|
||
if (Versions::versionMatches('5', $version)) { | ||
return (new V5Loader(CodeTracer::getInstance()))->load(self::NAME); | ||
} elseif (Versions::versionMatches('6', $version)) { | ||
return (new V6Loader(CodeTracer::getInstance()))->load(self::NAME); | ||
} | ||
|
||
return Integration::NOT_LOADED; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.