Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exec integration #2361

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bridge/_files_integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
__DIR__ . '/../src/Integrations/Integrations/AMQP/AMQPIntegration.php',
__DIR__ . '/../src/Integrations/Integrations/CakePHP/CakePHPIntegration.php',
__DIR__ . '/../src/Integrations/Integrations/CodeIgniter/V2/CodeIgniterIntegration.php',
__DIR__ . '/../src/Integrations/Integrations/Exec/ExecIntegration.php',
__DIR__ . '/../src/Integrations/Integrations/Drupal/DrupalIntegration.php',
__DIR__ . '/../src/Integrations/Integrations/Web/WebIntegration.php',
__DIR__ . '/../src/Integrations/Integrations/IntegrationsLoader.php',
Expand Down
1 change: 1 addition & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ if test "$PHP_DDTRACE" != "no"; then
ext/handlers_exception.c \
ext/handlers_internal.c \
ext/handlers_pcntl.c \
ext/integrations/exec_integration.c \
ext/integrations/integrations.c \
ext/ip_extraction.c \
ext/logging.c \
Expand Down
5 changes: 5 additions & 0 deletions ext/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "excluded_modules.h"
#include "handlers_http.h"
#include "handlers_internal.h"
#include "integrations/exec_integration.h"
#include "integrations/integrations.h"
#include "ip_extraction.h"
#include "logging.h"
Expand Down Expand Up @@ -1100,6 +1101,10 @@ static PHP_RSHUTDOWN_FUNCTION(ddtrace) {

zend_hash_destroy(&DDTRACE_G(traced_spans));

// this needs to be done before dropping the spans
// run unconditionally because ddtrace may've been disabled mid-request
ddtrace_exec_handlers_rshutdown();

if (get_DD_TRACE_ENABLED()) {
dd_force_shutdown_tracing();
} else if (!DDTRACE_G(disable)) {
Expand Down
19 changes: 17 additions & 2 deletions ext/handlers_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "arrays.h"
#include "ddtrace.h"
#include "integrations/exec_integration.h"

void ddtrace_free_unregistered_class(zend_class_entry *ce) {
#if PHP_VERSION_ID >= 80100
Expand Down Expand Up @@ -108,6 +109,11 @@ static void dd_install_internal_handlers(void) {
dd_install_internal_function("curl_exec");
dd_install_internal_function("pcntl_fork");
dd_install_internal_function("pcntl_rfork");
dd_install_internal_function("DDTrace\\Integrations\\Exec\\register_stream");
dd_install_internal_function("DDTrace\\Integrations\\Exec\\proc_assoc_span");
dd_install_internal_function("DDTrace\\Integrations\\Exec\\proc_get_span");
dd_install_internal_function("DDTrace\\Integrations\\Exec\\proc_get_pid");
dd_install_internal_function("DDTrace\\Integrations\\Exec\\test_rshutdown");
}
#endif

Expand All @@ -121,7 +127,7 @@ void ddtrace_exception_handlers_rinit(void);

void ddtrace_curl_handlers_rshutdown(void);

void ddtrace_internal_handlers_startup(void) {
void ddtrace_internal_handlers_startup() {
// On PHP 8.0 zend_execute_internal is not executed in JIT. Manually ensure internal hooks are executed.
#if PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80200
#if PHP_VERSION_ID >= 80100
Expand All @@ -139,6 +145,8 @@ void ddtrace_internal_handlers_startup(void) {
ddtrace_pcntl_handlers_startup();
// exception handlers have to run otherwise wrapping will fail horribly
ddtrace_exception_handlers_startup();

ddtrace_exec_handlers_startup();
}

void ddtrace_internal_handlers_shutdown(void) {
Expand All @@ -150,11 +158,18 @@ void ddtrace_internal_handlers_shutdown(void) {
#if PHP_VERSION_ID < 80000
ddtrace_curl_handlers_shutdown();
#endif

ddtrace_exec_handlers_shutdown();
}

void ddtrace_internal_handlers_rinit(void) {
ddtrace_curl_handlers_rinit();
ddtrace_exception_handlers_rinit();
ddtrace_exec_handlers_rinit();
}

void ddtrace_internal_handlers_rshutdown(void) { ddtrace_curl_handlers_rshutdown(); }
void ddtrace_internal_handlers_rshutdown(void) {
ddtrace_curl_handlers_rshutdown();
// called earlier in zm_deactivate_ddtrace
// ddtrace_exec_handlers_rshutdown();
cataphract marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 8 additions & 0 deletions ext/hook/uhook.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef struct {
zval *retval_ptr;
ddtrace_span_data *span;
ddtrace_span_stack *prior_stack;
bool returns_reference;
} dd_hook_data;

typedef struct {
Expand Down Expand Up @@ -225,6 +226,7 @@ static bool dd_uhook_begin(zend_ulong invocation, zend_execute_data *execute_dat
}

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

dyn->hook_data->invocation = invocation;
Expand Down Expand Up @@ -775,6 +777,12 @@ ZEND_METHOD(DDTrace_HookData, overrideReturnValue) {
RETURN_FALSE;
}

if (hookData->returns_reference) {
ZVAL_MAKE_REF(retval);
} else {
ZVAL_DEREF(retval);
}

zval_ptr_dtor(hookData->retval_ptr);
ZVAL_COPY(hookData->retval_ptr, retval);

Expand Down
Loading
Loading