From 6522a1f105cd61d8c0ffbf4e32336426db05a1ea Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 12 Aug 2026 12:17:05 +0200 Subject: [PATCH 1/2] feat!: remove enable_logs/metrics --- CHANGELOG.md | 8 +- examples/example.c | 90 ++++++++----------- include/sentry.h | 26 +----- ndk/lib/api/sentry-native-ndk.api | 2 - .../main/java/io/sentry/ndk/NdkOptions.java | 9 -- ndk/lib/src/main/jni/sentry.c | 7 -- src/sentry_logs.c | 25 +++--- src/sentry_metrics.c | 76 ++++++++-------- src/sentry_options.c | 26 ------ src/sentry_options.h | 2 - src/sentry_telemetry.c | 12 +-- tests/test_integration_client_reports.py | 1 - tests/test_integration_metrics.py | 17 ---- tests/unit/test_logger.c | 9 -- tests/unit/test_logs.c | 41 +-------- tests/unit/test_metrics.c | 24 +---- tests/unit/tests.inc | 5 +- 17 files changed, 110 insertions(+), 270 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a275f801a5..16e6d970cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,15 @@ ## Unreleased +**Breaking / Important behavior changes**: + +- Remove `sentry_options_get/set_enable_logs` and `sentry_options_get/set_enable_metrics`. ([#1980](https://github.com/getsentry/sentry-native/pull/1980)) + > Structured logs and metrics have been enabled by default since `0.13`. + > + > We recognize that this change may inconvenience applications that rely on the opt-out. Use `sentry_options_set_before_send_log` or `sentry_options_set_before_send_metric` to filter logs or metrics. We made this tradeoff deliberately because consistent behavior across SDK integrations will help most users successfully adopt these features. + **Features**: -- Forward `enable_logs` option through `NdkOptions` so the Android SDK can enable native structured logging. ([#1971](https://github.com/getsentry/sentry-native/pull/1971)) - Report enabled Qt and WER integrations in event SDK metadata (`sdk.integrations`) alongside the configured crash backend. ([#1969](https://github.com/ getsentry/sentry-native/pull/1969)) diff --git a/examples/example.c b/examples/example.c index 005a8f36dd..e36b9c8587 100644 --- a/examples/example.c +++ b/examples/example.c @@ -857,10 +857,6 @@ main(int argc, char **argv) sentry_options_set_logger_enabled_when_crashed(options, 1); } - if (has_arg(argc, argv, "disable-logs")) { - sentry_options_set_enable_logs(options, false); - } - if (has_arg(argc, argv, "crash-reporter")) { #ifdef SENTRY_PLATFORM_WINDOWS sentry_options_set_external_crash_reporter_pathw( @@ -895,10 +891,6 @@ main(int argc, char **argv) sentry_options_set_http_retry(options, false); } - if (has_arg(argc, argv, "disable-metrics")) { - sentry_options_set_enable_metrics(options, false); - } - if (has_arg(argc, argv, "before-send-metric")) { sentry_options_set_before_send_metric( options, before_send_metric_callback, NULL); @@ -1062,54 +1054,48 @@ main(int argc, char **argv) } } - if (sentry_options_get_enable_logs(options)) { - if (has_arg(argc, argv, "capture-log")) { - sentry_log_debug("I'm a log message!"); - } - if (has_arg(argc, argv, "logs-timer")) { - for (int i = 0; i < 10; i++) { - sentry_log_info("Informational log nr.%d", i); - } - // sleep >5s to trigger logs timer - sleep_s(6); - // we should see two envelopes make its way to Sentry - sentry_log_debug("post-sleep log"); - } - if (has_arg(argc, argv, "logs-threads")) { - run_threads(log_thread_func); + if (has_arg(argc, argv, "capture-log")) { + sentry_log_debug("I'm a log message!"); + } + if (has_arg(argc, argv, "logs-timer")) { + for (int i = 0; i < 10; i++) { + sentry_log_info("Informational log nr.%d", i); } + // sleep >5s to trigger logs timer + sleep_s(6); + // we should see two envelopes make its way to Sentry + sentry_log_debug("post-sleep log"); + } + if (has_arg(argc, argv, "logs-threads")) { + run_threads(log_thread_func); } - if (sentry_options_get_enable_metrics(options)) { - if (has_arg(argc, argv, "capture-metric")) { - sentry_metrics_count("test.counter", 1, sentry_value_new_null()); - } - if (has_arg(argc, argv, "capture-metric-all-types")) { - sentry_metrics_count("test.counter", 1, sentry_value_new_null()); - sentry_metrics_gauge("test.gauge", 42.5, SENTRY_UNIT_PERCENT, - sentry_value_new_null()); - sentry_metrics_distribution("test.distribution", 123.456, - SENTRY_UNIT_MILLISECOND, sentry_value_new_null()); - } - if (has_arg(argc, argv, "metric-with-attributes")) { - sentry_value_t attributes = sentry_value_new_object(); - sentry_value_t attr = sentry_value_new_attribute( - sentry_value_new_string("my_value"), NULL); - sentry_value_set_by_key(attributes, "my.custom.attribute", attr); - sentry_metrics_count("test.counter.with.attributes", 1, attributes); - } - if (has_arg(argc, argv, "metrics-timer")) { - for (int i = 0; i < 10; i++) { - sentry_metrics_count( - "batch.counter", 1, sentry_value_new_null()); - } - sleep_s(6); - sentry_metrics_count( - "post.sleep.counter", 1, sentry_value_new_null()); - } - if (has_arg(argc, argv, "metrics-threads")) { - run_threads(metric_thread_func); + if (has_arg(argc, argv, "capture-metric")) { + sentry_metrics_count("test.counter", 1, sentry_value_new_null()); + } + if (has_arg(argc, argv, "capture-metric-all-types")) { + sentry_metrics_count("test.counter", 1, sentry_value_new_null()); + sentry_metrics_gauge( + "test.gauge", 42.5, SENTRY_UNIT_PERCENT, sentry_value_new_null()); + sentry_metrics_distribution("test.distribution", 123.456, + SENTRY_UNIT_MILLISECOND, sentry_value_new_null()); + } + if (has_arg(argc, argv, "metric-with-attributes")) { + sentry_value_t attributes = sentry_value_new_object(); + sentry_value_t attr = sentry_value_new_attribute( + sentry_value_new_string("my_value"), NULL); + sentry_value_set_by_key(attributes, "my.custom.attribute", attr); + sentry_metrics_count("test.counter.with.attributes", 1, attributes); + } + if (has_arg(argc, argv, "metrics-timer")) { + for (int i = 0; i < 10; i++) { + sentry_metrics_count("batch.counter", 1, sentry_value_new_null()); } + sleep_s(6); + sentry_metrics_count("post.sleep.counter", 1, sentry_value_new_null()); + } + if (has_arg(argc, argv, "metrics-threads")) { + run_threads(metric_thread_func); } if (!has_arg(argc, argv, "no-setup")) { diff --git a/include/sentry.h b/include/sentry.h index d4913ded7c..9a715f1e78 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -2588,17 +2588,6 @@ SENTRY_EXPERIMENTAL_API void sentry_options_set_strict_trace_continuation( SENTRY_EXPERIMENTAL_API int sentry_options_get_strict_trace_continuation( const sentry_options_t *opts); -/** - * Enables or disables the structured logging feature. - * When disabled, all calls to `sentry_log_X()` are no-ops. - * - * Enabled by default. - */ -SENTRY_EXPERIMENTAL_API void sentry_options_set_enable_logs( - sentry_options_t *opts, int enable_logs); -SENTRY_EXPERIMENTAL_API int sentry_options_get_enable_logs( - const sentry_options_t *opts); - /** * Enables or disables HTTP retry with exponential backoff for network failures. * @@ -2670,7 +2659,7 @@ SENTRY_API int sentry_options_get_send_client_reports( * - Success means a log was enqueued * - Discard means the `before_send_log` function discarded the log * - Failed means the log wasn't enqueued. This happens if the buffers are full - * - Disabled means the option `enable_logs` was false. + * - Disabled means the SDK was not initialized */ typedef enum { SENTRY_LOG_RETURN_SUCCESS = 0, @@ -2772,17 +2761,6 @@ typedef sentry_value_t (*sentry_before_send_log_function_t)( SENTRY_EXPERIMENTAL_API void sentry_options_set_before_send_log( sentry_options_t *opts, sentry_before_send_log_function_t func, void *data); -/** - * Enables or disables the metrics feature. - * When disabled, all calls to `sentry_metrics_*()` are no-ops. - * - * Enabled by default. - */ -SENTRY_EXPERIMENTAL_API void sentry_options_set_enable_metrics( - sentry_options_t *opts, int enable_metrics); -SENTRY_EXPERIMENTAL_API int sentry_options_get_enable_metrics( - const sentry_options_t *opts); - /** * Enables or disables in-process app-hang detection. When enabled, a * background watchdog thread monitors heartbeats from the watched thread. If @@ -2865,7 +2843,7 @@ SENTRY_EXPERIMENTAL_API void sentry_options_set_before_send_metric( * - Success means the metric was enqueued * - Discard means the `before_send_metric` callback discarded the metric * - Failed means the metric wasn't enqueued (buffers are full) - * - Disabled means metrics are disabled + * - Disabled means the SDK was not initialized */ typedef enum { SENTRY_METRICS_RESULT_SUCCESS = 0, diff --git a/ndk/lib/api/sentry-native-ndk.api b/ndk/lib/api/sentry-native-ndk.api index 79d8238114..35780f414e 100644 --- a/ndk/lib/api/sentry-native-ndk.api +++ b/ndk/lib/api/sentry-native-ndk.api @@ -101,10 +101,8 @@ public final class io/sentry/ndk/NdkOptions { public fun getTracesSampleRate ()F public fun isDebug ()Z public fun isEnableAppHangTracking ()Z - public fun isEnableLogs ()Z public fun setAppHangTimeoutMillis (J)V public fun setEnableAppHangTracking (Z)V - public fun setEnableLogs (Z)V public fun setNdkHandlerStrategy (Lio/sentry/ndk/NdkHandlerStrategy;)V public fun setTracesSampleRate (F)V } diff --git a/ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java b/ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java index 41122e6acb..d8896367ea 100644 --- a/ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java +++ b/ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java @@ -17,7 +17,6 @@ public final class NdkOptions { private float tracesSampleRate = 0; private boolean enableAppHangTracking = false; private long appHangTimeoutMillis = 5000; - private boolean enableLogs = false; public NdkOptions( @NotNull String dsn, @@ -107,12 +106,4 @@ public void setAppHangTimeoutMillis(final long appHangTimeoutMillis) { public long getAppHangTimeoutMillis() { return appHangTimeoutMillis; } - - public void setEnableLogs(final boolean enableLogs) { - this.enableLogs = enableLogs; - } - - public boolean isEnableLogs() { - return enableLogs; - } } diff --git a/ndk/lib/src/main/jni/sentry.c b/ndk/lib/src/main/jni/sentry.c index 36516b9c8e..8235a77824 100644 --- a/ndk/lib/src/main/jni/sentry.c +++ b/ndk/lib/src/main/jni/sentry.c @@ -417,9 +417,6 @@ Java_io_sentry_ndk_SentryNdk_initSentryNative( jmethodID app_hang_timeout_mid = (*env)->GetMethodID( env, options_cls, "getAppHangTimeoutMillis", "()J"); - jmethodID enable_logs_mid - = (*env)->GetMethodID(env, options_cls, "isEnableLogs", "()Z"); - (*env)->DeleteLocalRef(env, options_cls); char *outbox_path = NULL; @@ -525,10 +522,6 @@ Java_io_sentry_ndk_SentryNdk_initSentryNative( } sentry_options_set_app_hang_timeout(options, (uint64_t)app_hang_timeout); - jboolean enable_logs = (jboolean)(*env)->CallBooleanMethod( - env, sentry_ndk_options, enable_logs_mid); - sentry_options_set_enable_logs(options, enable_logs); - int rv = sentry_init(options); return (jint)rv; diff --git a/src/sentry_logs.c b/src/sentry_logs.c index 4573abf7b4..e35aa59f5a 100644 --- a/src/sentry_logs.c +++ b/src/sentry_logs.c @@ -14,6 +14,17 @@ static sentry_batcher_ref_t g_batcher = SENTRY_BATCHER_REF_INIT; +static bool +sdk_is_initialized(void) +{ + bool initialized = false; + SENTRY_WITH_OPTIONS (options) { + (void)options; + initialized = true; + } + return initialized; +} + typedef enum { PRINTF_LENGTH_NONE, PRINTF_LENGTH_CHAR, @@ -517,12 +528,7 @@ send_log(sentry_level_t level, sentry_value_t log) log_return_value_t sentry__logs_log(sentry_level_t level, const char *message, va_list args) { - bool enable_logs = false; - SENTRY_WITH_OPTIONS (options) { - if (options->enable_logs) - enable_logs = true; - } - if (!enable_logs) { + if (!sdk_is_initialized()) { return SENTRY_LOG_RETURN_DISABLED; } return send_log(level, construct_log(level, message, args)); @@ -605,12 +611,7 @@ log_return_value_t sentry_scope_capture_log(sentry_scope_t *scope, sentry_level_t level, const char *body, sentry_value_t custom_attributes) { - bool enable_logs = false; - SENTRY_WITH_OPTIONS (options) { - if (options->enable_logs) - enable_logs = true; - } - if (!enable_logs) { + if (!sdk_is_initialized()) { sentry_value_decref(custom_attributes); sentry__scope_free_one_shot(scope); return SENTRY_LOG_RETURN_DISABLED; diff --git a/src/sentry_metrics.c b/src/sentry_metrics.c index 0f6f05f0ce..946c7ed817 100644 --- a/src/sentry_metrics.c +++ b/src/sentry_metrics.c @@ -10,6 +10,17 @@ static sentry_batcher_ref_t g_batcher = SENTRY_BATCHER_REF_INIT; +static bool +sdk_is_initialized(void) +{ + bool initialized = false; + SENTRY_WITH_OPTIONS (options) { + (void)options; + initialized = true; + } + return initialized; +} + static const char * metric_type_string(sentry_metric_type_t type) { @@ -65,46 +76,41 @@ sentry_scope_capture_metric(sentry_scope_t *scope, sentry_metric_type_t type, const char *name, sentry_value_t value, const char *unit, sentry_value_t attributes) { - bool enable_metrics = false; - SENTRY_WITH_OPTIONS (options) { - if (options->enable_metrics) - enable_metrics = true; - } - if (enable_metrics) { - bool discarded = false; - sentry_value_t metric - = construct_metric(scope, type, name, value, unit, attributes); + if (!sdk_is_initialized()) { + sentry_value_decref(value); + sentry_value_decref(attributes); sentry__scope_free_one_shot(scope); - SENTRY_WITH_OPTIONS (options) { - if (options->before_send_metric_func) { - metric = options->before_send_metric_func( - metric, options->before_send_metric_data); - if (sentry_value_is_null(metric)) { - SENTRY_DEBUG("metric was discarded by the " - "`before_send_metric` hook"); - sentry__client_report_discard( - SENTRY_DISCARD_REASON_BEFORE_SEND, - SENTRY_DATA_CATEGORY_TRACE_METRIC, 1); - discarded = true; - } + return SENTRY_METRICS_RESULT_DISABLED; + } + + bool discarded = false; + sentry_value_t metric + = construct_metric(scope, type, name, value, unit, attributes); + sentry__scope_free_one_shot(scope); + SENTRY_WITH_OPTIONS (options) { + if (options->before_send_metric_func) { + metric = options->before_send_metric_func( + metric, options->before_send_metric_data); + if (sentry_value_is_null(metric)) { + SENTRY_DEBUG("metric was discarded by the " + "`before_send_metric` hook"); + sentry__client_report_discard(SENTRY_DISCARD_REASON_BEFORE_SEND, + SENTRY_DATA_CATEGORY_TRACE_METRIC, 1); + discarded = true; } } - if (discarded) { - return SENTRY_METRICS_RESULT_DISCARD; - } - sentry_batcher_t *batcher = sentry__batcher_acquire(&g_batcher); - if (!batcher || !sentry__batcher_enqueue(batcher, metric)) { - sentry__batcher_release(batcher); - sentry_value_decref(metric); - return SENTRY_METRICS_RESULT_FAILED; - } + } + if (discarded) { + return SENTRY_METRICS_RESULT_DISCARD; + } + sentry_batcher_t *batcher = sentry__batcher_acquire(&g_batcher); + if (!batcher || !sentry__batcher_enqueue(batcher, metric)) { sentry__batcher_release(batcher); - return SENTRY_METRICS_RESULT_SUCCESS; + sentry_value_decref(metric); + return SENTRY_METRICS_RESULT_FAILED; } - sentry_value_decref(value); - sentry_value_decref(attributes); - sentry__scope_free_one_shot(scope); - return SENTRY_METRICS_RESULT_DISABLED; + sentry__batcher_release(batcher); + return SENTRY_METRICS_RESULT_SUCCESS; } sentry_metrics_result_t diff --git a/src/sentry_options.c b/src/sentry_options.c index 26cd3e9d1a..bca7668d15 100644 --- a/src/sentry_options.c +++ b/src/sentry_options.c @@ -90,8 +90,6 @@ sentry_options_new(void) opts->propagate_traceparent = false; opts->strict_trace_continuation = false; opts->crashpad_limit_stack_capture_to_sp = false; - opts->enable_metrics = true; - opts->enable_logs = true; opts->cache_keep = SENTRY_CACHE_KEEP_NONE; opts->cache_max_age = 0; opts->cache_max_size = 0; @@ -1005,18 +1003,6 @@ sentry__options_add_integration( opts->num_integrations = new_count; } -void -sentry_options_set_enable_logs(sentry_options_t *opts, int enable_logs) -{ - opts->enable_logs = !!enable_logs; -} - -int -sentry_options_get_enable_logs(const sentry_options_t *opts) -{ - return opts->enable_logs; -} - void sentry_options_set_logs_with_attributes( sentry_options_t *opts, int logs_with_attributes) @@ -1030,18 +1016,6 @@ sentry_options_get_logs_with_attributes(const sentry_options_t *opts) return opts->logs_with_attributes; } -void -sentry_options_set_enable_metrics(sentry_options_t *opts, int enable_metrics) -{ - opts->enable_metrics = !!enable_metrics; -} - -int -sentry_options_get_enable_metrics(const sentry_options_t *opts) -{ - return opts->enable_metrics; -} - void sentry_options_set_enable_app_hang_tracking(sentry_options_t *opts, int enable) { diff --git a/src/sentry_options.h b/src/sentry_options.h index 75d52220ad..bfe8733c6c 100644 --- a/src/sentry_options.h +++ b/src/sentry_options.h @@ -81,11 +81,9 @@ struct sentry_options_s { void *traces_sampler_data; char *org_id; size_t max_spans; - bool enable_logs; // takes the first varg as a `sentry_value_t` object containing attributes // if no custom attributes are to be passed, use `sentry_value_new_object()` bool logs_with_attributes; - bool enable_metrics; sentry_before_send_metric_function_t before_send_metric_func; void *before_send_metric_data; bool enable_app_hang_tracking; diff --git a/src/sentry_telemetry.c b/src/sentry_telemetry.c index 8e0268fac0..fe3d49b499 100644 --- a/src/sentry_telemetry.c +++ b/src/sentry_telemetry.c @@ -7,21 +7,13 @@ void sentry__telemetry_startup(const sentry_options_t *options) { - if (options->enable_logs) { - sentry__logs_startup(options); - } - if (options->enable_metrics) { - sentry__metrics_startup(options); - } + sentry__logs_startup(options); + sentry__metrics_startup(options); } void sentry__telemetry_shutdown(const sentry_options_t *options) { - if (!options->enable_logs && !options->enable_metrics) { - return; - } - SENTRY_DEBUG("shutting down telemetry"); sentry__logs_shutdown(options->shutdown_timeout); sentry__metrics_shutdown(options->shutdown_timeout); diff --git a/tests/test_integration_client_reports.py b/tests/test_integration_client_reports.py index 5c741a8776..f9e7bea8c3 100644 --- a/tests/test_integration_client_reports.py +++ b/tests/test_integration_client_reports.py @@ -212,7 +212,6 @@ def test_client_report_before_send_metric(cmake, httpserver): "sentry_example", [ "log", - "enable-metrics", "discarding-before-send-metric", "capture-metric", "capture-event", diff --git a/tests/test_integration_metrics.py b/tests/test_integration_metrics.py index 91d789163f..185f99db03 100644 --- a/tests/test_integration_metrics.py +++ b/tests/test_integration_metrics.py @@ -222,23 +222,6 @@ def test_before_send_metric_discard(cmake, httpserver): assert len(httpserver.log) == 0 -def test_metrics_disabled(cmake, httpserver): - tmp_path = cmake(["sentry_example"], {"SENTRY_BACKEND": "none"}) - - httpserver.expect_request("/api/123456/envelope/").respond_with_data("OK") - env = dict(os.environ, SENTRY_DSN=make_dsn(httpserver)) - - run( - tmp_path, - "sentry_example", - ["log", "disable-metrics", "capture-metric"], - env=env, - ) - - # No metrics should be sent when feature is disabled - assert len(httpserver.log) == 0 - - def test_metrics_event(cmake, httpserver): tmp_path = cmake(["sentry_example"], {"SENTRY_BACKEND": "none"}) diff --git a/tests/unit/test_logger.c b/tests/unit/test_logger.c index 44360a1268..7efe7aa7a0 100644 --- a/tests/unit/test_logger.c +++ b/tests/unit/test_logger.c @@ -39,9 +39,6 @@ SENTRY_TEST(custom_logger) SENTRY_TEST_OPTIONS_NEW(options); sentry_options_set_debug(options, true); sentry_options_set_logger(options, test_logger, &data); - sentry_options_set_enable_metrics(options, false); - sentry_options_set_enable_logs(options, false); - sentry_init(options); data.assert_now = true; @@ -68,9 +65,6 @@ SENTRY_TEST(logger_enable_disable_functionality) SENTRY_TEST_OPTIONS_NEW(options); sentry_options_set_debug(options, true); sentry_options_set_logger(options, test_logger, &data); - sentry_options_set_enable_metrics(options, false); - sentry_options_set_enable_logs(options, false); - sentry_init(options); // Test logging is enabled by default @@ -139,9 +133,6 @@ SENTRY_TEST(logger_level) sentry_options_set_debug(options, true); sentry_options_set_logger_level(options, test_cases[i].level); sentry_options_set_logger(options, test_log_level, &data); - sentry_options_set_enable_metrics(options, false); - sentry_options_set_enable_logs(options, false); - sentry_init(options); data.assert_now = true; diff --git a/tests/unit/test_logs.c b/tests/unit/test_logs.c index 1e7cfcb945..20d3db4b6f 100644 --- a/tests/unit/test_logs.c +++ b/tests/unit/test_logs.c @@ -53,7 +53,7 @@ SENTRY_TEST(basic_logging_functionality) sentry_init(options); sentry__logs_wait_for_thread_startup(); - // These should not crash and should respect the enable_logs option + // These should not crash. TEST_CHECK_INT_EQUAL(sentry_log_trace("Trace message"), 0); TEST_CHECK_INT_EQUAL(sentry_log_debug("Debug message"), 0); TEST_CHECK_INT_EQUAL(sentry_log_info("Info message"), 0); @@ -75,31 +75,6 @@ SENTRY_TEST(basic_logging_functionality) TEST_CHECK_INT_EQUAL(validation_data.called_count, 2); } -SENTRY_TEST(logs_disabled) -{ - transport_validation_data_t validation_data = { 0, false }; - - SENTRY_TEST_OPTIONS_NEW(options); - sentry_options_set_dsn(options, "https://foo@sentry.invalid/42"); - sentry_options_set_enable_logs(options, false); - - sentry_transport_t *transport - = sentry_transport_new(validate_logs_envelope); - sentry_transport_set_state(transport, &validation_data); - sentry_options_set_transport(options, transport); - - sentry_init(options); - - // Should return DISABLED since logs were explicitly disabled - TEST_CHECK_INT_EQUAL(sentry_log_info("This should not be sent"), 3); - - sentry_close(); - - // Transport should not be called since logs were explicitly disabled - TEST_CHECK(!validation_data.has_validation_error); - TEST_CHECK_INT_EQUAL(validation_data.called_count, 0); -} - SENTRY_TEST(formatted_log_messages) { transport_validation_data_t validation_data = { 0, false }; @@ -338,7 +313,7 @@ SENTRY_TEST(logs_force_flush) sentry_init(options); sentry__logs_wait_for_thread_startup(); - // These should not crash and should respect the enable_logs option + // These should not crash. TEST_CHECK_INT_EQUAL(sentry_log_trace("Trace message"), 0); sentry_flush(5000); TEST_CHECK_INT_EQUAL(sentry_log_debug("Debug message"), 0); @@ -556,22 +531,14 @@ SENTRY_TEST(logs_span_trace_attributes) sentry_close(); } -SENTRY_TEST(logs_plain_string_disabled) +SENTRY_TEST(logs_uninitialized) { - SENTRY_TEST_OPTIONS_NEW(options); - sentry_options_set_dsn(options, "https://foo@sentry.invalid/42"); - sentry_options_set_enable_logs(options, false); - - sentry_init(options); - - // Should not leak the attributes value sentry_value_t attrs = sentry_value_new_object(); sentry_value_set_by_key(attrs, "key", sentry_value_new_attribute(sentry_value_new_string("val"), NULL)); + TEST_CHECK_INT_EQUAL(sentry_log(SENTRY_LEVEL_INFO, "test", attrs), SENTRY_LOG_RETURN_DISABLED); - - sentry_close(); } SENTRY_TEST(logs_global_attribute_no_field_leak) diff --git a/tests/unit/test_metrics.c b/tests/unit/test_metrics.c index 7115d07348..a7a32225db 100644 --- a/tests/unit/test_metrics.c +++ b/tests/unit/test_metrics.c @@ -262,22 +262,8 @@ SENTRY_TEST(metrics_before_send_modify) TEST_CHECK_INT_EQUAL(validation_data.called_count, 1); } -SENTRY_TEST(metrics_disabled) +SENTRY_TEST(metrics_uninitialized) { - transport_validation_data_t validation_data = { 0, false }; - - SENTRY_TEST_OPTIONS_NEW(options); - sentry_options_set_dsn(options, "https://foo@sentry.invalid/42"); - sentry_options_set_enable_metrics(options, false); - - sentry_transport_t *transport - = sentry_transport_new(validate_metrics_envelope); - sentry_transport_set_state(transport, &validation_data); - sentry_options_set_transport(options, transport); - - sentry_init(options); - - // These should return DISABLED since metrics were explicitly disabled TEST_CHECK_INT_EQUAL( sentry_metrics_count("test.counter", 1, sentry_value_new_null()), SENTRY_METRICS_RESULT_DISABLED); @@ -287,12 +273,6 @@ SENTRY_TEST(metrics_disabled) TEST_CHECK_INT_EQUAL(sentry_metrics_distribution("test.distribution", 123.0, NULL, sentry_value_new_null()), SENTRY_METRICS_RESULT_DISABLED); - - sentry_close(); - - // Transport should not be called since metrics were explicitly disabled - TEST_CHECK(!validation_data.has_validation_error); - TEST_CHECK_INT_EQUAL(validation_data.called_count, 0); } SENTRY_TEST(metrics_force_flush) @@ -591,8 +571,6 @@ SENTRY_TEST(metrics_reinit) // This will deadlock if sentry__batcher_flush holds g_options_lock. SENTRY_TEST_OPTIONS_NEW(options2); sentry_options_set_dsn(options2, "https://foo@sentry.invalid/42"); - sentry_options_set_enable_metrics(options2, true); - sentry_init(options2); sentry_close(); } diff --git a/tests/unit/tests.inc b/tests/unit/tests.inc index dbc00cae5c..259c011558 100644 --- a/tests/unit/tests.inc +++ b/tests/unit/tests.inc @@ -193,7 +193,6 @@ XX(logger_enable_disable_functionality) XX(logger_level) XX(logs_custom_attributes_not_modified) XX(logs_custom_attributes_with_format_strings) -XX(logs_disabled) XX(logs_force_flush) XX(logs_global_attribute_no_field_leak) XX(logs_param_conversion) @@ -201,10 +200,10 @@ XX(logs_param_sign) XX(logs_param_types) XX(logs_param_width) XX(logs_plain_string) -XX(logs_plain_string_disabled) XX(logs_reinit) XX(logs_reinit_stress) XX(logs_span_trace_attributes) +XX(logs_uninitialized) XX(m128a_size) XX(message_with_null_text_is_valid) XX(metrics_batch) @@ -212,13 +211,13 @@ XX(metrics_before_send_discard) XX(metrics_before_send_modify) XX(metrics_count) XX(metrics_default_attributes) -XX(metrics_disabled) XX(metrics_distribution) XX(metrics_force_flush) XX(metrics_gauge) XX(metrics_global_attribute_no_field_leak) XX(metrics_reinit) XX(metrics_reinit_stress) +XX(metrics_uninitialized) XX(metrics_with_attributes) XX(minidump_context_flags) XX(minidump_context_sizes) From 4eabf1e2ab816ddeca1ce126f4dc820ca8588298 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 12 Aug 2026 12:55:17 +0200 Subject: [PATCH 2/2] wait --- tests/unit/test_logger.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/test_logger.c b/tests/unit/test_logger.c index 7efe7aa7a0..c372a341eb 100644 --- a/tests/unit/test_logger.c +++ b/tests/unit/test_logger.c @@ -1,5 +1,7 @@ #include "sentry_core.h" #include "sentry_logger.h" +#include "sentry_logs.h" +#include "sentry_metrics.h" #include "sentry_sync.h" #include "sentry_testsupport.h" @@ -14,6 +16,13 @@ typedef struct { // To blacklist a test, add to the respective list of `test_unit_transport` // in the `tests/test_unit.py` unit-test runner. +static void +wait_for_telemetry_threads(void) +{ + sentry__logs_wait_for_thread_startup(); + sentry__metrics_wait_for_thread_startup(); +} + static void test_logger( sentry_level_t level, const char *message, va_list args, void *_data) @@ -40,6 +49,7 @@ SENTRY_TEST(custom_logger) sentry_options_set_debug(options, true); sentry_options_set_logger(options, test_logger, &data); sentry_init(options); + wait_for_telemetry_threads(); data.assert_now = true; SENTRY_WARNF("Oh this is %s", "bad"); @@ -66,6 +76,7 @@ SENTRY_TEST(logger_enable_disable_functionality) sentry_options_set_debug(options, true); sentry_options_set_logger(options, test_logger, &data); sentry_init(options); + wait_for_telemetry_threads(); // Test logging is enabled by default data.called = 0; @@ -134,6 +145,7 @@ SENTRY_TEST(logger_level) sentry_options_set_logger_level(options, test_cases[i].level); sentry_options_set_logger(options, test_log_level, &data); sentry_init(options); + wait_for_telemetry_threads(); data.assert_now = true; // Test all 5 levels in order from most to least verbose