Skip to content

Commit

Permalink
ref: Pass options to scope apply directly (#521)
Browse files Browse the repository at this point in the history
Swatinem authored Apr 20, 2021
1 parent 7d6f29f commit c041386
Showing 7 changed files with 28 additions and 32 deletions.
5 changes: 3 additions & 2 deletions src/backends/sentry_backend_crashpad.cpp
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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;
26 changes: 12 additions & 14 deletions src/sentry_backend.h
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/sentry_core.c
Original file line number Diff line number Diff line change
@@ -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) {
5 changes: 0 additions & 5 deletions src/sentry_core.h
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 7 additions & 8 deletions src/sentry_scope.c
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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)
@@ -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));
3 changes: 2 additions & 1 deletion src/sentry_scope.h
Original file line number Diff line number Diff line change
@@ -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);

/**
* This will update a sessions `distinct_id`, which is generated out of other
4 changes: 3 additions & 1 deletion tests/unit/test_mpack.c
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit c041386

Please sign in to comment.