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

feat: API to add a stack trace to an exception or thread #723

Merged
merged 6 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ main(int argc, char **argv)
sentry_value_t exc = sentry_value_new_exception(
"ParseIntError", "invalid digit found in string");
if (has_arg(argc, argv, "add-stacktrace")) {
sentry_value_t stacktrace = sentry_value_new_stacktrace(NULL, 0);
sentry_value_set_by_key(exc, "stacktrace", stacktrace);
sentry_value_add_stacktrace(exc, NULL, 0);
}
sentry_value_t event = sentry_value_new_event();
sentry_event_add_exception(event, exc);
Expand Down
11 changes: 11 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,17 @@ SENTRY_EXPERIMENTAL_API sentry_value_t sentry_value_new_thread(
SENTRY_EXPERIMENTAL_API sentry_value_t sentry_value_new_stacktrace(
void **ips, size_t len);

/**
* Adds a Stack Trace conforming to the Stack Trace Interface to a value.
*
* The value needs to be either an exception event, or a thread object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exception event object, or an exception object (not event)? The implementation assumes the latter, which also makes more sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it should be

The value needs to be either an exception or a thread object.

Copy link
Collaborator Author

@supervacuus supervacuus Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you typically proceed with open conversations? I usually wait until the reviewer thinks the comment has been addressed in a follow-up commit, signaling by resolving.

*
* If `ips` is NULL the current stack trace is captured, otherwise `len` stack
* trace instruction pointers are attached to the event.
*/
SENTRY_EXPERIMENTAL_API void sentry_value_add_stacktrace(
sentry_value_t value, void **ips, size_t len);

/**
* Adds an Exception to an Event value.
*
Expand Down
6 changes: 1 addition & 5 deletions src/backends/sentry_backend_inproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ make_signal_event(
}
SENTRY_TRACEF("captured backtrace with %lu frames", frame_count);

sentry_value_t stacktrace
= sentry_value_new_stacktrace(&backtrace[0], frame_count);

sentry_value_set_by_key(exc, "stacktrace", stacktrace);

sentry_value_add_stacktrace(exc, &backtrace[0], frame_count);
sentry_event_add_exception(event, exc);

return event;
Expand Down
10 changes: 7 additions & 3 deletions src/sentry_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,12 +1200,16 @@ sentry_event_add_thread(sentry_value_t event, sentry_value_t thread)
}

void
sentry_event_value_add_stacktrace(sentry_value_t event, void **ips, size_t len)
sentry_value_add_stacktrace(sentry_value_t value, void **ips, size_t len)
{
sentry_value_t stacktrace = sentry_value_new_stacktrace(ips, len);
sentry_value_set_by_key(value, "stacktrace", stacktrace);
}

void
sentry_event_value_add_stacktrace(sentry_value_t event, void **ips, size_t len)
{
sentry_value_t thread = sentry_value_new_object();
sentry_value_set_by_key(thread, "stacktrace", stacktrace);

sentry_value_add_stacktrace(thread, ips, len);
sentry_event_add_thread(event, thread);
}