Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Match sentry-trace header case-insensitively #665

Merged
merged 2 commits into from
Jan 20, 2022
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
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