Skip to content
Draft
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
90 changes: 38 additions & 52 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")) {
Expand Down
26 changes: 2 additions & 24 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions ndk/lib/api/sentry-native-ndk.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 0 additions & 9 deletions ndk/lib/src/main/java/io/sentry/ndk/NdkOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
7 changes: 0 additions & 7 deletions ndk/lib/src/main/jni/sentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
25 changes: 13 additions & 12 deletions src/sentry_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
76 changes: 41 additions & 35 deletions src/sentry_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading