Skip to content

Commit b8b8a90

Browse files
committed
Merge branch 'master' of github.com:DataDog/dd-trace-php into glopes/http-endpoint
2 parents b3bdafd + bc34608 commit b8b8a90

File tree

24 files changed

+378
-207
lines changed

24 files changed

+378
-207
lines changed

CHANGELOG.md

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,25 @@
11
Changelog for older versions can be found in our [release page](https://github.com/DataDog/dd-trace-php/releases).
22

3-
## All products
4-
### Internal
5-
- Add injection metadata fields to telemetry forwarder #3359
6-
73
## Tracer
8-
### Added
9-
- Add http.route tag to SymfonyIntegration.php #2992
10-
- Add setting to avoid obfuscating mongodb queries #3390
11-
- Handle native HTTP requests #3366
12-
134
### Changed
14-
- Expose curl_multi_exec_get_request_spans() as non-internal #3389
15-
- Use resources_weak_* API for Curl as well #3386
16-
- Gracefully handle sidecar broken pipes #3370
17-
- Enable log injection by default #3355
5+
- Reduce integrations overhead #3380
6+
- Avoid unnecessary gc_collect_cycles if there's no open span #3428
7+
- Make use of fast_shutdown to avoid freeing overhead #3429
8+
- Optimize PDOIntegration::parseDsn() #3430
189

1910
### Fixed
20-
- Capture the stack for log probes #3367
21-
- Properly cache the telemetry cache #3387
22-
- Fix names of global git tags for debugger #3377
23-
- Fix SQLSRVIntegration resource handling #3379
24-
- Set DD_APPSEC_RASP_ENABLED default to true as on the tracer #3374
25-
- Fix top Code Origin frame for ExecIntegration and KafkaIntegration #3392
26-
27-
### Internal
28-
- Update baggage telemetry typo #3382
29-
- Switch to bookworm containers #3375
11+
- Fix #3135: Force flushing on shutdown of entry point processes #3398
12+
- Support curl_multi_exec root spans #3419
13+
- Fix a couple memory leaks #3420
3014

31-
## Application Security Management
15+
## Profiling
3216
### Added
33-
- Add fingerprint capabilities #3371
34-
- Implement jwt #3352
17+
- Add source code integration #3418
3518

3619
### Fixed
37-
- Fix musl appsec helper shutdown crash #3378
20+
- Fix missing line numbers #3417
21+
- Early init default connector to fix env var race #3432
3822

3923
### Internal
40-
- Fix submission of telemetry logs from appsec #3373
24+
- Refactor tag handling #3423
25+
- Permanently enable compilation of allocation, exception, and timeline features #3431

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.12.0
1+
1.13.0

ext/auto_flush.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
ZEND_EXTERN_MODULE_GLOBALS(ddtrace);
2121

22-
ZEND_RESULT_CODE ddtrace_flush_tracer(bool force_on_startup, bool collect_cycles) {
22+
ZEND_RESULT_CODE ddtrace_flush_tracer(bool force_on_startup, bool collect_cycles, bool fast_shutdown) {
2323
bool success = true;
2424

2525
ddog_TracesBytes *traces = ddog_get_traces();
2626
if (collect_cycles) {
27-
ddtrace_serialize_closed_spans_with_cycle(traces);
27+
ddtrace_serialize_closed_spans_with_cycle(traces, fast_shutdown);
2828
} else {
29-
ddtrace_serialize_closed_spans(traces);
29+
ddtrace_serialize_closed_spans(traces, fast_shutdown);
3030
}
3131

3232
// Prevent traces from requests not executing any PHP code:
@@ -113,7 +113,7 @@ ZEND_RESULT_CODE ddtrace_flush_tracer(bool force_on_startup, bool collect_cycles
113113
DDTRACE_PUBLIC void ddtrace_close_all_spans_and_flush()
114114
{
115115
ddtrace_close_all_open_spans(true);
116-
ddtrace_flush_tracer(true, true);
116+
ddtrace_flush_tracer(true, true, false);
117117
}
118118

119119
#define DEFAULT_UDS_PATH "/var/run/datadog/apm.socket"

ext/auto_flush.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <php.h>
66
#include <stdbool.h>
77

8-
ZEND_RESULT_CODE ddtrace_flush_tracer(bool force_on_startup, bool collect_cycles);
8+
ZEND_RESULT_CODE ddtrace_flush_tracer(bool force_on_startup, bool collect_cycles, bool fast_shutdown);
99

1010
// This function is exported and used by appsec
1111
DDTRACE_PUBLIC void ddtrace_close_all_spans_and_flush(void);

ext/configuration.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ bool ddtrace_config_minit(int module_number) {
243243
}
244244

245245
#ifndef _WIN32
246+
// PID 1 *obviously* needs to ensure the sidecar gets flushed. (As PID 1 terminating will just SIGKILL it.)
247+
// As to PPID 1, common scenarios where PHP is a direct child of PID 1:
248+
// - apache / fpm running in a container as PID 1 each
249+
// - PHP CLI processes running in a container as part of a bash script
250+
// - root processes of supervisord/systemd services - if these terminate, it's likely because the service or container shuts down.
251+
// -> If the sidecar is part of a cgroup, it will terminate the sidecar as well.
252+
if (getpid() == 1 || getppid() == 1) {
253+
config_entries[DDTRACE_CONFIG_DD_TRACE_FORCE_FLUSH_ON_SHUTDOWN].default_encoded_value = (zai_str) ZAI_STR_FROM_CSTR("true");
254+
config_entries[DDTRACE_CONFIG_DD_TRACE_FORCE_FLUSH_ON_SIGTERM].default_encoded_value = (zai_str) ZAI_STR_FROM_CSTR("true");
255+
config_entries[DDTRACE_CONFIG_DD_TRACE_FORCE_FLUSH_ON_SIGINT].default_encoded_value = (zai_str) ZAI_STR_FROM_CSTR("true");
256+
}
257+
246258
// Background sender does not send a Content-Length header, but sidecar does. Force-enable it thus, as the background sender does not work at all.
247259
if (getenv("AWS_LAMBDA_FUNCTION_NAME")) {
248260
config_entries[DDTRACE_CONFIG_DD_TRACE_SIDECAR_TRACE_SENDER].default_encoded_value = (zai_str) ZAI_STR_FROM_CSTR("true");

ext/configuration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ enum ddtrace_sampling_rules_format {
140140
CONFIG(STRING, DD_TRACE_MEMORY_LIMIT, "") \
141141
CONFIG(BOOL, DD_TRACE_REPORT_HOSTNAME, "false") \
142142
CONFIG(BOOL, DD_TRACE_FLUSH_COLLECT_CYCLES, "false") \
143+
CONFIG(BOOL, DD_TRACE_FORCE_FLUSH_ON_SHUTDOWN, "false") /* true if pid == 1 || ppid == 1 */ \
144+
CONFIG(BOOL, DD_TRACE_FORCE_FLUSH_ON_SIGTERM, "false") /* true if pid == 1 || ppid == 1 */ \
145+
CONFIG(BOOL, DD_TRACE_FORCE_FLUSH_ON_SIGINT, "false") /* true if pid == 1 || ppid == 1 */ \
143146
CONFIG(BOOL, DD_TRACE_KAFKA_DISTRIBUTED_TRACING, "true") \
144147
CONFIG(BOOL, DD_TRACE_LARAVEL_QUEUE_DISTRIBUTED_TRACING, "true") \
145148
CONFIG(BOOL, DD_TRACE_SYMFONY_MESSENGER_DISTRIBUTED_TRACING, "true") \

ext/ddtrace.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,10 @@ static PHP_MINIT_FUNCTION(ddtrace) {
15461546
ddtrace_minit_remote_config();
15471547
ddtrace_trace_source_minit();
15481548

1549+
#ifndef _WIN32
1550+
ddtrace_signals_minit();
1551+
#endif
1552+
15491553
return SUCCESS;
15501554
}
15511555

@@ -1580,8 +1584,11 @@ static PHP_MSHUTDOWN_FUNCTION(ddtrace) {
15801584
if (ddtrace_coms_flush_shutdown_writer_synchronous()) {
15811585
ddtrace_coms_curl_shutdown();
15821586
}
1583-
}
1587+
} else /* ! part of the if outside the ifdef */
15841588
#endif
1589+
if (get_global_DD_TRACE_FORCE_FLUSH_ON_SHUTDOWN() && ddtrace_sidecar) {
1590+
ddog_sidecar_flush_traces(&ddtrace_sidecar);
1591+
}
15851592

15861593
ddtrace_log_mshutdown();
15871594

@@ -1775,8 +1782,8 @@ static void dd_clean_globals(void) {
17751782
#endif
17761783
}
17771784

1778-
static void dd_shutdown_hooks_and_observer(void) {
1779-
zai_hook_clean();
1785+
static void dd_shutdown_hooks_and_observer(bool fast_shutdown) {
1786+
zai_hook_clean(fast_shutdown);
17801787

17811788
#if PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80200
17821789
#if PHP_VERSION_ID < 80100
@@ -1797,7 +1804,7 @@ static void dd_shutdown_hooks_and_observer(void) {
17971804
#endif
17981805
}
17991806

1800-
void dd_force_shutdown_tracing(void) {
1807+
void dd_force_shutdown_tracing(bool fast_shutdown) {
18011808
DDTRACE_G(in_shutdown) = true;
18021809

18031810
zend_try {
@@ -1807,7 +1814,7 @@ void dd_force_shutdown_tracing(void) {
18071814
} zend_end_try();
18081815

18091816
zend_try {
1810-
if (ddtrace_flush_tracer(false, true) == FAILURE) {
1817+
if (ddtrace_flush_tracer(false, true, fast_shutdown) == FAILURE) {
18111818
LOG(WARN, "Unable to flush the tracer");
18121819
}
18131820
} zend_catch {
@@ -1818,7 +1825,7 @@ void dd_force_shutdown_tracing(void) {
18181825
ddtrace_disable_tracing_in_current_request(); // implicitly calling dd_clean_globals
18191826

18201827
// The hooks shall not be reset, just disabled at runtime.
1821-
dd_shutdown_hooks_and_observer();
1828+
dd_shutdown_hooks_and_observer(fast_shutdown);
18221829

18231830
DDTRACE_G(in_shutdown) = false;
18241831
}
@@ -1832,16 +1839,31 @@ static void dd_finalize_sidecar_lifecycle(bool clear_id) {
18321839
static PHP_RSHUTDOWN_FUNCTION(ddtrace) {
18331840
UNUSED(module_number, type);
18341841

1842+
// We deliberately select to not free some data structures, as to avoid the overhead of freeing them.
1843+
// Just proper destruction can have significant and easily measurable overhead on applications.
1844+
// Prior to PHP 7.2 fast shutdown was an opcache only feature
1845+
#if ZEND_DEBUG || PHP_VERSION_ID < 70200
1846+
bool fast_shutdown = 0;
1847+
#elif defined(__SANITIZE_ADDRESS__)
1848+
char *force_fast_shutdown = getenv("ZEND_ASAN_FORCE_FAST_SHUTDOWN");
1849+
bool fast_shutdown = (
1850+
is_zend_mm()
1851+
|| (force_fast_shutdown && ZEND_ATOL(force_fast_shutdown))
1852+
) && !EG(full_tables_cleanup);
1853+
#else
1854+
bool fast_shutdown = is_zend_mm() && !EG(full_tables_cleanup);
1855+
#endif
1856+
18351857
zend_hash_destroy(&DDTRACE_G(traced_spans));
18361858

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

18411863
if (get_DD_TRACE_ENABLED()) {
1842-
dd_force_shutdown_tracing();
1864+
dd_force_shutdown_tracing(fast_shutdown);
18431865
} else if (!ddtrace_disable) {
1844-
dd_shutdown_hooks_and_observer();
1866+
dd_shutdown_hooks_and_observer(fast_shutdown);
18451867
}
18461868

18471869
if (DDTRACE_G(remote_config_state)) {
@@ -1851,7 +1873,9 @@ static PHP_RSHUTDOWN_FUNCTION(ddtrace) {
18511873
if (!ddtrace_disable) {
18521874
ddtrace_autoload_rshutdown();
18531875

1854-
OBJ_RELEASE(&DDTRACE_G(active_stack)->std);
1876+
if (!fast_shutdown) {
1877+
OBJ_RELEASE(&DDTRACE_G(active_stack)->std);
1878+
}
18551879
DDTRACE_G(active_stack) = NULL;
18561880
}
18571881

@@ -2344,7 +2368,7 @@ PHP_FUNCTION(dd_trace_serialize_closed_spans) {
23442368
ddtrace_mark_all_span_stacks_flushable();
23452369

23462370
ddog_TracesBytes *traces = ddog_get_traces();
2347-
ddtrace_serialize_closed_spans_with_cycle(traces);
2371+
ddtrace_serialize_closed_spans_with_cycle(traces, false);
23482372

23492373
zval traces_zv = dd_serialize_rust_traces_to_zval(traces);
23502374

@@ -3221,7 +3245,7 @@ PHP_FUNCTION(DDTrace_flush) {
32213245
if (get_DD_AUTOFINISH_SPANS()) {
32223246
ddtrace_close_userland_spans_until(NULL);
32233247
}
3224-
if (ddtrace_flush_tracer(false, get_DD_TRACE_FLUSH_COLLECT_CYCLES()) == FAILURE) {
3248+
if (ddtrace_flush_tracer(false, get_DD_TRACE_FLUSH_COLLECT_CYCLES(), false) == FAILURE) {
32253249
LOG_LINE(WARN, "Unable to flush the tracer");
32263250
}
32273251
RETURN_NULL();

ext/ddtrace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ bool ddtrace_alter_default_propagation_style(zval *old_value, zval *new_value, z
7171
bool ddtrace_alter_dd_service(zval *old_value, zval *new_value, zend_string *new_str);
7272
bool ddtrace_alter_dd_env(zval *old_value, zval *new_value, zend_string *new_str);
7373
bool ddtrace_alter_dd_version(zval *old_value, zval *new_value, zend_string *new_str);
74-
void dd_force_shutdown_tracing(void);
74+
void dd_force_shutdown_tracing(bool fast_shutdown);
7575
void dd_internal_handle_fork(void);
7676
#ifdef CXA_THREAD_ATEXIT_WRAPPER
7777
void dd_run_rust_thread_destructors(void *unused);

ext/handlers_exception.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ void dd_exception_handler_freed(zend_object *object) {
380380
// Here we are at the very last chance before objects are unconditionally freed.
381381
// Let's force-disable the tracing in case it wasn't yet
382382
// Typically RSHUTDOWN would handle that, but since 8.1.0 opcache will free our objects before module_shutdown during preloading
383-
dd_force_shutdown_tracing();
383+
dd_force_shutdown_tracing(false);
384384
}
385385
}
386386
#endif

0 commit comments

Comments
 (0)