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

Value supplied in sentry_options_set_max_breadcrumbs not honoured #565

Closed
1 of 3 tasks
MechInventor opened this issue Jun 30, 2021 · 1 comment · Fixed by #566
Closed
1 of 3 tasks

Value supplied in sentry_options_set_max_breadcrumbs not honoured #565

MechInventor opened this issue Jun 30, 2021 · 1 comment · Fixed by #566

Comments

@MechInventor
Copy link

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");
}

}

@MechInventor
Copy link
Author

Thanks! Can't wait for the next release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants