public async Task ExecuteAsync_should_create_trace() { var requestContext = Substitute.For <IRequestContext>(); var request = new Request("GET", new Uri("vostok/process?p1=p", UriKind.Relative)); requestContext.Request.Returns(request); requestContext.Strategy.Returns(new ParallelRequestStrategy(2)); var response = new Response(ResponseCode.Conflict); var clusterResult = new ClusterResult(ClusterResultStatus.Success, new List <ReplicaResult>(), response, request); var expectedAnnotations = new Dictionary <string, string> { [TracingAnnotationNames.Kind] = "cluster-client", [TracingAnnotationNames.Component] = "cluster-client", [TracingAnnotationNames.ClusterStrategy] = "Parallel-2", [TracingAnnotationNames.ClusterStatus] = "Success", [TracingAnnotationNames.HttpUrl] = "vostok/process", [TracingAnnotationNames.HttpMethod] = "GET", [TracingAnnotationNames.HttpRequestContentLength] = "0", [TracingAnnotationNames.HttpResponseContentLength] = "0", [TracingAnnotationNames.HttpCode] = "409", [TracingAnnotationNames.Service] = "serviceName" }; traceReporter.SendSpan(Arg.Do <Span>(span => { span.Annotations.ShouldBeEquivalentTo(expectedAnnotations); })); await tracingModule.ExecuteAsync(requestContext, x => Task.FromResult(clusterResult)).ConfigureAwait(false); traceReporter.Received().SendSpan(Arg.Any <Span>()); }
public async Task SendAsync_should_create_trace() { var request = new Request("POST", new Uri("http://vostok/process?p=p1"), new Content(new byte[10])); var timeout = TimeSpan.FromHours(1); var cancellationToken = new CancellationToken(); var response = new Response(ResponseCode.BadRequest); transport.SendAsync(request, timeout, cancellationToken).Returns(response); var expectedAnnotations = new Dictionary <string, string> { [TracingAnnotationNames.Kind] = "http-client", [TracingAnnotationNames.Component] = "cluster-client", [TracingAnnotationNames.HttpUrl] = "http://vostok/process", [TracingAnnotationNames.HttpMethod] = "POST", [TracingAnnotationNames.HttpRequestContentLength] = "10", [TracingAnnotationNames.HttpResponseContentLength] = "0", [TracingAnnotationNames.HttpCode] = "400" }; traceReporter.SendSpan(Arg.Do <Span>(span => { span.Annotations.ShouldBeEquivalentTo(expectedAnnotations); })); var actual = await transportWithTracing.SendAsync(request, timeout, cancellationToken).ConfigureAwait(false); actual.Should().Be(response); traceReporter.Received().SendSpan(Arg.Any <Span>()); }
public void BeginSpan_should_inherit_custom_field_from_whitelist() { const string customKey = "customKey"; const string customValue = "customValue"; Trace.Configuration.InheritedFieldsWhitelist.Add(customKey); traceReporter.SendSpan( Arg.Do <Span>( x => { x.Annotations.Keys.Should().Contain(customKey); x.Annotations[customKey].Should().Contain(customValue); })); using (var span = Trace.BeginSpan()) { span.SetAnnotation(customKey, customValue); using (Trace.BeginSpan()) { } } traceReporter.Received(2).SendSpan(Arg.Any <Span>()); }