Skip to content

Commit

Permalink
Remove singleton from SandboxedIntegration
Browse files Browse the repository at this point in the history
  • Loading branch information
SammyK committed Sep 9, 2019
1 parent c917b88 commit b6d378a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/DDTrace/Integrations/Guzzle/GuzzleIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class GuzzleIntegration extends Integration
*/
private static $instance;

protected function __construct()
public function __construct()
{
parent::__construct();
$this->codeTracer = CodeTracer::getInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/DDTrace/Integrations/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class Integration
abstract public function getName();


protected function __construct()
public function __construct()
{
$this->configuration = $this->buildConfiguration();
}
Expand Down
3 changes: 2 additions & 1 deletion src/DDTrace/Integrations/IntegrationsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public function loadAll()
}

if (strpos($class, 'SandboxedIntegration') !== false) {
$this->loadings[$name] = $class::get()->init();
$integration = new $class();
$this->loadings[$name] = $integration->init();
} else {
$this->loadings[$name] = $class::load();
}
Expand Down
14 changes: 8 additions & 6 deletions src/DDTrace/Integrations/PDO/PDOSandboxedIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function init()
return SandboxedIntegration::NOT_AVAILABLE;
}

$integration = $this;

// public PDO::__construct ( string $dsn [, string $username [, string $passwd [, array $options ]]] )
dd_trace_method('PDO', '__construct', function (SpanData $span, array $args) {
$span->name = $span->resource = 'PDO.__construct';
Expand All @@ -48,7 +50,7 @@ public function init()
});

// public int PDO::exec(string $query)
dd_trace_method('PDO', 'exec', function (SpanData $span, array $args, $retval) {
dd_trace_method('PDO', 'exec', function (SpanData $span, array $args, $retval) use ($integration) {
$span->name = 'PDO.exec';
$span->resource = $args[0];
$span->service = 'PDO';
Expand All @@ -59,7 +61,7 @@ public function init()
];
}
PDOSandboxedIntegration::setConnectionTags($this, $span);
PDOSandboxedIntegration::get()->addTraceAnalyticsIfEnabled($span);
$integration->addTraceAnalyticsIfEnabled($span);
PDOSandboxedIntegration::detectError($this, $span);
});

Expand All @@ -68,7 +70,7 @@ public function init()
// public PDOStatement PDO::query(string $query, int PDO::FETCH_CLASS, string $classname, array $ctorargs)
// public PDOStatement PDO::query(string $query, int PDO::FETCH_INFO, object $object)
// public int PDO::exec(string $query)
dd_trace_method('PDO', 'query', function (SpanData $span, array $args, $retval) {
dd_trace_method('PDO', 'query', function (SpanData $span, array $args, $retval) use ($integration) {
$span->name = 'PDO.query';
$span->resource = $args[0];
$span->service = 'PDO';
Expand All @@ -80,7 +82,7 @@ public function init()
PDOSandboxedIntegration::storeStatementFromConnection($this, $retval);
}
PDOSandboxedIntegration::setConnectionTags($this, $span);
PDOSandboxedIntegration::get()->addTraceAnalyticsIfEnabled($span);
$integration->addTraceAnalyticsIfEnabled($span);
PDOSandboxedIntegration::detectError($this, $span);
});

Expand All @@ -103,7 +105,7 @@ public function init()
});

// public bool PDOStatement::execute ([ array $input_parameters ] )
dd_trace_method('PDOStatement', 'execute', function (SpanData $span, array $args, $retval) {
dd_trace_method('PDOStatement', 'execute', function (SpanData $span, array $args, $retval) use ($integration) {
$span->name = 'PDOStatement.execute';
$span->resource = $this->queryString;
$span->service = 'PDO';
Expand All @@ -114,7 +116,7 @@ public function init()
];
}
PDOSandboxedIntegration::setStatementTags($this, $span);
PDOSandboxedIntegration::get()->addTraceAnalyticsIfEnabled($span);
$integration->addTraceAnalyticsIfEnabled($span);
PDOSandboxedIntegration::detectError($this, $span);
});

Expand Down
16 changes: 0 additions & 16 deletions src/DDTrace/Integrations/SandboxedIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@

abstract class SandboxedIntegration extends Integration
{
/**
* @var self
*/
private static $instance;

/**
* @return self
*/
public static function get()
{
if (null === self::$instance) {
self::$instance = new static();
}
return self::$instance;
}

/**
* Load the integration
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Common/Model/DummyIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class DummyIntegration extends Integration
* DummyIntegration constructor.
* @param $name
*/
protected function __construct($name)
public function __construct($name)
{
parent::__construct();
$this->name = $name;
Expand Down

0 comments on commit b6d378a

Please sign in to comment.