public async Task Traces_Block() { var uri = $"/TraceSamples/{nameof(TraceSamplesController.TraceHelloWorld)}/{_testId}"; var response = await _client.GetAsync(uri); var trace = s_tracePolling.GetTrace(uri, Timestamp.FromDateTime(_startTime)); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, _testId); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); }
public async Task Traces_MethodInjection() { var uri = $"/TraceSamplesMethod/{nameof(TraceSamplesMethodController.TraceHelloWorld)}/{_testId}"; var response = await _client.GetAsync(uri); var trace = TraceEntryPolling.Default.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, _testId); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); }
public async Task Traces_Outgoing() { var uri = $"/TraceSamples/{nameof(TraceSamplesController.TraceOutgoing)}/{_testId}"; var response = await _client.GetAsync(uri); var trace = s_polling.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, "https://weather.com/"); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); }
public async Task Traces_Outgoing() { Skip.If(TestEnvironment.IsWindows(), "https://github.com/googleapis/google-cloud-dotnet/issues/5425"); var uri = $"/TraceSamples/{nameof(TraceSamplesController.TraceOutgoing)}/{_testId}"; var response = await _client.GetAsync(uri); var trace = s_polling.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, "https://weather.com/"); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); }
private static async Task TestTrace(string testId, DateTimeOffset startTime, HttpClient client) { var uri = $"/Trace/{nameof(TraceController.Trace)}/{testId}"; var childSpanName = EntryData.GetMessage(nameof(TraceController.Trace), testId); var response = await client.GetAsync(uri); var trace = TraceEntryPolling.Default.GetTrace(uri, startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, childSpanName); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); }
public async Task Traces_OutgoingClientFactory() { var uri = $"/TraceSamples/{nameof(TraceSamplesController.TraceOutgoingClientFactory)}/{_testId}"; using var server = GetTestServer <TraceClientFactoryTestApplication.Startup>(); using var client = server.CreateClient(); var response = await client.GetAsync(uri); var trace = s_polling.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, "http://weather.com/"); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); }
public async Task Trace(Action <IWebHostBuilder> testServerConfigurator) { var uri = $"/Trace/{nameof(TraceController.Trace)}/{_testId}"; var childSpanName = EntryData.GetMessage(nameof(TraceController.Trace), _testId); using var server = GetTestServer <TraceTestNoBufferHighQpsApplication>(testServerConfigurator); using var client = server.CreateClient(); var response = await client.GetAsync(uri); var trace = _polling.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, childSpanName); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); AssertNoTraceHeaders(response); }
public async Task Trace_Label(Action <IWebHostBuilder> testServerConfigurator) { var uri = $"/Trace/{nameof(TraceController.TraceLabels)}/{_testId}"; var childSpanName = EntryData.GetMessage(nameof(TraceController.TraceLabels), _testId); using var server = GetTestServer <TraceTestNoBufferHighQpsApplication>(testServerConfigurator); using var client = server.CreateClient(); await client.GetAsync(uri); var trace = _polling.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, childSpanName); TraceEntryVerifiers.AssertSpanLabelsContains(trace.Spans.First(s => s.Name == childSpanName), new Dictionary <string, string> { { TraceEntryData.TraceLabel, TraceEntryData.TraceLabelValue } }); }
public async Task Trace_DummyNameProvider(Action <IWebHostBuilder> testServerConfigurator) { var uri = $"/Trace/{nameof(TraceController.Trace)}/{_testId}"; // our dummy provider prefixes with /Dummy var expectedTraceName = $"/Dummy{uri}"; var childSpanName = EntryData.GetMessage(nameof(TraceController.Trace), _testId); using var server = GetTestServer <TraceTestCustomNameProviderNoBufferHighQpsApplication>(testServerConfigurator); using var client = server.CreateClient(); var response = await client.GetAsync(uri); var trace = _polling.GetTrace(expectedTraceName, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, expectedTraceName, childSpanName); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == expectedTraceName), TraceEntryData.HttpGetSuccessLabels); AssertNoTraceHeaders(response); }
public async Task Trace() { var uri = $"/Trace/{nameof(TraceController.Trace)}/{_testId}"; var childSpanName = EntryData.GetMessage(nameof(TraceController.Trace), _testId); using (var server = new TestServer(new WebHostBuilder().UseStartup <TraceTestNoBufferHighQpsApplication>())) using (var client = server.CreateClient()) { var response = await client.GetAsync(uri); var trace = _polling.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, childSpanName); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); } }
private static async Task TestTrace(string testId, DateTime startTime, HttpClient client) { var uri = $"/Trace/{nameof(TraceController.Trace)}/{testId}"; var childSpanName = EntryData.GetMessage(nameof(TraceController.Trace), testId); var response = await client.GetAsync(uri); // Give the polling a little extra time to find the trace as // trace processing can sometimes take time and the default buffer is a // timed buffer. var polling = new TraceEntryPolling(TimeSpan.FromSeconds(20)); var trace = polling.GetTrace(uri, Timestamp.FromDateTime(startTime)); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, childSpanName); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); }
public async Task Trace_OutGoingClientFactory_WithLabels(Action <IWebHostBuilder> testServerConfigurator) { var uri = $"/Trace/{nameof(TraceController.TraceOutgoingClientFactoryWithLabels)}/{_testId}"; var childSpanName = EntryData.GetMessage(nameof(TraceController.TraceOutgoingClientFactory), _testId); var outgoingSpanName = "https://google.com/"; using var server = GetTestServer <TraceTestNoBufferHighQpsApplication>(builder => { testServerConfigurator?.Invoke(builder); builder.ConfigureServices(services => services .AddHttpClient("outgoing_with_labels", c => c.BaseAddress = new Uri("https://google.com/")) .AddOutgoingGoogleTraceHandler(sp => _customLabels)); }); using var client = server.CreateClient(); await client.GetAsync(uri); var trace = TraceEntryPolling.Default.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, childSpanName, outgoingSpanName); TraceEntryVerifiers.AssertSpanLabelsContains(trace.Spans.First(span => span.Name == outgoingSpanName), _customLabels); }
public async Task Trace_TraceFallbackPredicate(Action <IWebHostBuilder> testServerConfigurator) { var tracedId = $"fallback{_testId}"; var tracedUri = $"/Trace/{nameof(TraceController.Trace)}/{tracedId}"; var tracedChildSpanName = EntryData.GetMessage(nameof(TraceController.Trace), tracedId); var nonTracedUri = $"/Trace/{nameof(TraceController.Trace)}/{_testId}"; using var server = GetTestServer <TraceTestFallbackPredicate>(testServerConfigurator); using var client = server.CreateClient(); var nonTracedTask = client.GetAsync(nonTracedUri); var tracedTask = client.GetAsync(tracedUri); await Task.WhenAll(nonTracedTask, tracedTask); Assert.Null(TraceEntryPolling.NoEntry.GetTrace(nonTracedUri, _startTime, expectTrace: false)); var trace = TraceEntryPolling.Default.GetTrace(tracedUri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, tracedUri, tracedChildSpanName); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == tracedUri), TraceEntryData.HttpGetSuccessLabels); }
public async Task Trace_WebServerHosted_Label() { var service = $"/api/Trace/TraceLabels/{_testId}"; var childSpanName = EntryData.GetMessage("TraceLabels", _testId); using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = PublishedServiceBaseAddress; await httpClient.GetAsync(service); } var trace = _polling.GetTrace(service, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, service, childSpanName); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == childSpanName), new Dictionary <string, string> { { TraceEntryData.TraceLabel, TraceEntryData.TraceLabelValue } }); }
public async Task Trace_WebServerHosted() { var service = $"/api/Trace/Trace/{_testId}"; var childSpanName = EntryData.GetMessage("Trace", _testId); HttpResponseMessage response; using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = PublishedServiceBaseAddress; response = await httpClient.GetAsync(service); } var trace = _polling.GetTrace(service, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, service, childSpanName); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == service), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); }
public async Task Traces_CustomTraceContext() { var uri = $"/TraceSamples/{nameof(TraceSamplesController.TraceHelloWorld)}/{_testId}"; var traceId = TraceIdFactory.Create().NextId(); using var server = GetTestServer <CustomTraceContextTestApplication.Startup>(); using var client = server.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, uri) { Headers = { { "custom_trace_id", traceId } } }; var response = await client.SendAsync(request); var trace = s_polling.GetTrace(uri, _startTime); TraceEntryVerifiers.AssertParentChildSpan(trace, uri, _testId); TraceEntryVerifiers.AssertSpanLabelsContains( trace.Spans.First(s => s.Name == uri), TraceEntryData.HttpGetSuccessLabels); Assert.False(response.Headers.Contains(TraceHeaderContext.TraceHeader)); Assert.Equal(traceId, trace.TraceId); Assert.True(response.Headers.Contains("custom_trace_id")); }
public async Task Trace_MultipleHeaderPropagation() { var createFirstSpanUri = $"/Propagation/{nameof(PropagationController.CreateFirstSpan)}/{_testId}"; var createFirstSpanSpanName = EntryData.GetMessage(nameof(PropagationController.CreateFirstSpan), _testId); var createSecondSpanUri = $"/Propagation/{nameof(PropagationController.CreatesSecondSpan)}/{_testId}"; var createSecondSpanSpanName = EntryData.GetMessage(nameof(PropagationController.CreatesSecondSpan), _testId); var createNoSpanUri = $"/Propagation/{nameof(PropagationController.CreateNoSpan)}/{_testId}"; var createNoSpanLabels = new Dictionary <string, string> { { "Message", EntryData.GetMessage(nameof(PropagationController.CreateNoSpan), _testId) } }; // The clientSideServer is the server to which this method, i.e. the client, will post the request, which in turn will generate other requests to other servers. using (var clientSideServer = new TestServer(new WebHostBuilder().UseStartup <TraceTestNoBufferHighQpsApplication>())) // The firstCallServer is the server used from within the first request to make subsequent requests. using (var firstCallServer = new TestServer(new WebHostBuilder().UseStartup <TraceTestNoBufferHighQpsApplication>())) // The secondCallServer is the server used from within the second request to make subsequent requests. using (var secondCallServer = new TestServer(new WebHostBuilder().UseStartup <TraceTestNoBufferHighQpsApplication>())) using (var client = clientSideServer.CreateClient()) { // Set the servers on the Controller so it can generate the subsequent requests. // This is needed beacuse we are not making requests against published services but // to services that are only available through the test servers. // Whoever makes requests to those services (as PropagationController does) needs to do so // through an HttpClient generated from the test server. PropagationController.FirstCallServer = firstCallServer; PropagationController.SecondCallServer = secondCallServer; // This request will in turn make other requests, always propagating a trace handler. // This request first creates a span, and within that span: // 1. Makes a request to a method that does not create a new span but annotates the existing span // which is there because of the propagating header. // 2. Makes a request that creates a second span and within that span calls the same method in 1. var response = await client.GetAsync(createFirstSpanUri); // Cleanup PropagationController.FirstCallServer = null; PropagationController.SecondCallServer = null; } var trace = _polling.GetTrace(createFirstSpanUri, _startTime); // The structure of the spans on the trace should be // + span with name createFirstSpanUri (automatically created) // ---+ span with name createFirstSpanSpanName (explicitly created in CreateFirstSpan) // -------- span with name createNoSpanUri (automatically created because of the trace header and explicitly annotated) // -------+ span with name createSecondSpanUri (automatically created because of the trace header) // -----------+ span with name createSecondSpanSpanName (explicitly created in CreateSecondSpan) // ---------------- span with name createNoSpanUri (automatically created because of the trace header and explicitly annotated) Assert.NotNull(trace); var automaticFirst = trace.Spans.Single(s => s.Name == createFirstSpanUri); var manualFirst = trace.Spans.Single(s => s.Name == createFirstSpanSpanName && s.ParentSpanId == automaticFirst.SpanId); var automaticNoSpanInFirst = trace.Spans.Single(s => s.Name == createNoSpanUri && s.ParentSpanId == manualFirst.SpanId); TraceEntryVerifiers.AssertSpanLabelsContains(automaticNoSpanInFirst, createNoSpanLabels); var automaticSecond = trace.Spans.Single(s => s.Name == createSecondSpanUri && s.ParentSpanId == manualFirst.SpanId); var manualSecond = trace.Spans.Single(s => s.Name == createSecondSpanSpanName && s.ParentSpanId == automaticSecond.SpanId); var automaticNoSpanInSecond = trace.Spans.Single(s => s.Name == createNoSpanUri && s.ParentSpanId == manualSecond.SpanId); TraceEntryVerifiers.AssertSpanLabelsContains(automaticNoSpanInSecond, createNoSpanLabels); }