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 zend_try around closing and flushing spans #2507

Merged
merged 1 commit into from
Feb 7, 2024
Merged
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
23 changes: 16 additions & 7 deletions ext/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1274,10 +1274,19 @@ static void dd_shutdown_hooks_and_observer(void) {
void dd_force_shutdown_tracing(void) {
DDTRACE_G(in_shutdown) = true;

ddtrace_close_all_open_spans(true); // All remaining userland spans (and root span)
if (ddtrace_flush_tracer(false, true) == FAILURE) {
LOG(Warn, "Unable to flush the tracer");
}
zend_try {
ddtrace_close_all_open_spans(true); // All remaining userland spans (and root span)
} zend_catch {
LOG(Warn, "Failed to close remaining spans due to bailout");
} zend_end_try();

zend_try {
if (ddtrace_flush_tracer(false, true) == FAILURE) {
LOG(Warn, "Unable to flush the tracer");
}
} zend_catch {
LOG(Warn, "Unable to flush the tracer due to bailout");
} zend_end_try();

// we here need to disable the tracer, so that further hooks do not trigger
ddtrace_disable_tracing_in_current_request(); // implicitly calling dd_clean_globals
Expand All @@ -1288,7 +1297,7 @@ void dd_force_shutdown_tracing(void) {
DDTRACE_G(in_shutdown) = false;
}

static void dd_finalize_telemtry(void) {
static void dd_finalize_telemetry(void) {
if (DDTRACE_G(telemetry_queue_id)) {
ddtrace_telemetry_finalize();
DDTRACE_G(telemetry_queue_id) = 0;
Expand All @@ -1315,7 +1324,7 @@ static PHP_RSHUTDOWN_FUNCTION(ddtrace) {
DDTRACE_G(active_stack) = NULL;
}

dd_finalize_telemtry();
dd_finalize_telemetry();
if (DDTRACE_G(last_flushed_root_service_name)) {
zend_string_release(DDTRACE_G(last_flushed_root_service_name));
DDTRACE_G(last_flushed_root_service_name) = NULL;
Expand Down Expand Up @@ -1990,7 +1999,7 @@ PHP_FUNCTION(dd_trace_internal_fn) {
ddtrace_coms_test_msgpack_consumer();
RETVAL_TRUE;
} else if (FUNCTION_NAME_MATCHES("finalize_telemetry")) {
dd_finalize_telemtry();
dd_finalize_telemetry();
RETVAL_TRUE;
} else if (FUNCTION_NAME_MATCHES("dump_sidecar")) {
if (!ddtrace_sidecar) {
Expand Down
Loading