-
-
Notifications
You must be signed in to change notification settings - Fork 203
feat(cache): consent-aware offline caching #1542
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
base: master
Are you sure you want to change the base?
Changes from all commits
2f9cd13
7118dbc
1b09433
8c7ca45
1bb4358
63ab463
233e06d
39cb2de
e6d7611
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,13 +80,13 @@ load_user_consent(sentry_options_t *opts) | |
| sentry__path_free(consent_path); | ||
| switch (contents ? contents[0] : 0) { | ||
| case '1': | ||
| opts->user_consent = SENTRY_USER_CONSENT_GIVEN; | ||
| opts->run->user_consent = SENTRY_USER_CONSENT_GIVEN; | ||
| break; | ||
| case '0': | ||
| opts->user_consent = SENTRY_USER_CONSENT_REVOKED; | ||
| opts->run->user_consent = SENTRY_USER_CONSENT_REVOKED; | ||
| break; | ||
| default: | ||
| opts->user_consent = SENTRY_USER_CONSENT_UNKNOWN; | ||
| opts->run->user_consent = SENTRY_USER_CONSENT_UNKNOWN; | ||
| break; | ||
| } | ||
| sentry_free(contents); | ||
|
|
@@ -97,9 +97,7 @@ sentry__should_skip_upload(void) | |
| { | ||
| bool skip = true; | ||
| SENTRY_WITH_OPTIONS (options) { | ||
| skip = options->require_user_consent | ||
| && sentry__atomic_fetch((long *)&options->user_consent) | ||
| != SENTRY_USER_CONSENT_GIVEN; | ||
| skip = sentry__run_should_skip_upload(options->run); | ||
| } | ||
| return skip; | ||
| } | ||
|
|
@@ -207,6 +205,7 @@ sentry_init(sentry_options_t *options) | |
| SENTRY_WARN("failed to initialize run directory"); | ||
| goto fail; | ||
| } | ||
| options->run->require_user_consent = options->require_user_consent; | ||
|
|
||
| load_user_consent(options); | ||
|
|
||
|
|
@@ -437,7 +436,7 @@ static void | |
| set_user_consent(sentry_user_consent_t new_val) | ||
| { | ||
| SENTRY_WITH_OPTIONS (options) { | ||
| if (sentry__atomic_store((long *)&options->user_consent, new_val) | ||
| if (sentry__atomic_store(&options->run->user_consent, new_val) | ||
| != new_val) { | ||
| if (options->backend | ||
| && options->backend->user_consent_changed_func) { | ||
|
|
@@ -449,6 +448,8 @@ set_user_consent(sentry_user_consent_t new_val) | |
| switch (new_val) { | ||
| case SENTRY_USER_CONSENT_GIVEN: | ||
| sentry__path_write_buffer(consent_path, "1\n", 2); | ||
| // flush any envelopes cached while consent was revoked | ||
| sentry_transport_retry(options->transport); | ||
| break; | ||
| case SENTRY_USER_CONSENT_REVOKED: | ||
| sentry__path_write_buffer(consent_path, "0\n", 2); | ||
|
|
@@ -486,7 +487,7 @@ sentry_user_consent_get(void) | |
| sentry_user_consent_t rv = SENTRY_USER_CONSENT_UNKNOWN; | ||
| SENTRY_WITH_OPTIONS (options) { | ||
| rv = (sentry_user_consent_t)(int)sentry__atomic_fetch( | ||
| (long *)&options->user_consent); | ||
| &options->run->user_consent); | ||
| } | ||
| return rv; | ||
| } | ||
|
|
@@ -505,13 +506,19 @@ void | |
| sentry__capture_envelope( | ||
| sentry_transport_t *transport, sentry_envelope_t *envelope) | ||
| { | ||
| bool has_consent = !sentry__should_skip_upload(); | ||
| if (!has_consent) { | ||
| SENTRY_INFO("discarding envelope due to missing user consent"); | ||
| sentry_envelope_free(envelope); | ||
| if (!sentry__should_skip_upload()) { | ||
| sentry__transport_send_envelope(transport, envelope); | ||
| return; | ||
| } | ||
| sentry__transport_send_envelope(transport, envelope); | ||
| bool cached = false; | ||
| SENTRY_WITH_OPTIONS (options) { | ||
| if (options->cache_keep || options->http_retry) { | ||
|
Comment on lines
+509
to
+515
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: A race condition exists between checking user consent with Suggested FixThe check for user consent should be performed atomically with the decision to cache the envelope. Re-check the consent status within the Prompt for AI Agent |
||
| cached = sentry__run_write_cache(options->run, envelope, 0); | ||
| } | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| SENTRY_INFO(cached ? "caching envelope due to missing user consent" | ||
| : "discarding envelope due to missing user consent"); | ||
| sentry_envelope_free(envelope); | ||
| } | ||
|
|
||
| void | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.