@@ -116,6 +116,7 @@ typedef struct {
116116 sentry_path_t *event_path;
117117 sentry_path_t *breadcrumb1_path;
118118 sentry_path_t *breadcrumb2_path;
119+ sentry_path_t *external_report_path;
119120 size_t num_breadcrumbs;
120121 std::atomic<bool > crashed;
121122 std::atomic<bool > scope_flush;
@@ -188,7 +189,7 @@ crashpad_register_wer_module(
188189#endif
189190
190191static void
191- crashpad_backend_flush_scope_to_event (const sentry_path_t *event_path,
192+ flush_scope_to_event (const sentry_path_t *event_path,
192193 const sentry_options_t *options, sentry_value_t crash_event)
193194{
194195 SENTRY_WITH_SCOPE (scope) {
@@ -212,6 +213,25 @@ crashpad_backend_flush_scope_to_event(const sentry_path_t *event_path,
212213 }
213214}
214215
216+ // Prepares an envelope with DSN, event ID, and session if available, for an
217+ // external crash reporter.
218+ static void
219+ flush_external_crash_report (
220+ const sentry_options_t *options, const sentry_uuid_t *crash_event_id)
221+ {
222+ sentry_envelope_t *envelope = sentry__envelope_new ();
223+ if (!envelope) {
224+ return ;
225+ }
226+ sentry__envelope_set_event_id (envelope, crash_event_id);
227+ if (options->session ) {
228+ sentry__envelope_add_session (envelope, options->session );
229+ }
230+
231+ sentry__run_write_external (options->run , envelope);
232+ sentry_envelope_free (envelope);
233+ }
234+
215235// This function is necessary for macOS since it has no `FirstChanceHandler`.
216236// but it is also necessary on Windows if the WER handler is enabled.
217237// This means we have to continuously flush the scope on
@@ -244,7 +264,10 @@ crashpad_backend_flush_scope(
244264 sentry_value_set_by_key (
245265 event, " level" , sentry__value_new_level (SENTRY_LEVEL_FATAL));
246266
247- crashpad_backend_flush_scope_to_event (data->event_path , options, event);
267+ flush_scope_to_event (data->event_path , options, event);
268+ if (data->external_report_path ) {
269+ flush_external_crash_report (options, &data->crash_event_id );
270+ }
248271 data->scope_flush .store (false , std::memory_order_release);
249272#endif
250273}
@@ -267,8 +290,10 @@ flush_scope_from_handler(
267290 }
268291
269292 // now we are the sole flusher and can flush into the crash event
270- crashpad_backend_flush_scope_to_event (
271- state->event_path , options, crash_event);
293+ flush_scope_to_event (state->event_path , options, crash_event);
294+ if (state->external_report_path ) {
295+ flush_external_crash_report (options, &state->crash_event_id );
296+ }
272297}
273298
274299# ifdef SENTRY_PLATFORM_WINDOWS
@@ -474,6 +499,22 @@ crashpad_backend_startup(
474499 sentry__path_free (screenshot_path);
475500 }
476501
502+ base::FilePath crash_reporter;
503+ base::FilePath crash_envelope;
504+ if (options->external_crash_reporter ) {
505+ char *filename
506+ = sentry__uuid_as_filename (&data->crash_event_id , " .envelope" );
507+ data->external_report_path
508+ = sentry__path_join_str (options->run ->external_path , filename);
509+ sentry_free (filename);
510+
511+ if (data->external_report_path ) {
512+ crash_reporter
513+ = base::FilePath (options->external_crash_reporter ->path );
514+ crash_envelope = base::FilePath (data->external_report_path ->path );
515+ }
516+ }
517+
477518 std::vector<std::string> arguments { " --no-rate-limit" };
478519
479520 // Initialize database first, flushing the consent later on as part of
@@ -501,7 +542,7 @@ crashpad_backend_startup(
501542 minidump_url ? minidump_url : " " , proxy_url, annotations, arguments,
502543 /* restartable */ true ,
503544 /* asynchronous_start */ false , attachments, screenshot,
504- options->crashpad_wait_for_upload );
545+ options->crashpad_wait_for_upload , crash_reporter, crash_envelope );
505546 sentry_free (minidump_url);
506547
507548#ifdef SENTRY_PLATFORM_WINDOWS
@@ -614,6 +655,7 @@ crashpad_backend_free(sentry_backend_t *backend)
614655 sentry__path_free (data->event_path );
615656 sentry__path_free (data->breadcrumb1_path );
616657 sentry__path_free (data->breadcrumb2_path );
658+ sentry__path_free (data->external_report_path );
617659 sentry_free (data);
618660}
619661
0 commit comments