public void TestActiveSpanAutoReference() { InMemoryReporter reporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("test") .WithReporter(reporter) .WithSampler(new ConstSampler(true)) .Build(); using (IScope parent = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true)) { tracer.BuildSpan("child").StartActive(finishSpanOnDispose: true).Dispose(); } Assert.Equal(2, reporter.GetSpans().Count); Span childSpan = reporter.GetSpans()[0]; Span parentSpan = reporter.GetSpans()[1]; Assert.Equal("child", childSpan.OperationName); Assert.Single(childSpan.GetReferences()); Assert.Equal("parent", parentSpan.OperationName); Assert.Empty(parentSpan.GetReferences()); Assert.Equal(References.ChildOf, childSpan.GetReferences()[0].Type); Assert.Equal(parentSpan.Context, childSpan.GetReferences()[0].Context); Assert.Equal(parentSpan.Context.TraceId, childSpan.Context.TraceId); Assert.Equal(parentSpan.Context.SpanId, childSpan.Context.ParentId); }
public void TestNoAutoRefWithExistingRefs() { InMemoryReporter reporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("test") .WithReporter(reporter) .WithSampler(new ConstSampler(true)) .Build(); ISpan initialSpan = tracer.BuildSpan("initial").Start(); using (IScope parent = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true)) { tracer.BuildSpan("child").AsChildOf(initialSpan.Context).StartActive(finishSpanOnDispose: true).Dispose(); } initialSpan.Finish(); Assert.Equal(3, reporter.GetSpans().Count); Span childSpan = reporter.GetSpans()[0]; Span parentSpan = reporter.GetSpans()[1]; Span initSpan = reporter.GetSpans()[2]; Assert.Empty(initSpan.GetReferences()); Assert.Empty(parentSpan.GetReferences()); Assert.Equal(initSpan.Context.TraceId, childSpan.Context.TraceId); Assert.Equal(initSpan.Context.SpanId, childSpan.Context.ParentId); Assert.Equal(0L, initSpan.Context.ParentId); Assert.Equal(0L, parentSpan.Context.ParentId); }
public void TestActiveSpanAutoFinishOnClose() { InMemoryReporter reporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("test") .WithReporter(reporter) .WithSampler(new ConstSampler(true)) .Build(); tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true).Dispose(); Assert.Single(reporter.GetSpans()); }
public void TestShortDeclaredIpTag() { InMemoryReporter spanReporter = new InMemoryReporter(); string ip = ":19"; Tracer tracer = new Tracer.Builder("x") .WithReporter(spanReporter) .WithTag(Constants.TracerIpTagKey, ip) .Build(); Assert.Equal(0, tracer.IPv4); }
public void TestDefaultHostTags() { InMemoryReporter spanReporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("x") .WithReporter(spanReporter) .Build(); string hostname = tracer.GetHostName(); string hostIPv4 = Dns.GetHostAddresses(hostname).First(ip => ip.AddressFamily == AddressFamily.InterNetwork).ToString(); Assert.Equal(hostname, tracer.Tags[Constants.TracerHostnameTagKey]); Assert.Equal(hostIPv4, tracer.Tags[Constants.TracerIpTagKey]); Assert.Equal(Utils.IpToInt(hostIPv4), tracer.IPv4); }
public void TestDeclaredHostTags() { InMemoryReporter spanReporter = new InMemoryReporter(); string hostname = "myhost"; string ip = "1.1.1.1"; Tracer tracer = new Tracer.Builder("x") .WithReporter(spanReporter) .WithTag(Constants.TracerHostnameTagKey, hostname) .WithTag(Constants.TracerIpTagKey, ip) .Build(); Assert.Equal(hostname, tracer.Tags[Constants.TracerHostnameTagKey]); Assert.Equal(ip, tracer.Tags[Constants.TracerIpTagKey]); Assert.Equal(Utils.IpToInt(ip), tracer.IPv4); }
public BaggageSetterTests() { _metricsFactory = new InMemoryMetricsFactory(); _reporter = new InMemoryReporter(); _metrics = new MetricsImpl(_metricsFactory); _mgr = Substitute.For <IBaggageRestrictionManager>(); _setter = new BaggageSetter(_mgr, _metrics); _tracer = new Tracer.Builder(Service) .WithReporter(_reporter) .WithSampler(new ConstSampler(true)) .WithMetrics(_metrics) .Build(); _span = (Span)_tracer.BuildSpan("some-operation").Start(); }
public void TestActiveSpanNotAutoFinishOnClose() { InMemoryReporter reporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("test") .WithReporter(reporter) .WithSampler(new ConstSampler(true)) .Build(); IScope scope = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: false); Span span = (Span)scope.Span; scope.Dispose(); Assert.Empty(reporter.GetSpans()); span.Finish(); Assert.Single(reporter.GetSpans()); }
public SpanTests() { metricsFactory = new InMemoryMetricsFactory(); reporter = new InMemoryReporter(); clock = Substitute.For <IClock>(); metrics = new MetricsImpl(metricsFactory); tracer = new Tracer.Builder("SamplerTest") .WithReporter(reporter) .WithSampler(new ConstSampler(true)) .WithMetrics(metrics) .WithClock(clock) .WithBaggageRestrictionManager(new DefaultBaggageRestrictionManager()) .WithExpandExceptionLogs() .Build(); span = (Span)tracer.BuildSpan("some-operation").Start(); }
public void TestTracerTags() { InMemoryReporter spanReporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("x") .WithReporter(spanReporter) .WithSampler(new ConstSampler(true)) .WithZipkinSharedRpcSpan() .WithTag("tracer.tag.str", "y") .Build(); Span span = (Span)tracer.BuildSpan("root").Start(); // span should only contain sampler tags and no tracer tags Assert.Equal(2, span.GetTags().Count); Assert.True(span.GetTags().ContainsKey("sampler.type")); Assert.True(span.GetTags().ContainsKey("sampler.param")); Assert.False(span.GetTags().ContainsKey("tracer.tag.str")); }
public void TestIgnoreActiveSpan() { InMemoryReporter reporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("test") .WithReporter(reporter) .WithSampler(new ConstSampler(true)) .Build(); using (IScope parent = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true)) { tracer.BuildSpan("child").IgnoreActiveSpan().StartActive(finishSpanOnDispose: true).Dispose(); } Assert.Equal(2, reporter.GetSpans().Count); Span childSpan = reporter.GetSpans()[0]; Span parentSpan = reporter.GetSpans()[1]; Assert.Empty(reporter.GetSpans()[0].GetReferences()); Assert.Empty(reporter.GetSpans()[1].GetReferences()); Assert.NotEqual(parentSpan.Context.TraceId, childSpan.Context.TraceId); Assert.Equal(0L, childSpan.Context.ParentId); }