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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Fixes**:

- Add logs flush on crash. This is not available for macOS with the `crashpad` backend. ([#1404](https://github.com/getsentry/sentry-native/pull/1404))
- Re-add setting thread name for Windows transport. ([#1424](https://github.com/getsentry/sentry-native/pull/1424))

**Internal**:

Expand Down
8 changes: 8 additions & 0 deletions src/sentry_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,14 @@ sentry__bgworker_setname(sentry_bgworker_t *bgw, const char *thread_name)
bgw->thread_name = sentry__string_clone(thread_name);
}

#ifdef SENTRY_UNITTEST
const char *
sentry__bgworker_get_thread_name(sentry_bgworker_t *bgw)
{
return bgw ? bgw->thread_name : NULL;
}
#endif

#if defined(SENTRY_PLATFORM_UNIX) || defined(SENTRY_PLATFORM_NX)
# include "sentry_cpu_relax.h"

Expand Down
8 changes: 8 additions & 0 deletions src/sentry_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@ int sentry__bgworker_shutdown(sentry_bgworker_t *bgw, uint64_t timeout);
*/
void sentry__bgworker_setname(sentry_bgworker_t *bgw, const char *thread_name);

#ifdef SENTRY_UNITTEST
/**
* Test helper function to get the thread name from a bgworker.
* Only available in unit tests.
*/
const char *sentry__bgworker_get_thread_name(sentry_bgworker_t *bgw);
#endif

/**
* This will submit a new task to the background thread.
*
Expand Down
9 changes: 9 additions & 0 deletions src/sentry_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ sentry_transport_free(sentry_transport_t *transport)
sentry_free(transport);
}

#ifdef SENTRY_UNITTEST
void *
sentry__transport_get_bgworker(sentry_transport_t *transport)
{
// For HTTP transports (curl/winhttp), the transport state is the bgworker
return transport ? transport->state : NULL;
}
#endif

#ifdef SENTRY_TRANSPORT_COMPRESSION
static bool
gzipped_with_compression(const char *body, const size_t body_len,
Expand Down
8 changes: 8 additions & 0 deletions src/sentry_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ sentry_transport_t *sentry__transport_new_default(void);
size_t sentry__transport_dump_queue(
sentry_transport_t *transport, sentry_run_t *run);

#ifdef SENTRY_UNITTEST
/**
* Test helper function to get the bgworker from a transport.
* Only available in unit tests and only works for HTTP transports.
*/
void *sentry__transport_get_bgworker(sentry_transport_t *transport);
#endif

typedef struct sentry_prepared_http_header_s {
const char *key;
char *value;
Expand Down
2 changes: 2 additions & 0 deletions src/transports/sentry_transport_winhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ sentry__winhttp_transport_start(
state->user_agent = sentry__string_to_wstr(opts->user_agent);
state->debug = opts->debug;

sentry__bgworker_setname(bgworker, opts->transport_thread_name);

const char *env_proxy = opts->dsn
? getenv(opts->dsn->is_secure ? "https_proxy" : "http_proxy")
: NULL;
Expand Down
4 changes: 4 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


def test_unit(cmake, unittest):
if unittest in ["basic_transport_thread_name"]:
pytest.skip("excluded from unit test-suite")
cwd = cmake(
["sentry_test_unit"],
{"SENTRY_BACKEND": "none", "SENTRY_TRANSPORT": "none"},
Expand All @@ -27,6 +29,8 @@ def test_unit_transport(cmake, unittest):


def test_unit_with_test_path(cmake, unittest):
if unittest in ["basic_transport_thread_name"]:
pytest.skip("excluded from unit test-suite")
cwd = cmake(
["sentry_test_unit"],
{"SENTRY_BACKEND": "none", "SENTRY_TRANSPORT": "none"},
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/test_basic.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "sentry_core.h"
#include "sentry_database.h"
#include "sentry_options.h"
#include "sentry_string.h"
#include "sentry_sync.h"
#include "sentry_testsupport.h"
#include "sentry_transport.h"

static void
send_envelope_test_basic(sentry_envelope_t *envelope, void *data)
Expand Down Expand Up @@ -304,3 +307,41 @@ SENTRY_TEST(capture_minidump_invalid_path)

sentry_close();
}

SENTRY_TEST(basic_transport_thread_name)
{
const char *expected_thread_name = "sentry::worker_thread";

SENTRY_TEST_OPTIONS_NEW(options);
sentry_options_set_dsn(options, "https://[email protected]/42");
sentry_options_set_transport_thread_name(options, expected_thread_name);

// Initialize sentry which should start the transport and set the thread
// name
TEST_CHECK_INT_EQUAL(sentry_init(options), 0);

// Access the transport through runtime options to check if thread name was
// set
SENTRY_WITH_OPTIONS (runtime_options) {
TEST_ASSERT(!!runtime_options->transport);

// Get the bgworker from the transport (for HTTP transports)
sentry_bgworker_t *bgworker
= (sentry_bgworker_t *)sentry__transport_get_bgworker(
runtime_options->transport);
TEST_ASSERT(!!bgworker);

// Check if the thread name was properly set on the bgworker
const char *actual_thread_name
= sentry__bgworker_get_thread_name(bgworker);

if (actual_thread_name) {
TEST_CHECK_STRING_EQUAL(actual_thread_name, expected_thread_name);
} else {
TEST_CHECK(false); // Fail if thread_name is NULL
TEST_MSG("Transport thread name was not set ");
}
}

sentry_close();
}
1 change: 1 addition & 0 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ XX(basic_logging_functionality)
XX(basic_spans)
XX(basic_tracing_context)
XX(basic_transaction)
XX(basic_transport_thread_name)
XX(basic_write_envelope_to_file)
XX(bgworker_flush)
XX(breadcrumb_without_type_or_message_still_valid)
Expand Down
Loading