Skip to content

Commit

Permalink
fix: Match sentry-trace header case-insensitively (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem authored Jan 20, 2022
1 parent 02e0c5f commit 8cb3380
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/sentry_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,12 @@ void
sentry_transaction_context_update_from_header(
sentry_transaction_context_t *tx_cxt, const char *key, const char *value)
{
if (!sentry__string_eq(key, "sentry-trace")) {
return;
// do case-insensitive header key comparison
const char sentry_trace[] = "sentry-trace";
for (size_t i = 0; i < sizeof(sentry_trace); i++) {
if (tolower(key[i]) != sentry_trace[i]) {
return;
}
}

// https://develop.sentry.dev/sdk/performance/#header-sentry-trace
Expand Down
17 changes: 16 additions & 1 deletion tests/unit/test_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,29 @@ SENTRY_TEST(distributed_headers)
sentry_options_set_max_spans(options, 2);
sentry_init(options);

const char *trace_header
= "2674eb52d5874b13b560236d6c79ce8a-a0f9fdf04f1a63df-1";
const char *not_expected_header
= "00000000000000000000000000000000-0000000000000000-1";
const char *expected_trace_id = "2674eb52d5874b13b560236d6c79ce8a";

sentry_transaction_context_t *tx_ctx
= sentry_transaction_context_new("wow!", NULL);

// check case insensitive headers, and bogus header names
sentry_transaction_context_update_from_header(
tx_ctx, "SeNtry-TrAcE", trace_header);
sentry_transaction_context_update_from_header(
tx_ctx, "nop", not_expected_header);
sentry_transaction_context_update_from_header(
tx_ctx, "sentry-trace-but-a-lot-longer", not_expected_header);

sentry_transaction_t *tx
= sentry_start_transaction(tx_ctx, sentry_value_new_null());

const char *trace_id = sentry_value_as_string(
sentry_value_get_by_key(tx->inner, "trace_id"));
TEST_CHECK(!sentry__string_eq(trace_id, ""));
TEST_CHECK_STRING_EQUAL(trace_id, expected_trace_id);

const char *span_id
= sentry_value_as_string(sentry_value_get_by_key(tx->inner, "span_id"));
Expand Down

0 comments on commit 8cb3380

Please sign in to comment.