-
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.
feat: Add CakePHP 3+ Support (#2618)
* feat: Add CakePHP 3 Support * tests: Test for 7.1+ (requires intl) + typo * feat: Retrieve extension, plugin, and theme information * tests: Add CakePHP v4.5 tests * tests: Add CakePHP v5.0 tests * style: Use `hook_method` * fix: Fetch root span from `\DDTrace\root_span()` * style: refactor common logic
- Loading branch information
Showing
285 changed files
with
12,634 additions
and
103 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
99 changes: 99 additions & 0 deletions
99
src/DDTrace/Integrations/CakePHP/V2/CakePHPIntegrationLoader.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,99 @@ | ||
<?php | ||
|
||
namespace DDTrace\Integrations\CakePHP\V2; | ||
|
||
use CakeRequest; | ||
use DDTrace\Integrations\CakePHP\CakePHPIntegration; | ||
use DDTrace\Integrations\Integration; | ||
use DDTrace\SpanData; | ||
use DDTrace\Tag; | ||
use DDTrace\Type; | ||
use DDTrace\Util\Normalizer; | ||
use Router; | ||
|
||
class CakePHPIntegrationLoader | ||
{ | ||
// CakePHP v2.x - we don't need to check for v3 since it does not have \Dispatcher or \ShellDispatcher | ||
public function load($integration) | ||
{ | ||
if (!defined('CAKE_CORE_INCLUDE_PATH')) { | ||
return Integration::NOT_AVAILABLE; | ||
} | ||
|
||
\DDTrace\hook_method('App', 'init', $integration->setRootSpanInfoFn); | ||
\DDTrace\hook_method('Dispatcher', '__construct', $integration->setRootSpanInfoFn); | ||
|
||
\DDTrace\trace_method( | ||
'Controller', | ||
'invokeAction', | ||
function (SpanData $span, array $args) use ($integration) { | ||
$span->name = $span->resource = 'Controller.invokeAction'; | ||
$span->type = Type::WEB_SERVLET; | ||
$span->service = $integration->appName; | ||
$span->meta[Tag::COMPONENT] = CakePHPIntegration::NAME; | ||
|
||
$request = $args[0]; | ||
if (!$request instanceof CakeRequest) { | ||
return; | ||
} | ||
|
||
$rootSpan = \DDTrace\root_span(); | ||
|
||
if (dd_trace_env_config("DD_HTTP_SERVER_ROUTE_BASED_NAMING")) { | ||
$rootSpan->resource = | ||
$_SERVER['REQUEST_METHOD'] . ' ' . $this->name . 'Controller@' . $request->params['action']; | ||
} | ||
|
||
if (!array_key_exists(Tag::HTTP_URL, $rootSpan->meta)) { | ||
$rootSpan->meta[Tag::HTTP_URL] = Router::url($request->here, true) | ||
. Normalizer::sanitizedQueryString(); | ||
} | ||
$rootSpan->meta['cakephp.route.controller'] = $request->params['controller']; | ||
$rootSpan->meta['cakephp.route.action'] = $request->params['action']; | ||
if (isset($request->params['plugin'])) { | ||
$rootSpan->meta['cakephp.plugin'] = $request->params['plugin']; | ||
} | ||
} | ||
); | ||
|
||
// This only traces the default exception renderer | ||
// Remove this when error tracking is added | ||
// Other possible places to trace | ||
// - ErrorHandler::handleException() | ||
// - Controller::appError() | ||
// - Exception.handler | ||
// - Exception.renderer | ||
\DDTrace\hook_method( | ||
'ExceptionRenderer', | ||
'__construct', | ||
$integration->handleExceptionFn | ||
); | ||
|
||
\DDTrace\hook_method( | ||
'CakeResponse', | ||
'statusCode', | ||
null, | ||
$integration->setStatusCodeFn | ||
); | ||
|
||
// Create a trace span for every template rendered | ||
\DDTrace\trace_method('View', 'render', function (SpanData $span) use ($integration) { | ||
$span->name = 'cakephp.view'; | ||
$span->type = Type::WEB_SERVLET; | ||
$file = $this->viewPath . '/' . $this->view . $this->ext; | ||
$span->resource = $file; | ||
$span->meta = ['cakephp.view' => $file]; | ||
$span->service = $integration->appName; | ||
$span->meta[Tag::COMPONENT] = CakePHPIntegration::NAME; | ||
}); | ||
|
||
\DDTrace\hook_method( | ||
'CakeRoute', | ||
'parse', | ||
null, | ||
$integration->parseRouteFn | ||
); | ||
|
||
return Integration::LOADED; | ||
} | ||
} |
Oops, something went wrong.