-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #559 from DataDog/labbati/sandboxing-eloquent
Migrate eloquent integration to sandboxed API
- Loading branch information
Showing
34 changed files
with
794 additions
and
63 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
130 changes: 130 additions & 0 deletions
130
src/DDTrace/Integrations/Eloquent/EloquentSandboxedIntegration.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,130 @@ | ||
<?php | ||
|
||
namespace DDTrace\Integrations\Eloquent; | ||
|
||
use DDTrace\Configuration; | ||
use DDTrace\Integrations\Integration; | ||
use DDTrace\Integrations\SandboxedIntegration; | ||
use DDTrace\SpanData; | ||
use DDTrace\Tag; | ||
use DDTrace\Type; | ||
|
||
class EloquentSandboxedIntegration extends SandboxedIntegration | ||
{ | ||
const NAME = 'eloquent'; | ||
|
||
/** | ||
* @var string The app name. Note that this value is used as a cache, you should use method getAppName(). | ||
*/ | ||
private $appName; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return self::NAME; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function init() | ||
{ | ||
$integration = $this; | ||
|
||
dd_trace_method( | ||
'Illuminate\Database\Eloquent\Builder', | ||
'getModels', | ||
function (SpanData $span) use ($integration) { | ||
$span->name = 'eloquent.get'; | ||
$sql = $this->getQuery()->toSql(); | ||
$span->resource = $sql; | ||
$span->meta[Tag::DB_STATEMENT] = $sql; | ||
$integration->setCommonValues($span); | ||
} | ||
); | ||
|
||
dd_trace_method( | ||
'Illuminate\Database\Eloquent\Model', | ||
'performInsert', | ||
function (SpanData $span) use ($integration) { | ||
$span->name = 'eloquent.insert'; | ||
$span->resource = get_class($this); | ||
$integration->setCommonValues($span); | ||
} | ||
); | ||
|
||
dd_trace_method( | ||
'Illuminate\Database\Eloquent\Model', | ||
'performUpdate', | ||
function (SpanData $span) use ($integration) { | ||
$span->name = 'eloquent.update'; | ||
$span->resource = get_class($this); | ||
$integration->setCommonValues($span); | ||
} | ||
); | ||
|
||
dd_trace_method( | ||
'Illuminate\Database\Eloquent\Model', | ||
'delete', | ||
function (SpanData $span) use ($integration) { | ||
$span->name = 'eloquent.delete'; | ||
$span->resource = get_class($this); | ||
$integration->setCommonValues($span); | ||
} | ||
); | ||
|
||
dd_trace_method( | ||
'Illuminate\Database\Eloquent\Model', | ||
'destroy', | ||
function (SpanData $span) use ($integration) { | ||
$span->name = 'eloquent.destroy'; | ||
$span->resource = get_called_class(); | ||
$integration->setCommonValues($span); | ||
} | ||
); | ||
|
||
dd_trace_method( | ||
'Illuminate\Database\Eloquent\Model', | ||
'refresh', | ||
function (SpanData $span) use ($integration) { | ||
$span->name = 'eloquent.refresh'; | ||
$span->resource = get_class($this); | ||
$integration->setCommonValues($span); | ||
} | ||
); | ||
|
||
return Integration::LOADED; | ||
} | ||
|
||
/** | ||
* Set common values shared by many different spans. | ||
* | ||
* @param SpanData $span | ||
*/ | ||
public function setCommonValues(SpanData $span) | ||
{ | ||
$span->type = Type::SQL; | ||
$span->service = $this->getAppName(); | ||
$span->meta[Tag::INTEGRATION_NAME] = $this->getName(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAppName() | ||
{ | ||
if (null !== $this->appName) { | ||
return $this->appName; | ||
} | ||
|
||
$name = Configuration::get()->appName(); | ||
if (empty($name) && is_callable('config')) { | ||
$name = config('app.name'); | ||
} | ||
|
||
$this->appName = $name ?: 'laravel'; | ||
return $this->appName; | ||
} | ||
} |
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
Oops, something went wrong.