diff --git a/utils/build/docker/dotnet/parametric/Endpoints/ApmTestApi.cs b/utils/build/docker/dotnet/parametric/Endpoints/ApmTestApi.cs index dd5ecb8992..30b3529017 100644 --- a/utils/build/docker/dotnet/parametric/Endpoints/ApmTestApi.cs +++ b/utils/build/docker/dotnet/parametric/Endpoints/ApmTestApi.cs @@ -178,12 +178,23 @@ private static async Task ExtractHeaders(HttpRequest request) { var requestJson = await ParseJsonAsync(request.Body); - var headers = requestJson.GetProperty("http_headers") + var headersList = requestJson.GetProperty("http_headers") .EnumerateArray() - .GroupBy(kvp => kvp[0].ToString(), kvp => kvp[1].ToString()) - .ToDictionary(g => g.Key, g => g.ToList()); - - var extractedContext = SpanContextExtractor.Extract(headers, (dict, key) => dict.GetValueOrDefault(key) ?? []); + .GroupBy(pair => pair[0].ToString(), kvp => kvp[1].ToString()) + .Select(g => KeyValuePair.Create(g.Key, g.ToList())); + + // There's a test for case-insensitive header names, so use a case-insensitive comparer. + // (Yeah, the test is only testing this code, not the tracer itself) + // tests/parametric/test_headers_tracecontext.py + // Test_Headers_Tracecontext + // test_traceparent_header_name_valid_casing + var headersDictionary = new Dictionary>(headersList, StringComparer.OrdinalIgnoreCase); + + // TODO: returning null causes an exception when the extractor tried to iterate over the headers + var extractedContext = SpanContextExtractor.Extract( + headersDictionary, + (dict, key) => + dict.GetValueOrDefault(key) ?? []); if (extractedContext is not null) {