From d6fa85d9915d61df6e8b3dfe395eaac0a588dd85 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Thu, 20 Jan 2022 15:54:21 +0100 Subject: [PATCH 1/2] fix: Match sentry-trace header case-insensitively --- src/sentry_tracing.c | 8 ++++++-- tests/unit/test_tracing.c | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/sentry_tracing.c b/src/sentry_tracing.c index a3354790f..99df83432 100644 --- a/src/sentry_tracing.c +++ b/src/sentry_tracing.c @@ -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 (int i = 0; i < sizeof(sentry_trace); i++) { + if (tolower(key[i]) != sentry_trace[i]) { + return; + } } // https://develop.sentry.dev/sdk/performance/#header-sentry-trace diff --git a/tests/unit/test_tracing.c b/tests/unit/test_tracing.c index d5e8b5911..9beab0afe 100644 --- a/tests/unit/test_tracing.c +++ b/tests/unit/test_tracing.c @@ -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")); From 35e1faef429ffeda3a55a6ebcc916346e80e437d Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Thu, 20 Jan 2022 16:00:04 +0100 Subject: [PATCH 2/2] type conversions --- src/sentry_tracing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry_tracing.c b/src/sentry_tracing.c index 99df83432..038912526 100644 --- a/src/sentry_tracing.c +++ b/src/sentry_tracing.c @@ -127,7 +127,7 @@ sentry_transaction_context_update_from_header( { // do case-insensitive header key comparison const char sentry_trace[] = "sentry-trace"; - for (int i = 0; i < sizeof(sentry_trace); i++) { + for (size_t i = 0; i < sizeof(sentry_trace); i++) { if (tolower(key[i]) != sentry_trace[i]) { return; }