Skip to content

Commit

Permalink
assert baggage header in Samples.ManualInstrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspimentel committed Oct 30, 2024
1 parent 70851c8 commit 0aca775
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ async Task OtherStuff()
// verify instrumentation
ThrowIf(string.IsNullOrEmpty(_initialTracer.DefaultServiceName));

// baggage works without an active span
Baggage.Current["key1"] = "value1";
Expect(Baggage.Current["key1"] == "value1");

// Manual + automatic before reconfiguration
var firstOperationName = $"Manual-{++count}.Initial";
using (var scope = _initialTracer.StartActive(firstOperationName))
Expand All @@ -83,7 +87,10 @@ async Task OtherStuff()
Expect(scope.Span.GetTag("Temp") == "TempTest");
scope.Span.SetTag("Temp", null);

await SendHttpRequest("Initial");
var responseMessage = await SendHttpRequest("Initial");

// verify baggage in the request headers
Expect(responseMessage.RequestMessage.Headers.GetValues("baggage").FirstOrDefault() == "key1=value1");
}

await _initialTracer.ForceFlushAsync();
Expand Down Expand Up @@ -207,12 +214,15 @@ async Task OtherStuff()
Environment.Exit(0);
return;

async Task SendHttpRequest(string name)
async Task<HttpResponseMessage> SendHttpRequest(string name)
{
var q = $"{count}.{name}";
using var scope = Tracer.Instance.StartActive($"Manual-{q}.HttpClient");
await client.GetAsync(url + $"?q={q}");
var responseMessage = await client.GetAsync(url + $"?q={q}");

Console.WriteLine("Received response for client.GetAsync(String)");

return responseMessage;
}

void HandleHttpRequests(HttpListenerContext context)
Expand Down

0 comments on commit 0aca775

Please sign in to comment.