Skip to content

Commit 1f4dab6

Browse files
committed
Add exec integration
1 parent 8b7df34 commit 1f4dab6

File tree

23 files changed

+1711
-4
lines changed

23 files changed

+1711
-4
lines changed

bridge/_files_integrations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
__DIR__ . '/../src/Integrations/Integrations/AMQP/AMQPIntegration.php',
1212
__DIR__ . '/../src/Integrations/Integrations/CakePHP/CakePHPIntegration.php',
1313
__DIR__ . '/../src/Integrations/Integrations/CodeIgniter/V2/CodeIgniterIntegration.php',
14+
__DIR__ . '/../src/Integrations/Integrations/Exec/ExecIntegration.php',
1415
__DIR__ . '/../src/Integrations/Integrations/Drupal/DrupalIntegration.php',
1516
__DIR__ . '/../src/Integrations/Integrations/Web/WebIntegration.php',
1617
__DIR__ . '/../src/Integrations/Integrations/IntegrationsLoader.php',

config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ if test "$PHP_DDTRACE" != "no"; then
142142
ext/handlers_exception.c \
143143
ext/handlers_internal.c \
144144
ext/handlers_pcntl.c \
145+
ext/integrations/exec_integration.c \
145146
ext/integrations/integrations.c \
146147
ext/ip_extraction.c \
147148
ext/logging.c \

ext/ddtrace.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "excluded_modules.h"
4848
#include "handlers_http.h"
4949
#include "handlers_internal.h"
50+
#include "integrations/exec_integration.h"
5051
#include "integrations/integrations.h"
5152
#include "ip_extraction.h"
5253
#include "logging.h"
@@ -1098,6 +1099,10 @@ static PHP_RSHUTDOWN_FUNCTION(ddtrace) {
10981099

10991100
zend_hash_destroy(&DDTRACE_G(traced_spans));
11001101

1102+
// this needs to be done before dropping the spans
1103+
// run unconditionally because ddtrace may've been disabled mid-request
1104+
ddtrace_exec_handlers_rshutdown();
1105+
11011106
if (get_DD_TRACE_ENABLED()) {
11021107
dd_force_shutdown_tracing();
11031108
} else if (!DDTRACE_G(disable)) {

ext/handlers_internal.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "arrays.h"
44
#include "ddtrace.h"
5+
#include "integrations/exec_integration.h"
56

67
void ddtrace_free_unregistered_class(zend_class_entry *ce) {
78
#if PHP_VERSION_ID >= 80100
@@ -121,7 +122,7 @@ void ddtrace_exception_handlers_rinit(void);
121122

122123
void ddtrace_curl_handlers_rshutdown(void);
123124

124-
void ddtrace_internal_handlers_startup(void) {
125+
void ddtrace_internal_handlers_startup() {
125126
// On PHP 8.0 zend_execute_internal is not executed in JIT. Manually ensure internal hooks are executed.
126127
#if PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80200
127128
#if PHP_VERSION_ID >= 80100
@@ -139,6 +140,8 @@ void ddtrace_internal_handlers_startup(void) {
139140
ddtrace_pcntl_handlers_startup();
140141
// exception handlers have to run otherwise wrapping will fail horribly
141142
ddtrace_exception_handlers_startup();
143+
144+
ddtrace_exec_handlers_startup();
142145
}
143146

144147
void ddtrace_internal_handlers_shutdown(void) {
@@ -150,11 +153,18 @@ void ddtrace_internal_handlers_shutdown(void) {
150153
#if PHP_VERSION_ID < 80000
151154
ddtrace_curl_handlers_shutdown();
152155
#endif
156+
157+
ddtrace_exec_handlers_shutdown();
153158
}
154159

155160
void ddtrace_internal_handlers_rinit(void) {
156161
ddtrace_curl_handlers_rinit();
157162
ddtrace_exception_handlers_rinit();
163+
ddtrace_exec_handlers_rinit();
158164
}
159165

160-
void ddtrace_internal_handlers_rshutdown(void) { ddtrace_curl_handlers_rshutdown(); }
166+
void ddtrace_internal_handlers_rshutdown(void) {
167+
ddtrace_curl_handlers_rshutdown();
168+
// called earlier in zm_deactivate_ddtrace
169+
// ddtrace_exec_handlers_rshutdown();
170+
}

ext/hook/uhook.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ typedef struct {
5858
zval *retval_ptr;
5959
ddtrace_span_data *span;
6060
ddtrace_span_stack *prior_stack;
61+
bool returns_reference;
6162
} dd_hook_data;
6263

6364
typedef struct {
@@ -225,6 +226,7 @@ static bool dd_uhook_begin(zend_ulong invocation, zend_execute_data *execute_dat
225226
}
226227

227228
dyn->hook_data = (dd_hook_data *)dd_hook_data_create(ddtrace_hook_data_ce);
229+
dyn->hook_data->returns_reference = execute_data->func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE;
228230
dyn->hook_data->vm_stack_top = EG(vm_stack_top);
229231

230232
dyn->hook_data->invocation = invocation;
@@ -775,6 +777,12 @@ ZEND_METHOD(DDTrace_HookData, overrideReturnValue) {
775777
RETURN_FALSE;
776778
}
777779

780+
if (hookData->returns_reference) {
781+
ZVAL_MAKE_REF(retval);
782+
} else {
783+
ZVAL_DEREF(retval);
784+
}
785+
778786
zval_ptr_dtor(hookData->retval_ptr);
779787
ZVAL_COPY(hookData->retval_ptr, retval);
780788

0 commit comments

Comments
 (0)