Skip to content

Commit 4aac38f

Browse files
committed
Use WeakMap for frankenphp closure
Signed-off-by: Bob Weinand <[email protected]>
1 parent b3baee8 commit 4aac38f

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

ext/integrations/integrations.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ void ddtrace_integrations_minit(void) {
192192
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_ELOQUENT, "Illuminate\\Database\\Eloquent\\Model", "destroy",
193193
"DDTrace\\Integrations\\Eloquent\\EloquentIntegration");
194194

195+
#if PHP_VERSION_ID >= 80200
195196
DD_SET_UP_DEFERRED_LOADING_BY_FUNCTION(DDTRACE_INTEGRATION_FRANKENPHP, "frankenphp_handle_request",
196197
"DDTrace\\Integrations\\Frankenphp\\FrankenphpIntegration");
198+
#endif
197199

198200
DD_SET_UP_DEFERRED_LOADING_BY_METHOD(DDTRACE_INTEGRATION_GUZZLE, "GuzzleHttp\\Client", "__construct",
199201
"DDTrace\\Integrations\\Guzzle\\GuzzleIntegration");

src/Integrations/Integrations/Frankenphp/FrankenphpIntegration.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ public function init()
3434
ini_set("datadog.trace.auto_flush_enabled", 1);
3535
ini_set("datadog.trace.generate_root_span", 0);
3636

37-
\DDTrace\install_hook('frankenphp_handle_request', function (HookData $hook) use ($integration) {
38-
$hook->data = \DDTrace\install_hook(
39-
$hook->args[0],
37+
$is_hooked = new \WeakMap();
38+
\DDTrace\install_hook('frankenphp_handle_request', function (HookData $hook) use ($integration, $is_hooked) {
39+
$handler = $hook->args[0];
40+
if (isset($is_hooked[$handler])) {
41+
return;
42+
}
43+
$is_hooked[$handler] = true;
44+
45+
\DDTrace\install_hook(
46+
$handler,
4047
function (HookData $hook) use ($integration) {
4148
$rootSpan = $hook->span(new SpanStack());
4249
$rootSpan->name = "web.request";
@@ -48,10 +55,10 @@ function (HookData $hook) use ($integration) {
4855
$integration->addTraceAnalyticsIfEnabled($rootSpan);
4956

5057
consume_distributed_tracing_headers(null);
51-
}
58+
},
59+
null,
60+
\DDTrace\HOOK_INSTANCE
5261
);
53-
}, function (HookData $hook) {
54-
\DDTrace\remove_hook($hook->data);
5562
});
5663

5764
return Integration::LOADED;

0 commit comments

Comments
 (0)