Skip to content

Commit

Permalink
Refactor integration loading
Browse files Browse the repository at this point in the history
  • Loading branch information
SammyK committed Nov 27, 2018
1 parent 4801264 commit 11e1b1d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/DDTrace/Integrations/Guzzle/v5/GuzzleIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ class GuzzleIntegration extends Integration
{
const CLASS_NAME = 'GuzzleHttp\Client';

public static function load()
protected static function loadIntegration()
{
parent::load();
self::traceMethod('send', function (Span $span, array $args) {
$span->setTag('http.method', $args[0]->getMethod());
});
Expand Down
8 changes: 6 additions & 2 deletions src/DDTrace/Integrations/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ public static function load()
{
if (!extension_loaded('ddtrace')) {
trigger_error('The ddtrace extension is required to trace ' . static::CLASS_NAME, E_USER_WARNING);
return;
return false;
}
if (!class_exists(static::CLASS_NAME)) {
trigger_error(static::CLASS_NAME . ' is not loaded and cannot be traced', E_USER_WARNING);
return;
return false;
}
static::loadIntegration();
return true;
}

abstract protected static function loadIntegration();

/**
* @param string $method
* @param \Closure $spanMutator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ final class GuzzleIntegrationTest extends IntegrationTestCase

public static function setUpBeforeClass()
{
GuzzleIntegration::load();
if(!GuzzleIntegration::load()) {
self::markTestSkipped('Guzzle required to run tests.');
}
}

protected function setUp()
Expand Down

0 comments on commit 11e1b1d

Please sign in to comment.