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

ref: Pass options to scope apply directly #521

Merged
merged 1 commit into from
Apr 20, 2021
Merged
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
5 changes: 3 additions & 2 deletions src/backends/sentry_backend_crashpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ sentry__crashpad_backend_user_consent_changed(sentry_backend_t *backend)
}

static void
sentry__crashpad_backend_flush_scope(sentry_backend_t *backend)
sentry__crashpad_backend_flush_scope(
sentry_backend_t *backend, const sentry_options_t *options)
{
const crashpad_state_t *data = (crashpad_state_t *)backend->data;
if (!data->event_path) {
Expand All @@ -78,7 +79,7 @@ sentry__crashpad_backend_flush_scope(sentry_backend_t *backend)
sentry_value_t event = sentry_value_new_object();
SENTRY_WITH_SCOPE (scope) {
// we want the scope without any modules or breadcrumbs
sentry__scope_apply_to_event(scope, event, SENTRY_SCOPE_NONE);
sentry__scope_apply_to_event(scope, options, event, SENTRY_SCOPE_NONE);
}

size_t mpack_size;
Expand Down
26 changes: 12 additions & 14 deletions src/sentry_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@
* can ensure that any captured crash contains the sentry scope and other
* information.
*/
struct sentry_backend_s;
typedef struct sentry_backend_s {
int (*startup_func)(
struct sentry_backend_s *, const sentry_options_t *options);
void (*shutdown_func)(struct sentry_backend_s *);
void (*free_func)(struct sentry_backend_s *);
void (*except_func)(
struct sentry_backend_s *, const struct sentry_ucontext_s *);
void (*flush_scope_func)(struct sentry_backend_s *);
typedef struct sentry_backend_s sentry_backend_t;
struct sentry_backend_s {
int (*startup_func)(sentry_backend_t *, const sentry_options_t *options);
void (*shutdown_func)(sentry_backend_t *);
void (*free_func)(sentry_backend_t *);
void (*except_func)(sentry_backend_t *, const struct sentry_ucontext_s *);
void (*flush_scope_func)(
sentry_backend_t *, const sentry_options_t *options);
// NOTE: The breadcrumb is not moved into the hook and does not need to be
// `decref`-d internally.
void (*add_breadcrumb_func)(
struct sentry_backend_s *, sentry_value_t breadcrumb);
void (*user_consent_changed_func)(struct sentry_backend_s *);
uint64_t (*get_last_crash_func)(struct sentry_backend_s *);
void (*add_breadcrumb_func)(sentry_backend_t *, sentry_value_t breadcrumb);
void (*user_consent_changed_func)(sentry_backend_t *);
uint64_t (*get_last_crash_func)(sentry_backend_t *);
void *data;
bool can_capture_after_shutdown;
} sentry_backend_t;
};

/**
* This will free a previously allocated backend.
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ sentry__prepare_event(const sentry_options_t *options, sentry_value_t event,
if (!options->symbolize_stacktraces) {
mode &= ~SENTRY_SCOPE_STACKTRACES;
}
sentry__scope_apply_to_event(scope, event, mode);
sentry__scope_apply_to_event(scope, options, event, mode);
}

if (options->before_send_func) {
Expand Down
5 changes: 0 additions & 5 deletions src/sentry_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ sentry_value_t sentry__ensure_event_id(
*/
const sentry_options_t *sentry__options_getref(void);

/**
* Release the lock on the global options.
*/
void sentry__options_unlock(void);

#define SENTRY_WITH_OPTIONS(Options) \
for (const sentry_options_t *Options = sentry__options_getref(); Options; \
sentry_options_free((sentry_options_t *)Options), Options = NULL)
Expand Down
15 changes: 7 additions & 8 deletions src/sentry_scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ sentry__scope_flush_unlock(const sentry_scope_t *scope)
// we try to unlock the scope/session lock as soon as possible. The
// backend will do its own `WITH_SCOPE` internally.
if (options->backend && options->backend->flush_scope_func) {
options->backend->flush_scope_func(options->backend);
options->backend->flush_scope_func(options->backend, options);
}
}
if (!did_unlock) {
Expand Down Expand Up @@ -237,8 +237,9 @@ sentry__symbolize_stacktrace(sentry_value_t stacktrace)
}

void
sentry__scope_apply_to_event(
const sentry_scope_t *scope, sentry_value_t event, sentry_scope_mode_t mode)
sentry__scope_apply_to_event(const sentry_scope_t *scope,
const sentry_options_t *options, sentry_value_t event,
sentry_scope_mode_t mode)
{
#define IS_NULL(Key) sentry_value_is_null(sentry_value_get_by_key(event, Key))
#define SET(Key, Value) sentry_value_set_by_key(event, Key, Value)
Expand All @@ -264,11 +265,9 @@ sentry__scope_apply_to_event(

PLACE_STRING("platform", "native");

SENTRY_WITH_OPTIONS (options) {
PLACE_STRING("release", options->release);
PLACE_STRING("dist", options->dist);
PLACE_STRING("environment", options->environment);
}
PLACE_STRING("release", options->release);
PLACE_STRING("dist", options->dist);
PLACE_STRING("environment", options->environment);

if (IS_NULL("level")) {
SET("level", sentry__value_new_level(scope->level));
Expand Down
3 changes: 2 additions & 1 deletion src/sentry_scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ void sentry__scope_flush_unlock(const sentry_scope_t *scope);
* attached.
*/
void sentry__scope_apply_to_event(const sentry_scope_t *scope,
sentry_value_t event, sentry_scope_mode_t mode);
const sentry_options_t *options, sentry_value_t event,
sentry_scope_mode_t mode);
Swatinem marked this conversation as resolved.
Show resolved Hide resolved

/**
* This will update a sessions `distinct_id`, which is generated out of other
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_mpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ SENTRY_TEST(mpack_removed_tags)
sentry_set_extra("int", sentry_value_new_int32(1234));
sentry_set_extra("double", sentry_value_new_double(12.34));

sentry_options_t *options = sentry_options_new();
SENTRY_WITH_SCOPE (scope) {
sentry__scope_apply_to_event(scope, obj, SENTRY_SCOPE_NONE);
sentry__scope_apply_to_event(scope, options, obj, SENTRY_SCOPE_NONE);
}

size_t size;
char *buf = sentry_value_to_msgpack(obj, &size);

sentry_options_free(options);
sentry_value_decref(obj);
sentry_free(buf);
sentry__scope_cleanup();
Expand Down