From dacfa9d2e9e763f385bfd3393e13e37fdb17babb Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 12 Aug 2026 12:17:05 +0200 Subject: [PATCH] feat!: remove enable_logs/metrics --- CHANGELOG.md | 9 ++ examples/example.c | 97 ++++++++----------- include/sentry.h | 34 +------ ndk/lib/api/sentry-native-ndk.api | 2 - .../main/java/io/sentry/ndk/NdkOptions.java | 9 -- ndk/lib/src/main/jni/sentry.c | 9 -- src/sentry_logs.c | 25 ++--- src/sentry_metrics.c | 76 ++++++++------- src/sentry_options.c | 30 ------ src/sentry_options.h | 2 - src/sentry_telemetry.c | 17 +--- tests/test_integration_client_reports.py | 1 - 12 files changed, 105 insertions(+), 206 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86638e98fe..bee17dd316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## Unreleased +**Breaking 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`, and the options were deprecated and made no-ops in `0.16`. + > + > 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. + +## Unreleased + **Important behavior changes**: - `sentry_options_set_enable_logs` and `sentry_options_set_enable_metrics` no longer have any effect. The corresponding getters always return true. diff --git a/examples/example.c b/examples/example.c index 9d166c8d36..9671b2c895 100644 --- a/examples/example.c +++ b/examples/example.c @@ -872,12 +872,6 @@ main(int argc, char **argv) sentry_options_set_logger_enabled_when_crashed(options, 1); } - SENTRY_SUPPRESS_DEPRECATED - if (has_arg(argc, argv, "disable-logs")) { - sentry_options_set_enable_logs(options, false); - } - SENTRY_RESTORE_DEPRECATED - if (has_arg(argc, argv, "crash-reporter")) { #ifdef SENTRY_PLATFORM_WINDOWS sentry_options_set_external_crash_reporter_pathw( @@ -912,12 +906,6 @@ main(int argc, char **argv) sentry_options_set_http_retry(options, false); } - SENTRY_SUPPRESS_DEPRECATED - if (has_arg(argc, argv, "disable-metrics")) { - sentry_options_set_enable_metrics(options, false); - } - SENTRY_RESTORE_DEPRECATED - if (has_arg(argc, argv, "before-send-metric")) { sentry_options_set_before_send_metric( options, before_send_metric_callback, NULL); @@ -1081,58 +1069,49 @@ main(int argc, char **argv) } } - SENTRY_SUPPRESS_DEPRECATED - 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); } - SENTRY_RESTORE_DEPRECATED - if (!has_arg(argc, argv, "no-setup")) { sentry_set_transaction("test-transaction"); sentry_set_level(SENTRY_LEVEL_WARNING); diff --git a/include/sentry.h b/include/sentry.h index 6e874ce16e..72c290db00 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -2873,21 +2873,6 @@ SENTRY_API void sentry_options_set_strict_trace_continuation( SENTRY_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_DEPRECATED( - "This function does nothing. It will be removed in a future release.") -SENTRY_EXPERIMENTAL_API void sentry_options_set_enable_logs( - sentry_options_t *opts, int enable_logs); -SENTRY_DEPRECATED("This function always returns true. It will be removed in a " - "future release.") -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. * @@ -2959,7 +2944,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, @@ -3061,21 +3046,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_DEPRECATED( - "This function does nothing. It will be removed in a future release.") -SENTRY_EXPERIMENTAL_API void sentry_options_set_enable_metrics( - sentry_options_t *opts, int enable_metrics); -SENTRY_DEPRECATED("This function always returns true. It will be removed in a " - "future release.") -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 @@ -3158,7 +3128,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 30ecb6d55f..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,12 +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_SUPPRESS_DEPRECATED - sentry_options_set_enable_logs(options, enable_logs); - SENTRY_RESTORE_DEPRECATED - int rv = sentry_init(options); return (jint)rv; diff --git a/src/sentry_logs.c b/src/sentry_logs.c index 98ec234fb7..5ae675897a 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, @@ -519,12 +530,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)); @@ -607,12 +613,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 833c3cc39e..c506a7c5fe 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 838823850e..788ccc91e8 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; @@ -1033,20 +1031,6 @@ sentry__options_has_integration(const sentry_options_t *opts, const char *name) return false; } -void -sentry_options_set_enable_logs(sentry_options_t *opts, int enable_logs) -{ - (void)opts; - (void)enable_logs; -} - -int -sentry_options_get_enable_logs(const sentry_options_t *opts) -{ - (void)opts; - return true; -} - void sentry_options_set_logs_with_attributes( sentry_options_t *opts, int logs_with_attributes) @@ -1060,20 +1044,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) -{ - (void)opts; - (void)enable_metrics; -} - -int -sentry_options_get_enable_metrics(const sentry_options_t *opts) -{ - (void)opts; - return true; -} - 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 f974620381..01129dc73d 100644 --- a/src/sentry_options.h +++ b/src/sentry_options.h @@ -83,11 +83,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 0a16babe74..0dcd13a10f 100644 --- a/src/sentry_telemetry.c +++ b/src/sentry_telemetry.c @@ -19,11 +19,6 @@ sentry__telemetry_startup(const sentry_options_t *options) SENTRY__MUTEX_INIT_DYN_ONCE(g_telemetry_lock); sentry__mutex_lock(&g_telemetry_lock); - if (!options->enable_logs && !options->enable_metrics) { - sentry__mutex_unlock(&g_telemetry_lock); - return; - } - // use two workers for serializing telemetry batches off the batcher threads // and cap to 10x100 batches to respect the max 1000-item buffer limit: // https://develop.sentry.dev/sdk/telemetry/logs/#buffering @@ -36,22 +31,14 @@ sentry__telemetry_startup(const sentry_options_t *options) "telemetry pool unavailable; serializing in batcher thread"); } - if (options->enable_logs) { - sentry__logs_startup(options, g_telemetry_pool); - } - if (options->enable_metrics) { - sentry__metrics_startup(options, g_telemetry_pool); - } + sentry__logs_startup(options, g_telemetry_pool); + sentry__metrics_startup(options, g_telemetry_pool); sentry__mutex_unlock(&g_telemetry_lock); } void sentry__telemetry_shutdown(const sentry_options_t *options) { - if (!options->enable_logs && !options->enable_metrics) { - return; - } - SENTRY__MUTEX_INIT_DYN_ONCE(g_telemetry_lock); sentry__mutex_lock(&g_telemetry_lock); 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",