Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 6 additions & 17 deletions src/backends/sentry_backend_breakpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern "C" {
#include "sentry_tracing.h"
#include "sentry_transport.h"
#include "sentry_unix_pageallocator.h"
#include "transports/sentry_disk_transport.h"
}

#ifdef __GNUC__
Expand Down Expand Up @@ -167,6 +166,8 @@ breakpad_backend_callback(const google_breakpad::MinidumpDescriptor &descriptor,
should_handle = !sentry_value_is_null(result);
}

sentry__transport_suspend(options->transport);

// Flush logs and metrics in a crash-safe manner before crash handling
if (options->enable_logs) {
sentry__logs_flush_crash_safe();
Expand Down Expand Up @@ -246,33 +247,21 @@ breakpad_backend_callback(const google_breakpad::MinidumpDescriptor &descriptor,
if (envelope && sentry__session_replay_has_pending(options)) {
sentry_value_t crash_event
= sentry_envelope_get_event(envelope);
sentry_transport_t *replay_transport
= sentry_new_disk_transport(options->run);
if (replay_transport) {
sentry__session_replay_flush_pending(
options, replay_transport, crash_event);
sentry__transport_dump_queue(
replay_transport, options->run);
sentry_transport_free(replay_transport);
}
sentry__session_replay_flush_pending(
options, options->transport, crash_event);
}

if (!sentry__launch_external_crash_reporter(options, envelope)) {
// capture the envelopes with the disk transport
sentry_transport_t *disk_transport
= sentry_new_disk_transport(options->run);
if (!sentry_value_is_null(transaction)) {
sentry_envelope_t *tx_envelope
= sentry__prepare_transaction(
options, transaction, nullptr);
if (tx_envelope) {
sentry__capture_envelope(
disk_transport, tx_envelope, options);
options->transport, tx_envelope, options);
}
}
sentry__capture_envelope(disk_transport, envelope, options);
sentry__transport_dump_queue(disk_transport, options->run);
sentry_transport_free(disk_transport);
sentry__capture_envelope(options->transport, envelope, options);
} else {
sentry_value_decref(transaction);
}
Expand Down
22 changes: 5 additions & 17 deletions src/backends/sentry_backend_crashpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ extern "C" {
#endif
#include "sentry_utils.h"
#include "sentry_uuid.h"
#include "transports/sentry_disk_transport.h"
}

#include <map>
Expand Down Expand Up @@ -477,6 +476,8 @@ crashpad_handler(int signum, siginfo_t *info, ucontext_t *user_context)
crash_event, nullptr, options->before_send_data);
}

sentry__transport_suspend(options->transport);

// Flush logs and metrics in a crash-safe manner before crash handling
if (options->enable_logs) {
sentry__logs_flush_crash_safe();
Expand All @@ -498,13 +499,7 @@ crashpad_handler(int signum, siginfo_t *info, ucontext_t *user_context)
if (session) {
sentry_envelope_t *envelope = sentry__envelope_new();
sentry__envelope_add_session(envelope, session);

// capture the envelope with the disk transport
sentry_transport_t *disk_transport
= sentry_new_disk_transport(options->run);
sentry__capture_envelope(disk_transport, envelope, options);
sentry__transport_dump_queue(disk_transport, options->run);
sentry_transport_free(disk_transport);
sentry__capture_envelope(options->transport, envelope, options);
}

if (sentry__session_replay_has_pending(options)) {
Expand All @@ -517,15 +512,8 @@ crashpad_handler(int signum, siginfo_t *info, ucontext_t *user_context)
sentry__ringbuffer_to_list(scope->breadcrumbs));
}

sentry_transport_t *replay_transport
= sentry_new_disk_transport(options->run);
if (replay_transport) {
sentry__session_replay_flush_pending(
options, replay_transport, crash_event);
sentry__transport_dump_queue(
replay_transport, options->run);
sentry_transport_free(replay_transport);
}
sentry__session_replay_flush_pending(
options, options->transport, crash_event);
}
sentry_value_decref(crash_event);
} else {
Expand Down
23 changes: 6 additions & 17 deletions src/backends/sentry_backend_inproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "sentry_tracing.h"
#include "sentry_transport.h"
#include "sentry_unix_pageallocator.h"
#include "transports/sentry_disk_transport.h"
#include <errno.h>
#include <limits.h>
#ifdef SENTRY_PLATFORM_UNIX
Expand Down Expand Up @@ -1086,6 +1085,8 @@ process_ucontext_deferred(const sentry_ucontext_t *uctx,
SENTRY_DEBUG("skipping `on_crash` hook due to recursive crash");
}

sentry__transport_suspend(options->transport);

// Flush logs in a crash-safe manner before crash handling
if (options->enable_logs) {
sentry__logs_flush_crash_safe();
Expand Down Expand Up @@ -1135,33 +1136,21 @@ process_ucontext_deferred(const sentry_ucontext_t *uctx,
if (envelope && sentry__session_replay_has_pending(options)) {
sentry_value_t crash_event
= sentry_envelope_get_event(envelope);
sentry_transport_t *replay_transport
= sentry_new_disk_transport(options->run);
if (replay_transport) {
sentry__session_replay_flush_pending(
options, replay_transport, crash_event);
sentry__transport_dump_queue(
replay_transport, options->run);
sentry_transport_free(replay_transport);
}
sentry__session_replay_flush_pending(
options, options->transport, crash_event);
}

if (!sentry__launch_external_crash_reporter(options, envelope)) {
// capture the envelopes with the disk transport
sentry_transport_t *disk_transport
= sentry_new_disk_transport(options->run);
if (!sentry_value_is_null(transaction)) {
sentry_envelope_t *tx_envelope
= sentry__prepare_transaction(
options, transaction, NULL);
if (tx_envelope) {
sentry__capture_envelope(
disk_transport, tx_envelope, options);
options->transport, tx_envelope, options);
}
}
sentry__capture_envelope(disk_transport, envelope, options);
sentry__transport_dump_queue(disk_transport, options->run);
sentry_transport_free(disk_transport);
sentry__capture_envelope(options->transport, envelope, options);
} else {
sentry_value_decref(transaction);
}
Expand Down
41 changes: 16 additions & 25 deletions src/backends/sentry_backend_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "sentry_tracing.h"
#include "sentry_transport.h"
#include "sentry_value.h"
#include "transports/sentry_disk_transport.h"

// Global process-wide synchronization for IPC and shared memory access
// This lives for the entire backend lifetime and is shared across all threads
Expand Down Expand Up @@ -989,6 +988,8 @@ native_backend_except(sentry_backend_t *backend, const sentry_ucontext_t *uctx)

SENTRY_DEBUG("handling native backend exception");

sentry__transport_suspend(options->transport);

// Flush logs and metrics in a crash-safe manner before crash handling
if (options->enable_logs) {
sentry__logs_flush_crash_safe();
Expand Down Expand Up @@ -1087,32 +1088,22 @@ native_backend_except(sentry_backend_t *backend, const sentry_ucontext_t *uctx)
SENTRY_SESSION_STATUS_CRASHED);

if (session || !sentry_value_is_null(transaction)) {
sentry_transport_t *disk_transport
= sentry_new_disk_transport(options->run);
if (disk_transport) {
if (!sentry_value_is_null(transaction)) {
sentry_envelope_t *tx_envelope
= sentry__prepare_transaction(
options, transaction, NULL);
if (tx_envelope) {
sentry__capture_envelope(
disk_transport, tx_envelope, options);
}
if (!sentry_value_is_null(transaction)) {
sentry_envelope_t *tx_envelope
= sentry__prepare_transaction(
options, transaction, NULL);
if (tx_envelope) {
sentry__capture_envelope(
options->transport, tx_envelope, options);
}
if (session) {
sentry_envelope_t *envelope
= sentry__envelope_new();
if (envelope) {
sentry__envelope_add_session(envelope, session);
sentry__capture_envelope(
disk_transport, envelope, options);
}
}
if (session) {
sentry_envelope_t *envelope = sentry__envelope_new();
if (envelope) {
sentry__envelope_add_session(envelope, session);
sentry__capture_envelope(
options->transport, envelope, options);
}
sentry__transport_dump_queue(
disk_transport, options->run);
sentry_transport_free(disk_transport);
} else {
sentry_value_decref(transaction);
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ sentry_init(sentry_options_t *options)
}

transport = options->transport;
if (!transport) {
transport = sentry__transport_new_null();
options->transport = transport;
}
sentry_path_t *database_path = options->database_path;
options->database_path = sentry__path_absolute(database_path);
if (options->database_path) {
Expand Down Expand Up @@ -199,7 +203,12 @@ sentry_init(sentry_options_t *options)
// Also, we want to continue - crash capture doesn't need transport.
sentry__transport_shutdown(transport, 0);
sentry_options_set_transport(options, NULL);
transport = NULL;
transport = options->transport;
if (!transport
|| sentry__transport_startup(transport, options) != 0) {
SENTRY_WARN("failed to initialize fallback transport");
goto fail;
}
#else
SENTRY_WARN("failed to initialize transport");
goto fail;
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ sentry_options_set_transport(
sentry_options_t *opts, sentry_transport_t *transport)
{
sentry_transport_free(opts->transport);
opts->transport = transport;
opts->transport = transport ? transport : sentry__transport_new_null();
}

#ifdef SENTRY_PLATFORM_NX
Expand Down
36 changes: 36 additions & 0 deletions src/sentry_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "sentry_alloc.h"
#include "sentry_envelope.h"
#include "sentry_options.h"
#include "sentry_sync.h"

struct sentry_transport_s {
void (*send_envelope_func)(sentry_envelope_t *envelope, void *state);
Expand All @@ -13,9 +14,18 @@ struct sentry_transport_s {
void (*retry_func)(void *state);
void (*cleanup_func)(const sentry_options_t *options, void *state);
void *state;
sentry_run_t *run;
long suspended;
bool running;
};

static void
send_null_envelope(sentry_envelope_t *envelope, void *state)
{
(void)state;
sentry_envelope_free(envelope);
}

sentry_transport_t *
sentry_transport_new(
void (*send_func)(sentry_envelope_t *envelope, void *state))
Expand All @@ -28,6 +38,12 @@ sentry_transport_new(

return transport;
}

sentry_transport_t *
sentry__transport_new_null(void)
{
return sentry_transport_new(send_null_envelope);
}
void
sentry_transport_set_state(sentry_transport_t *transport, void *state)
{
Expand Down Expand Up @@ -73,14 +89,24 @@ sentry__transport_send_envelope(
sentry_envelope_free(envelope);
return;
}
if (sentry__atomic_fetch(&transport->suspended)) {
sentry__run_write_envelope(transport->run, envelope);
sentry_envelope_free(envelope);
return;
}
SENTRY_DEBUG("sending envelope");
transport->send_envelope_func(envelope, transport->state);
if (sentry__atomic_fetch(&transport->suspended)) {
sentry__transport_dump_queue(transport, transport->run);
}
}

int
sentry__transport_startup(
sentry_transport_t *transport, const sentry_options_t *options)
{
sentry__run_free(transport->run);
transport->run = sentry__run_incref(options->run);
if (transport->startup_func) {
SENTRY_DEBUG("starting transport");
int rv = transport->startup_func(options, transport->state);
Expand Down Expand Up @@ -131,6 +157,15 @@ sentry__transport_dump_queue(sentry_transport_t *transport, sentry_run_t *run)
return dumped;
}

void
sentry__transport_suspend(sentry_transport_t *transport)
{
if (!transport) {
return;
}
sentry__atomic_store(&transport->suspended, 1);
}

void
sentry_transport_free(sentry_transport_t *transport)
{
Expand All @@ -140,6 +175,7 @@ sentry_transport_free(sentry_transport_t *transport)
if (transport->free_func) {
transport->free_func(transport->state);
}
sentry__run_free(transport->run);
sentry_free(transport);
}

Expand Down
6 changes: 6 additions & 0 deletions src/sentry_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ sentry_transport_t *sentry__transport_new_default(void);
size_t sentry__transport_dump_queue(
sentry_transport_t *transport, sentry_run_t *run);

/** Creates an internal transport that discards envelopes. */
sentry_transport_t *sentry__transport_new_null(void);

/** Sets the run used for automatic queue dumps. */
void sentry__transport_suspend(sentry_transport_t *transport);

void *sentry__transport_get_state(sentry_transport_t *transport);

void sentry__transport_set_retry_func(
Expand Down
Loading
Loading