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: programatic minidump capture #1052

Closed
wants to merge 18 commits into from

Conversation

PlasmaDev5
Copy link
Collaborator

Resolves: #1050

Summary

Provides a new function that allows sentry to capture user created minidumps.

PlasmaDev5 and others added 2 commits October 11, 2024 19:57
This provides a new function that will allow for independently created minidumps to be captured by sentry

Resolves: #1050
Copy link

github-actions bot commented Oct 11, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 67bd3af

Copy link
Collaborator

@vaind vaind left a comment

Choose a reason for hiding this comment

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

Thanks for the change. looks straightforard so far.

Is this PR done and ready for review? because it's marked as such, I'll asume so (if not, you ca use draft PRs in the future so that reviewers don't get notifications yet).

CI is currently failing so that will need to be fixed. Also, the newly added API should have a new test case.

include/sentry.h Outdated Show resolved Hide resolved
include/sentry.h Outdated Show resolved Hide resolved
@PlasmaDev5
Copy link
Collaborator Author

Thanks for the change. looks straightforard so far.

Is this PR done and ready for review? because it's marked as such, I'll asume so (if not, you ca use draft PRs in the future so that reviewers don't get notifications yet).

CI is currently failing so that will need to be fixed. Also, the newly added API should have a new test case.

i guess somewhere between draft and final. I for sure not indented to be be merged yet but at the same time i need feedback and review before moving further.

include/sentry.h Outdated Show resolved Hide resolved
@bruno-garcia bruno-garcia changed the title Feat/programatic minidump capture feat: programatic minidump capture Oct 14, 2024
Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

Thanks @PlasmaDev5!

There are still quite a few open design decisions to consider. In this case, I tend to leave the duplication because there are already visible diverging needs.

I know that you haven't finished this yet, but the function needs

  • clear header documentation of tbd design decisions mentioned in my comments
  • an integration test and an example.c entry

include/sentry.h Outdated Show resolved Hide resolved
include/sentry.h Outdated Show resolved Hide resolved
include/sentry.h Outdated Show resolved Hide resolved
include/sentry.h Outdated Show resolved Hide resolved
src/sentry_core.c Outdated Show resolved Hide resolved
@PlasmaDev5
Copy link
Collaborator Author

Feel i addressed feedback provided.
Unit test and mentioned example.c still need doing tomorrow. but wanted to get a little more feedback

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 9.52381% with 38 lines in your changes missing coverage. Please review.

Project coverage is 81.25%. Comparing base (21c6d0a) to head (8233951).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1052      +/-   ##
==========================================
- Coverage   81.81%   81.25%   -0.57%     
==========================================
  Files          53       53              
  Lines        6363     6402      +39     
  Branches     1207     1214       +7     
==========================================
- Hits         5206     5202       -4     
- Misses       1045     1086      +41     
- Partials      112      114       +2     

Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

Thanks, things are getting in shape.

src/sentry_core.c Outdated Show resolved Hide resolved
src/sentry_core.c Outdated Show resolved Hide resolved
src/sentry_core.c Outdated Show resolved Hide resolved
src/sentry_core.c Outdated Show resolved Hide resolved
src/sentry_core.c Outdated Show resolved Hide resolved
src/sentry_core.c Outdated Show resolved Hide resolved
@PlasmaDev5
Copy link
Collaborator Author

Addressed review feedback.
Note: feedback to split declaration and initialization of envelope creates a lint error.

I also have work towards the test case and will post a draft version in a comment on here once i start work tomorrow for feedback as i am a lot more unsure with how we want to handle this step.

Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

If the format linter is bugging you, the Native SDK has a .clang-format spec that you can use locally.

If you have any questions about integration testing, please let me know.

src/sentry_core.c Outdated Show resolved Hide resolved
src/sentry_core.c Outdated Show resolved Hide resolved
@PlasmaDev5
Copy link
Collaborator Author

To give a rundown on what i have planned for the tests

I am referencing the attachment tests.
It essentially comes down to using sentry__path_write_buffer, from what i can tell it should be able to create a .dmp file and just add some unused data. I can then use the new API to send capture this file.
Im not sure if there is a better solution as im still getting to grips with the available API.

@PlasmaDev5
Copy link
Collaborator Author

@supervacuus Any feedback on the test case stuff? and hopefully all review feedback is addressed.

src/sentry_core.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

I am referencing the attachment tests.
It essentially comes down to using sentry__path_write_buffer, from what i can tell it should be able to create a .dmp file and just add some unused data. I can then use the new API to send capture this file.
Im not sure if there is a better solution as im still getting to grips with the available API.

Given that the inner parts of sentry_capture_minidump() are already covered by unit tests and its side effects primarily affect the network and the file system, I think a basic integration test should suffice for starters.

What I would do is the following:

  • Build and run the sentry_example with log and crash arguments to produce a minidump (which you can find in the database directory after the crash) and store it in tests/fixtures. At this point, you can also upload the debug info files, which will be useful if you want to verify what the function uploaded in the WebUI.
  • Add a new command (capture-minidump) to example.c that passes that fixture as an (initially hard-coded absolute system-) path and an empty event. This also lets you experiment manually with the function to see what the WebUI renders for the incoming event.
  • Alternatively, you can also send any file as a first step since we don't check whether the path pointed to contains a valid minidump
  • Get an integration test running that invokes the example using your new capture-minidump command (take inspiration from test_capture_http in test_integration_http.py, removing anything relating to transport-compression, but adding an assert_minidump(envelope) at the end)
  • You can run integration tests locally via make tests, scripts\run_tests.ps1 if you are on Windows or directly via pytest. You can check out the Makefile or the Powershell script to see the venv setup if you want to run this manually.
  • to allow the test to run in CI, you must pass the fixture path from the test to the example executable (either via command-line arg or via the environment) or let the test or build script copy the fixture to a known location relative to the example executable (which might be helpful to test the removal case).
  • if the above works,
    • add a test case for (other) attachments (using the command attachment + adding assert_attachment(envelope) to the case)
    • Add a test case for capture-minidump-remove to verify that the file at the input path was removed.

Comment on lines 1189 to 1192
if (!envelope || !sentry__envelope_add_event(envelope, event)) {
sentry_envelope_free(envelope);
sentry_value_decref(event);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This block must return and free the dump path.

SENTRY_WITH_OPTIONS (options) {
SENTRY_WITH_OPTIONS (options) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: unnecessary whitespace.

Comment on lines +1243 to +1245
if (remove_dump_on_send) {
sentry__path_remove(sentry_dump_path);
}
Copy link
Collaborator

@vaind vaind Oct 31, 2024

Choose a reason for hiding this comment

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

Because this parameter doesn't actually do what it says in the name (and it cannot at the moment), I'd remove it completely and let users move/remove the file after this function returns.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: I could of course remove it myself since I'm taking over this PR, just raised this as a discussion in the PR because I know the original issue had a request to remove processed files. It just doesn't fit with the rest of the API in my opinion.

@bruno-garcia
Copy link
Member

Closing in favor of:

@bruno-garcia bruno-garcia deleted the feat/programatic_minidump_capture branch November 1, 2024 14:33
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 this pull request may close these issues.

Allow capturing minidumps programatically
5 participants