Skip to content

Commit fc8379a

Browse files
committed
Fix distributed tracing on PHP 8
The curl extension API was upgraded from a resource to an object in php/php-src#5402.
1 parent 2ebb9c1 commit fc8379a

21 files changed

+189
-394
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,11 @@ TEST_WEB_74 := \
476476
test_opentracing_10
477477

478478
TEST_INTEGRATIONS_80 := \
479+
test_integrations_curl \
479480
test_integrations_mysqli \
480481
test_integrations_pdo \
482+
test_integrations_guzzle5 \
483+
test_integrations_guzzle6 \
481484
test_integrations_predis1
482485

483486
TEST_WEB_80 := \
File renamed without changes.

bridge/dd_init.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ function_exists('dd_trace_internal_fn') && \dd_trace_internal_fn('ddtrace_reload
6060

6161
// Required classes and functions
6262
require __DIR__ . '/autoload.php';
63-
if (\PHP_MAJOR_VERSION === 5) {
64-
require __DIR__ . '/php5.php';
63+
if (\PHP_MAJOR_VERSION === 8 || \PHP_MAJOR_VERSION === 5) {
64+
require __DIR__ . '/curl_inject.php';
6565
}
6666

6767
// Optional classes and functions

config.m4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ if test "$PHP_DDTRACE" != "no"; then
162162
ext/php8/configuration_php_iface.c \
163163
ext/php8/ddtrace_string.c \
164164
ext/php8/dispatch.c \
165-
ext/php8/distributed_tracing.c \
166165
ext/php8/dogstatsd_client.c \
167166
ext/php8/engine_api.c \
168167
ext/php8/engine_hooks.c \

ext/php8/ddtrace.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "ddtrace.h"
3737
#include "ddtrace_string.h"
3838
#include "dispatch.h"
39-
#include "distributed_tracing.h"
4039
#include "dogstatsd_client.h"
4140
#include "engine_hooks.h"
4241
#include "excluded_modules.h"
@@ -420,10 +419,10 @@ static PHP_RINIT_FUNCTION(ddtrace) {
420419
dd_request_init_hook_rinit(TSRMLS_C);
421420
}
422421

422+
ddtrace_internal_handlers_rinit();
423423
ddtrace_engine_hooks_rinit(TSRMLS_C);
424424
ddtrace_bgs_log_rinit(PG(error_log));
425425
ddtrace_dispatch_init(TSRMLS_C);
426-
ddtrace_distributed_tracing_rinit(TSRMLS_C);
427426
DDTRACE_G(disable_in_current_request) = 0;
428427

429428
ddtrace_dogstatsd_client_rinit(TSRMLS_C);
@@ -458,7 +457,6 @@ static PHP_RSHUTDOWN_FUNCTION(ddtrace) {
458457
ddtrace_internal_handlers_rshutdown();
459458
ddtrace_dogstatsd_client_rshutdown(TSRMLS_C);
460459

461-
ddtrace_distributed_tracing_rshutdown(TSRMLS_C);
462460
ddtrace_dispatch_destroy(TSRMLS_C);
463461
ddtrace_free_span_id_stack(TSRMLS_C);
464462
ddtrace_free_span_stacks(TSRMLS_C);

ext/php8/ddtrace.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ extern zend_class_entry *ddtrace_ce_fatal_error;
1515
typedef struct ddtrace_span_ids_t ddtrace_span_ids_t;
1616
typedef struct ddtrace_span_fci ddtrace_span_fci;
1717

18-
#if PHP_VERSION_ID >= 70000
1918
zval *ddtrace_spandata_property_name(zval *spandata);
2019
zval *ddtrace_spandata_property_resource(zval *spandata);
2120
zval *ddtrace_spandata_property_service(zval *spandata);
2221
zval *ddtrace_spandata_property_type(zval *spandata);
2322
zval *ddtrace_spandata_property_meta(zval *spandata);
2423
zval *ddtrace_spandata_property_metrics(zval *spandata);
25-
#endif
2624

2725
BOOL_T ddtrace_tracer_is_limited(TSRMLS_D);
2826

@@ -45,25 +43,6 @@ ZEND_BEGIN_MODULE_GLOBALS(ddtrace)
4543
char *dogstatsd_port;
4644
char *dogstatsd_buffer;
4745

48-
// PHP 7 uses ZEND_TLS for these
49-
#if PHP_VERSION_ID < 70000
50-
// Distributed tracing & curl
51-
HashTable *dt_http_saved_curl_headers;
52-
zend_bool back_up_http_headers;
53-
54-
/* These ones are used for measuring the call stack depth so that we can
55-
* emit a warning prior to encountering a stack overflow.
56-
*
57-
* A 16-bit call depth would allow us to count to 65,535, which is way more
58-
* than necessary. An 8-bit depth would be inadequate (255).
59-
*/
60-
bool should_warn_call_depth;
61-
uint16_t call_depth;
62-
63-
// ext/curl's list entry resource type
64-
int le_curl;
65-
#endif
66-
6746
uint64_t trace_id;
6847
ddtrace_span_ids_t *span_ids_top;
6948
ddtrace_span_fci *open_spans_top;
@@ -92,13 +71,7 @@ ZEND_END_MODULE_GLOBALS(ddtrace)
9271
* defines these macros without the comma in the definition site, so that it
9372
* exists at the usage site.
9473
*/
95-
#if PHP_VERSION_ID < 70000
96-
#define DDTRACE_ARG_INFO_SIZE(arg_info) ((zend_uint)(sizeof(arg_info) / sizeof(struct _zend_arg_info) - 1))
97-
#elif PHP_VERSION_ID < 80100
9874
#define DDTRACE_ARG_INFO_SIZE(arg_info) ((uint32_t)(sizeof(arg_info) / sizeof(struct _zend_internal_arg_info) - 1))
99-
#else
100-
#error Check if ZEND_FENTRY has changed in PHP 8.1 and if we need to update the macros
101-
#endif
10275

10376
#define DDTRACE_FENTRY(zend_name, name, arg_info, flags) \
10477
{ #zend_name, name, arg_info, DDTRACE_ARG_INFO_SIZE(arg_info), flags }
@@ -111,19 +84,4 @@ ZEND_END_MODULE_GLOBALS(ddtrace)
11184
#define DDTRACE_FALIAS(name, alias, arg_info) DDTRACE_RAW_FENTRY(#name, zif_##alias, arg_info, 0)
11285
#define DDTRACE_FE_END ZEND_FE_END
11386

114-
/* Currently used on PHP 5. After a zend_execute_ex has called the previous hook
115-
* the execute_data cannot be trusted for some things, notably function_state.
116-
* So we use this struct to back up the data.
117-
*/
118-
struct ddtrace_execute_data {
119-
zval *This;
120-
zend_class_entry *scope;
121-
zend_function *fbc;
122-
const zend_op *opline;
123-
void **arguments;
124-
zval *retval;
125-
bool free_retval;
126-
};
127-
typedef struct ddtrace_execute_data ddtrace_execute_data;
128-
12987
#endif // DDTRACE_H

ext/php8/distributed_tracing.c

Lines changed: 0 additions & 7 deletions
This file was deleted.

ext/php8/distributed_tracing.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

ext/php8/engine_api.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ ZEND_RESULT_CODE ddtrace_call_method(zend_object *obj, zend_class_entry *ce, zen
7979
}
8080

8181
ZEND_RESULT_CODE ddtrace_call_function(zend_function **fn_proxy, const char *name, size_t name_len, zval *retval,
82-
int argc, zval argv[]) {
82+
int argc, ...) {
8383
zend_fcall_info fci = {
8484
.size = sizeof(zend_fcall_info),
8585
};
8686
zend_fcall_info_cache fcc = {
8787
.function_handler = (fn_proxy && *fn_proxy) ? *fn_proxy : NULL,
8888
};
8989

90+
va_list argv;
91+
va_start(argv, argc);
92+
zend_fcall_info_argv(&fci, (uint32_t)argc, &argv);
93+
va_end(argv);
94+
9095
if (!fcc.function_handler) {
9196
// This avoids allocating a zend_string if fn_proxy is used
9297
zval fname = ddtrace_zval_stringl(name, name_len);
@@ -111,12 +116,10 @@ ZEND_RESULT_CODE ddtrace_call_function(zend_function **fn_proxy, const char *nam
111116
// ZVAL_COPY_VALUE(&fci.function_name, fcc.function_handler->common.function_name);
112117

113118
fci.retval = retval;
114-
fci.params = argv;
115-
#if PHP_VERSION_ID < 80000
116-
fci.no_separation = 0; // allow for by-ref args
117-
#endif
118-
fci.param_count = argc;
119119
ZEND_RESULT_CODE result = zend_call_function(&fci, &fcc);
120+
121+
zend_fcall_info_args_clear(&fci, 1);
122+
120123
return result;
121124
}
122125

ext/php8/engine_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ inline zval ddtrace_zval_undef(void) {
5050
ZEND_RESULT_CODE ddtrace_call_method(zend_object *obj, zend_class_entry *ce, zend_function **fn_proxy,
5151
const char *fname, size_t fname_len, zval *retval, int argc, zval *argv);
5252
ZEND_RESULT_CODE ddtrace_call_function(zend_function **fn_proxy, const char *name, size_t name_len, zval *retval,
53-
int argc, zval argv[]);
53+
int argc, ...);
5454

5555
void ddtrace_write_property(zval *obj, const char *prop, size_t prop_len, zval *value);
5656
bool ddtrace_property_exists(zval *object, zval *property);

0 commit comments

Comments
 (0)