public async Task ShouldPostTraceToZipkin() { string traceId; using (var active = Tracer.BuildSpan("bar").WithTag("foo", true).WithTag("akka.net", "1.3.8") .StartActive(true)) { active.Span.Log("this is an event"); using (var active2 = Tracer.BuildSpan("foo").StartActive(true)) { active2.Span.Log("This is a nested span"); } traceId = active.Span.Context.AsInstanceOf <IZipkinSpanContext>().TraceId.ToString(); } await Task.Delay(1000); // give it some time to get uploaded var fullUri = new Uri(_httpBaseUri, $"api/v2/trace/{traceId}/"); var traceResp = await _zipkinClient.GetAsync(fullUri); traceResp.IsSuccessStatusCode.Should().BeTrue(); var json = await traceResp.Content.ReadAsStringAsync(); var traces = ZipkinDeserializer.Deserialize(json); traces.Count.Should().Be(2); var barSpan = traces.Single(x => x.name.Equals("bar")); var fooSpan = traces.Single(x => x.name.Equals("foo")); fooSpan.parentId.Should().Be(barSpan.id); }
public async Task ShouldPostTraceToZipkin() { HttpResponseMessage traceResp = null; var retries = 3; for (var i = 1; i <= retries; i++) { /* * Might have to try re-uploading the entire span. Takes Kafka a bit longer to spin up than stand-alone HTTP. * */ string traceId; using (var active = Tracer.BuildSpan("bar").WithTag("foo", true).WithTag("akka.net", "1.3.8") .StartActive(true)) { active.Span.Log("this is an event"); using (var active2 = Tracer.BuildSpan("foo").StartActive(true)) { active2.Span.Log("This is a nested span"); } traceId = active.Span.Context.AsInstanceOf <IZipkinSpanContext>().TraceId; } var fullUri = new Uri(_httpBaseUri, $"api/v2/trace/{traceId}"); try { await Task.Delay(1000); // give it some time to get uploaded traceResp = await _zipkinClient.GetAsync(fullUri); traceResp.IsSuccessStatusCode.Should() .BeTrue( $"Expected success status code, but instead found [{traceResp.StatusCode}][{traceResp.ReasonPhrase}]"); } catch (Exception ex) { if (i == retries) { throw; } } } var json = await traceResp.Content.ReadAsStringAsync(); var traces = ZipkinDeserializer.Deserialize(json); traces.Count.Should().Be(2); var barSpan = traces.Single(x => x.name.Equals("bar")); var fooSpan = traces.Single(x => x.name.Equals("foo")); fooSpan.parentId.Should().Be(barSpan.id); }
public async Task HttpReporterShouldPostCorrectlyToZipkin() { var testTracer = new ZipkinTracer(new ZipkinTracerOptions( new Endpoint(_appName), new NoOpReporter()) { ScopeManager = new AsyncLocalScopeManager() }); string traceId; Span parentSpan = null; Span childSpan = null; using (var parentScope = testTracer.BuildSpan("parent").StartActive()) { parentSpan = (Span)parentScope.Span; using (var childScope = testTracer.BuildSpan("child").StartActive()) { childSpan = (Span)childScope.Span; } traceId = parentSpan.TypedContext.TraceId; } // sanity check parentSpan.TypedContext.ParentId.Should().BeNullOrEmpty(); childSpan.TypedContext.ParentId.Should().Be(parentSpan.Context.SpanId); // create an HTTP reporting engine var httpReporter = new ZipkinHttpApiTransmitter(_zipkinClient, ZipkinHttpApiTransmitter.GetFullZipkinUri(_httpBaseUri.AbsoluteUri)); // manually transmit data to Zipkin for parent span var resp1 = await httpReporter.TransmitSpans(new[] { parentSpan }, TimeSpan.FromSeconds(3)); resp1.IsSuccessStatusCode.Should().BeTrue( $"Expected success status code, but instead found [{resp1.StatusCode}][{resp1.ReasonPhrase}]"); // manually transmit data to Zipkin for child span var resp2 = await httpReporter.TransmitSpans(new[] { childSpan }, TimeSpan.FromSeconds(3)); resp2.IsSuccessStatusCode.Should().BeTrue( $"Expected success status code, but instead found [{resp2.StatusCode}][{resp2.ReasonPhrase}]"); var fullUri = new Uri(_httpBaseUri, $"api/v2/trace/{traceId}"); HttpResponseMessage traceResp = null; var retries = 3; for (var i = 1; i <= retries; i++) { try { await Task.Delay(1000); // give it some time to get uploaded traceResp = await _zipkinClient.GetAsync(fullUri); traceResp.IsSuccessStatusCode.Should() .BeTrue( $"Expected success status code, but instead found [{traceResp.StatusCode}][{traceResp.ReasonPhrase}]"); } catch (Exception ex) { if (i == retries) { throw; } } } var json = await traceResp.Content.ReadAsStringAsync(); var traces = ZipkinDeserializer.Deserialize(json); traces.Count.Should().Be(2); }