Skip to content

Value supplied in sentry_options_set_max_breadcrumbs not honoured #565

@MechInventor

Description

@MechInventor

Description

Setting the number of breadcrumbs to a number other that the default does not lead to that number being used

When does the problem happen

  • During build
  • During run-time
  • When capturing a hard crash

Environment

  • OS: [Windows/Mac/Linux]
  • Compiler: [GCC 10/MSVC 19.16.27030.1]
  • CMake version and config: [e.g. 3.18.1, SENTRY_BACKEND=inproc]

Steps To Reproduce

During application startup run the line of code

sentry_options_set_max_breadcrumbs(options, 256);

Log more than 256 events, then crash

observe that only 100 (the default) will be logged

Suggested Resolution

It appears that sentry__crashpad_backend_add_breadcrumb uses SENTRY_BREADCRUMBS_MAX without looking to the
value set in options. an alteration such as below may be suitable, though consideration may need to be given to resizing buffers and any aspects of threading that I have not looked into.

static void
sentry__crashpad_backend_add_breadcrumb(
sentry_backend_t *backend, sentry_value_t breadcrumb)
{
crashpad_state_t *data = (crashpad_state_t *)backend->data;

size_t max_breadcrumbs = options->max_breadcrumbs 
	? options->max_breadcrumbs 
	: SENTRY_BREADCRUMBS_MAX;

bool first_breadcrumb = data->num_breadcrumbs % max_breadcrumbs == 0;

const sentry_path_t *breadcrumb_file = data->num_breadcrumbs % (max_breadcrumbs * 2) 
< max_breadcrumbs
    ? data->breadcrumb1_path
    : data->breadcrumb2_path;
data->num_breadcrumbs++;
if (!breadcrumb_file) {
    return;
}

size_t mpack_size;
char *mpack = sentry_value_to_msgpack(breadcrumb, &mpack_size);
if (!mpack) {
    return;
}

int rv = first_breadcrumb
    ? sentry__path_write_buffer(breadcrumb_file, mpack, mpack_size)
    : sentry__path_append_buffer(breadcrumb_file, mpack, mpack_size);
sentry_free(mpack);

if (rv != 0) {
    SENTRY_DEBUG("flushing breadcrumb to msgpack failed");
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions