Skip to content

Commit

Permalink
case-insensitive header names
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspimentel committed Jan 8, 2025
1 parent a185d6b commit 402db6b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions utils/build/docker/dotnet/parametric/Endpoints/ApmTestApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,23 @@ private static async Task<string> 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<string, List<string>>(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)
{
Expand Down

0 comments on commit 402db6b

Please sign in to comment.