Skip to content

Commit b6943ef

Browse files
jpnurmicodex
andcommitted
fix: Add cache_dir header for external crash reports
External crash reporters only receive the envelope path, so include the cache directory in envelope headers when cache_keep is enabled. This lets capable reporters cache related files without changing the one-argument protocol. Fixes GH-1688 Co-Authored-By: OpenAI Codex <noreply@openai.com>
1 parent 8198e04 commit b6943ef

5 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/backends/sentry_backend_crashpad.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ flush_external_crash_report(
253253
sentry__envelope_add_session(envelope, options->session);
254254
}
255255

256+
if (options->cache_keep) {
257+
sentry__envelope_set_header(envelope, "cache_dir",
258+
sentry_value_new_string(options->run->cache_path->path));
259+
}
256260
sentry__run_write_external(options->run, envelope);
257261
sentry_envelope_free(envelope);
258262
}

src/sentry_core.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,14 @@ sentry__launch_external_crash_reporter(
16901690
sentry_free(envelope_filename);
16911691
return false;
16921692
}
1693+
if (options->cache_keep) {
1694+
if (sentry__envelope_materialize(envelope)) {
1695+
sentry__envelope_set_header(envelope, "cache_dir",
1696+
sentry_value_new_string(options->run->cache_path->path));
1697+
} else {
1698+
SENTRY_WARN("failed to add cache_dir to external crash report");
1699+
}
1700+
}
16931701
sentry__transport_send_envelope(disk_transport, envelope);
16941702
sentry__transport_dump_queue(disk_transport, options->run);
16951703
sentry_transport_free(disk_transport);

tests/test_integration_crashpad.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ def test_crashpad_external_crash_reporter(cmake, httpserver, run_args):
768768
tmp_path = cmake(
769769
["sentry_example", "sentry_crash_reporter"], {"SENTRY_BACKEND": "crashpad"}
770770
)
771+
cache_dir = tmp_path.joinpath(".sentry-native/cache")
771772

772773
env = dict(os.environ, SENTRY_DSN=make_dsn(httpserver))
773774
httpserver.expect_oneshot_request("/api/123456/envelope/").respond_with_data("OK")
@@ -777,7 +778,7 @@ def test_crashpad_external_crash_reporter(cmake, httpserver, run_args):
777778
run(
778779
tmp_path,
779780
"sentry_example",
780-
["log", "crash-reporter"] + run_args,
781+
["log", "crash-reporter", "cache-keep"] + run_args,
781782
expect_failure=True,
782783
env=env,
783784
)
@@ -791,6 +792,7 @@ def test_crashpad_external_crash_reporter(cmake, httpserver, run_args):
791792
crash = crash_request.get_data()
792793

793794
envelope = Envelope.deserialize(crash)
795+
assert envelope.headers["cache_dir"] == str(cache_dir)
794796
assert_meta(envelope, integration="crashpad")
795797
assert_breadcrumb(envelope)
796798

tests/test_integration_http.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def test_user_report_http(cmake, httpserver):
314314
)
315315
def test_external_crash_reporter_http(cmake, httpserver, build_args):
316316
tmp_path = cmake(["sentry_example", "sentry_crash_reporter"], build_args)
317+
cache_dir = tmp_path.joinpath(".sentry-native/cache")
317318

318319
httpserver.expect_oneshot_request(
319320
"/api/123456/envelope/",
@@ -329,7 +330,7 @@ def test_external_crash_reporter_http(cmake, httpserver, build_args):
329330
run(
330331
tmp_path,
331332
"sentry_example",
332-
["log", "crash-reporter", "crash"],
333+
["log", "crash-reporter", "cache-keep", "crash"],
333334
expect_failure=True,
334335
env=env,
335336
)
@@ -354,6 +355,7 @@ def test_external_crash_reporter_http(cmake, httpserver, build_args):
354355
crash = crash_request.get_data()
355356

356357
envelope = Envelope.deserialize(crash)
358+
assert envelope.headers["cache_dir"] == str(cache_dir)
357359
assert_meta(envelope, integration=build_args.get("SENTRY_BACKEND", ""))
358360

359361
envelope = Envelope.deserialize(feedback)

tests/test_integration_native.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def test_native_external_crash_reporter(cmake, httpserver):
398398
tmp_path = cmake(
399399
["sentry_example", "sentry_crash_reporter"], {"SENTRY_BACKEND": "native"}
400400
)
401+
cache_dir = tmp_path.joinpath(".sentry-native/cache")
401402

402403
env = dict(os.environ, SENTRY_DSN=make_dsn(httpserver))
403404
httpserver.expect_oneshot_request("/api/123456/envelope/").respond_with_data("OK")
@@ -408,7 +409,7 @@ def test_native_external_crash_reporter(cmake, httpserver):
408409
run_crash(
409410
tmp_path,
410411
"sentry_example",
411-
["log", "crash-reporter", "crash"],
412+
["log", "crash-reporter", "cache-keep", "crash"],
412413
env=env,
413414
)
414415
assert waiting.result
@@ -423,6 +424,7 @@ def test_native_external_crash_reporter(cmake, httpserver):
423424

424425
# Verify it's a minidump crash report and user feedback
425426
envelope = Envelope.deserialize(crash)
427+
assert envelope.headers["cache_dir"] == str(cache_dir)
426428
assert_meta(envelope)
427429
assert_breadcrumb(envelope)
428430

0 commit comments

Comments
 (0)