Skip to content

Commit ce7e8dd

Browse files
committed
Make integrations static
Signed-off-by: Bob Weinand <[email protected]>
1 parent 9b0c55d commit ce7e8dd

File tree

60 files changed

+1141
-1354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1141
-1354
lines changed

ext/ddtrace.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ interface Integration {
363363
const NOT_AVAILABLE = UNKNOWN;
364364

365365
/** Load the integration */
366-
public function init(): int;
366+
public static function init(): int;
367367
}
368368

369369
// phpcs:disable Generic.Files.LineLength.TooLong

ext/ddtrace_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 2fa8c7fb33e71ec0fb70c54ba57a8c5281e6e8d8 */
2+
* Stub hash: 88f47f7df088bcf13cf114f886599855d7b5b2aa */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_trace_method, 0, 3, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, className, IS_STRING, 0)
@@ -518,7 +518,7 @@ static const zend_function_entry class_DDTrace_SpanData_methods[] = {
518518
};
519519

520520
static const zend_function_entry class_DDTrace_Integration_methods[] = {
521-
ZEND_RAW_FENTRY("init", NULL, arginfo_class_DDTrace_Integration_init, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT, NULL, NULL)
521+
ZEND_RAW_FENTRY("init", NULL, arginfo_class_DDTrace_Integration_init, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT, NULL, NULL)
522522
ZEND_FE_END
523523
};
524524

ext/integrations/integrations.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,14 @@ static void dd_invoke_integration_loader_and_unhook_posthook(zend_ulong invocati
111111
break;
112112
}
113113

114-
zval obj;
115-
if (!zai_symbol_new(&obj, ce, 0)) {
116-
break;
117-
}
118-
119114
zval rv;
120115
zval *thisp = getThis();
121116
if (thisp) {
122-
success = zai_symbol_call_named(ZAI_SYMBOL_SCOPE_OBJECT, &obj, &(zai_str) ZAI_STRL("init"), &rv, 1 | ZAI_SYMBOL_SANDBOX, &sandbox, thisp);
117+
success = zai_symbol_call_static(ce, (zai_str) ZAI_STRL("init"), &rv, 1 | ZAI_SYMBOL_SANDBOX, &sandbox, thisp);
123118
} else {
124-
success = zai_symbol_call_named(ZAI_SYMBOL_SCOPE_OBJECT, &obj, &(zai_str) ZAI_STRL("init"), &rv, 0 | ZAI_SYMBOL_SANDBOX, &sandbox);
119+
success = zai_symbol_call_static(ce, (zai_str) ZAI_STRL("init"), &rv, 0 | ZAI_SYMBOL_SANDBOX, &sandbox);
125120
}
126121

127-
zval_ptr_dtor(&obj);
128-
129122
if (success && get_DD_TRACE_ENABLED()) {
130123
switch (Z_LVAL(rv)) {
131124
case DD_TRACE_INTEGRATION_LOADED:

src/DDTrace/Integrations/AMQP/AMQPIntegration.php

Lines changed: 74 additions & 77 deletions
Large diffs are not rendered by default.

src/DDTrace/Integrations/CakePHP/CakePHPIntegration.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,32 @@ class CakePHPIntegration extends Integration
1111
{
1212
const NAME = 'cakephp';
1313

14-
public $appName;
15-
public $rootSpan;
16-
public $setRootSpanInfoFn;
17-
public $handleExceptionFn;
18-
public $setStatusCodeFn;
19-
public $parseRouteFn;
14+
public static $appName;
15+
public static $rootSpan;
16+
public static $setRootSpanInfoFn;
17+
public static $handleExceptionFn;
18+
public static $setStatusCodeFn;
19+
public static $parseRouteFn;
2020

2121
/**
2222
* {@inheritdoc}
2323
*/
24-
public function requiresExplicitTraceAnalyticsEnabling(): bool
24+
public static function requiresExplicitTraceAnalyticsEnabling(): bool
2525
{
2626
return false;
2727
}
2828

29-
public function init(): int
29+
public static function init(): int
3030
{
31-
$integration = $this;
32-
33-
$integration->setRootSpanInfoFn = function () use ($integration) {
31+
self::$setRootSpanInfoFn = function () {
3432
$rootSpan = \DDTrace\root_span();
3533
if ($rootSpan === null) {
3634
return;
3735
}
3836

39-
$integration->appName = \ddtrace_config_app_name(CakePHPIntegration::NAME);
40-
$integration->addTraceAnalyticsIfEnabled($rootSpan);
41-
$rootSpan->service = $integration->appName;
37+
self::$appName = \ddtrace_config_app_name(CakePHPIntegration::NAME);
38+
self::addTraceAnalyticsIfEnabled($rootSpan);
39+
$rootSpan->service = self::$appName;
4240
if ('cli' === PHP_SAPI) {
4341
$rootSpan->name = 'cakephp.console';
4442
$rootSpan->resource = !empty($_SERVER['argv'][1])
@@ -51,21 +49,21 @@ public function init(): int
5149
$rootSpan->meta[Tag::COMPONENT] = CakePHPIntegration::NAME;
5250
};
5351

54-
$integration->handleExceptionFn = function ($This, $scope, $args) use ($integration) {
52+
self::$handleExceptionFn = function ($This, $scope, $args) {
5553
$rootSpan = \DDTrace\root_span();
5654
if ($rootSpan !== null) {
5755
$rootSpan->exception = $args[0];
5856
}
5957
};
6058

61-
$integration->setStatusCodeFn = function ($This, $scope, $args, $retval) use ($integration) {
59+
self::$setStatusCodeFn = function ($This, $scope, $args, $retval) {
6260
$rootSpan = \DDTrace\root_span();
6361
if ($rootSpan) {
6462
$rootSpan->meta[Tag::HTTP_STATUS_CODE] = $retval;
6563
}
6664
};
6765

68-
$integration->parseRouteFn = function ($app, $appClass, $args, $retval) use ($integration) {
66+
self::$parseRouteFn = function ($app, $appClass, $args, $retval) {
6967
if (!$retval) {
7068
return;
7169
}
@@ -76,9 +74,8 @@ public function init(): int
7674
}
7775
};
7876

79-
$loader = class_exists('Cake\Http\Server') // Only exists in V3+
80-
? new CakePHPIntegrationLoaderV3()
81-
: new CakePHPIntegrationLoaderV2();
82-
return $loader->load($integration);
77+
return class_exists('Cake\Http\Server') // Only exists in V3+
78+
? CakePHPIntegrationLoaderV3::load()
79+
: CakePHPIntegrationLoaderV2::load();
8380
}
8481
}

src/DDTrace/Integrations/CakePHP/V2/CakePHPIntegrationLoader.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
class CakePHPIntegrationLoader
1515
{
1616
// CakePHP v2.x - we don't need to check for v3 since it does not have \Dispatcher or \ShellDispatcher
17-
public function load($integration)
17+
public static function load()
1818
{
1919
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
2020
return Integration::NOT_AVAILABLE;
2121
}
2222

23-
\DDTrace\hook_method('App', 'init', $integration->setRootSpanInfoFn);
24-
\DDTrace\hook_method('Dispatcher', '__construct', $integration->setRootSpanInfoFn);
23+
\DDTrace\hook_method('App', 'init', CakePHPIntegration::$setRootSpanInfoFn);
24+
\DDTrace\hook_method('Dispatcher', '__construct', CakePHPIntegration::$setRootSpanInfoFn);
2525

2626
\DDTrace\trace_method(
2727
'Controller',
2828
'invokeAction',
29-
function (SpanData $span, array $args) use ($integration) {
29+
function (SpanData $span, array $args) {
3030
$span->name = $span->resource = 'Controller.invokeAction';
3131
$span->type = Type::WEB_SERVLET;
32-
$span->service = $integration->appName;
32+
$span->service = CakePHPIntegration::$appName;
3333
$span->meta[Tag::COMPONENT] = CakePHPIntegration::NAME;
3434

3535
$request = $args[0];
@@ -66,32 +66,32 @@ function (SpanData $span, array $args) use ($integration) {
6666
\DDTrace\hook_method(
6767
'ExceptionRenderer',
6868
'__construct',
69-
$integration->handleExceptionFn
69+
CakePHPIntegration::$handleExceptionFn
7070
);
7171

7272
\DDTrace\hook_method(
7373
'CakeResponse',
7474
'statusCode',
7575
null,
76-
$integration->setStatusCodeFn
76+
CakePHPIntegration::$setStatusCodeFn
7777
);
7878

7979
// Create a trace span for every template rendered
80-
\DDTrace\trace_method('View', 'render', function (SpanData $span) use ($integration) {
80+
\DDTrace\trace_method('View', 'render', function (SpanData $span) {
8181
$span->name = 'cakephp.view';
8282
$span->type = Type::WEB_SERVLET;
8383
$file = $this->viewPath . '/' . $this->view . $this->ext;
8484
$span->resource = $file;
8585
$span->meta = ['cakephp.view' => $file];
86-
$span->service = $integration->appName;
86+
$span->service = CakePHPIntegration::$appName;
8787
$span->meta[Tag::COMPONENT] = CakePHPIntegration::NAME;
8888
});
8989

9090
\DDTrace\hook_method(
9191
'CakeRoute',
9292
'parse',
9393
null,
94-
$integration->parseRouteFn
94+
CakePHPIntegration::$parseRouteFn
9595
);
9696

9797
return Integration::LOADED;

src/DDTrace/Integrations/CakePHP/V3/CakePHPIntegrationLoader.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
class CakePHPIntegrationLoader
1616
{
17-
public function load($integration)
17+
public static function load()
1818
{
19-
\DDTrace\hook_method('App\Application', '__construct', $integration->setRootSpanInfoFn);
20-
\DDTrace\hook_method('Cake\Http\Server', '__construct', $integration->setRootSpanInfoFn);
19+
\DDTrace\hook_method('App\Application', '__construct', CakePHPIntegration::$setRootSpanInfoFn);
20+
\DDTrace\hook_method('Cake\Http\Server', '__construct', CakePHPIntegration::$setRootSpanInfoFn);
2121

2222
\DDTrace\trace_method(
2323
'Cake\Controller\Controller',
2424
'invokeAction',
25-
function (SpanData $span) use ($integration) {
25+
function (SpanData $span) {
2626
$span->name = $span->resource = 'Controller.invokeAction';
2727
$span->type = Type::WEB_SERVLET;
28-
$span->service = $integration->appName;
28+
$span->service = CakePHPIntegration::$appName;
2929
$span->meta[Tag::COMPONENT] = CakePHPIntegration::NAME;
3030

3131
/** @var \Cake\Controller\Controller $this */
@@ -57,14 +57,14 @@ function (SpanData $span) use ($integration) {
5757
\DDTrace\hook_method(
5858
'Cake\Error\Middleware\ErrorHandlerMiddleware',
5959
'handleException',
60-
$integration->handleExceptionFn
60+
CakePHPIntegration::$handleExceptionFn
6161
);
6262

6363
\DDTrace\hook_method(
6464
'Cake\Http\Response',
6565
'getStatusCode',
6666
null,
67-
$integration->setStatusCodeFn
67+
CakePHPIntegration::$setStatusCodeFn
6868
);
6969

7070
// Create a trace span for every template rendered
@@ -86,11 +86,11 @@ function (HookData $hook) use ($renderHook) {
8686
\DDTrace\remove_hook($hook->id);
8787
}
8888
);
89-
}, function (HookData $renderHook) use ($integration) {
89+
}, function (HookData $renderHook) {
9090
$span = $renderHook->span();
9191
$span->name = 'cakephp.view';
9292
$span->type = Type::WEB_SERVLET;
93-
$span->service = $integration->appName;
93+
$span->service = CakePHPIntegration::$appName;
9494
$span->meta[Tag::COMPONENT] = CakePHPIntegration::NAME;
9595

9696
$absoluteFilePath = $renderHook->data['viewFileName'] ?? '';
@@ -116,7 +116,7 @@ function (HookData $hook) use ($renderHook) {
116116
'Cake\Routing\Route\Route',
117117
'parseRequest',
118118
null,
119-
$integration->parseRouteFn
119+
CakePHPIntegration::$parseRouteFn
120120
);
121121

122122
return Integration::LOADED;

src/DDTrace/Integrations/CodeIgniter/V2/CodeIgniterIntegration.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ class CodeIgniterIntegration extends Integration
1515
/**
1616
* Add instrumentation to CodeIgniter requests
1717
*/
18-
public function init($router = null): int
18+
public static function init($router = null): int
1919
{
20-
$integration = $this;
2120
$rootSpan = \DDTrace\root_span();
2221
if (null === $rootSpan) {
2322
return Integration::NOT_LOADED;
@@ -32,15 +31,15 @@ public function init($router = null): int
3231
/* After _set_routing has been called the class and method
3332
* are known, so now we can set up tracing on CodeIgniter.
3433
*/
35-
$integration->registerIntegration($router, $rootSpan, $service);
34+
self::registerIntegration($router, $rootSpan, $service);
3635
}
3736

3837
return parent::LOADED;
3938
}
4039

41-
public function registerIntegration(\CI_Router $router, SpanData $rootSpan, $service)
40+
public static function registerIntegration(\CI_Router $router, SpanData $rootSpan, $service)
4241
{
43-
$this->addTraceAnalyticsIfEnabled($rootSpan);
42+
self::addTraceAnalyticsIfEnabled($rootSpan);
4443
$rootSpan->name = 'codeigniter.request';
4544
$rootSpan->service = $service;
4645
$rootSpan->type = Type::WEB_SERVLET;

0 commit comments

Comments
 (0)