public void ReceiveServerSpan_UsingToBeCleanedDomainName()
        {
            var serverServiceName = "server";
            var requestName       = fixture.Create <string>();
            var traceId           = fixture.Create <long>().ToString();
            var parentSpanId      = fixture.Create <long>().ToString();
            var spanId            = fixture.Create <long>().ToString();
            var serverUri         = new Uri("https://" + clientServiceName + ":" + port + api);

            var domain = new Uri("https://" + serverServiceName + zipkinNotToBeDisplayedDomainList.First());

            var spanTracer = new SpanTracer(spanCollectorStub, zipkinEndpointStub, zipkinNotToBeDisplayedDomainList, domain);

            var localEndpoint = new Endpoint {
                ServiceName = serverServiceName, Port = port
            };

            zipkinEndpointStub.Expect(x => x.GetLocalEndpoint(Arg.Is(serverServiceName), Arg.Is(port))).Return(localEndpoint);

            var resultSpan = spanTracer.ReceiveServerSpan(requestName, traceId, parentSpanId, spanId, serverUri);

            var annotation = resultSpan.Annotations[0] as Annotation;

            Assert.AreEqual(localEndpoint, annotation.Host);
        }
Example #2
0
        public async Task ReceiveServerSpan_InCorrectRequest_ReturnTraceSpan1()
        {
            var requestUri   = new Uri("http://server.com:999/api");
            var requestName  = "request";
            var traceId      = "traceId";
            var parentSpanId = "parentSpanId";
            var spanId       = "spanId";

            var spanCollector  = Substitute.For <ISpanCollector>();
            var zipkinEndpoint = Substitute.For <IServiceEndpoint>();
            var zipkinConfig   = new ZipkinConfig(new Uri("http://localhost"));
            var localEndpoint  = new Endpoint {
                ServiceName = "server.com", Port = 999
            };

            zipkinEndpoint.GetLocalEndpoint(null, null, 0).ReturnsForAnyArgs(localEndpoint);

            var st         = new SpanTracer(zipkinConfig, spanCollector, zipkinEndpoint);
            var trInfo     = new TraceInfo(traceId, spanId, true, false, new Uri("http://localhost"), null, parentSpanId);
            var resultSpan = await st.ReceiveServerSpan(requestName, trInfo, requestUri);

            var annotation = resultSpan.Annotations[0] as Annotation;

            Assert.AreEqual(localEndpoint, annotation.Host);
        }
        public void ReceiveServerSpan()
        {
            var serviceName = fixture.Create<string>();
            var requestName = fixture.Create<string>();
            var traceId = fixture.Create<long>().ToString();
            var parentSpanId = fixture.Create<long>().ToString();
            var spanId = fixture.Create<long>().ToString();

            var spanTracer = new SpanTracer(spanCollectorStub, serviceName, zipkinEndpointStub);

            zipkinEndpointStub.Expect(x => x.GetEndpoint(serviceName)).Return(new Endpoint() { Service_name = serviceName });

            var resultSpan = spanTracer.ReceiveServerSpan(requestName, traceId, parentSpanId, spanId);

            Assert.AreEqual(requestName, resultSpan.Name);
            Assert.AreEqual(Int64.Parse(traceId, System.Globalization.NumberStyles.HexNumber), resultSpan.Trace_id);
            Assert.AreEqual(Int64.Parse(parentSpanId, System.Globalization.NumberStyles.HexNumber), resultSpan.Parent_id);
            Assert.AreEqual(Int64.Parse(spanId, System.Globalization.NumberStyles.HexNumber), resultSpan.Id);

            Assert.AreEqual(1, resultSpan.Annotations.Count);

            var annotation = resultSpan.Annotations[0] as Annotation;
            Assert.IsNotNull(annotation);
            Assert.AreEqual(zipkinCoreConstants.SERVER_RECV, annotation.Value);
            Assert.IsNotNull(annotation.Timestamp);
            Assert.IsNotNull(annotation.Host);

            var endpoint = annotation.Host as Endpoint;
            Assert.IsNotNull(endpoint);
            Assert.AreEqual(serviceName, endpoint.Service_name);

            AssertBinaryAnnotations(resultSpan.Binary_annotations, traceId, spanId, parentSpanId);
        }
Example #4
0
        public async Task ReceiveServerSpan_InCorrectRequest_ReturnTraceSpan()
        {
            var requestUri   = new Uri("http://server.com:999/api");
            var requestName  = "request";
            var traceId      = "traceId";
            var parentSpanId = "parentSpanId";
            var spanId       = "spanId";

            var spanCollector  = Substitute.For <ISpanCollector>();
            var zipkinEndpoint = Substitute.For <IServiceEndpoint>();
            var zipkinConfig   = new ZipkinConfig(new Uri("http://localhost"));
            var localEndpoint  = new Endpoint {
                ServiceName = "server.com", Port = 999
            };

            zipkinEndpoint.GetLocalEndpoint(null, null, 0).ReturnsForAnyArgs(localEndpoint);

            var st         = new SpanTracer(zipkinConfig, spanCollector, zipkinEndpoint);
            var trInfo     = new TraceInfo(traceId, spanId, true, false, new Uri("http://localhost"), null, parentSpanId);
            var resultSpan = await st.ReceiveServerSpan(requestName, trInfo, requestUri);

            Assert.AreEqual(requestName, resultSpan.Name);
            Assert.AreEqual(traceId, resultSpan.TraceId);
            Assert.AreEqual(parentSpanId, resultSpan.ParentId);
            Assert.AreEqual(spanId, resultSpan.Id);

            Assert.AreEqual(1, resultSpan.GetAnnotationsByType <Annotation>().Count());

            var annotation = resultSpan.Annotations[0] as Annotation;

            Assert.IsNotNull(annotation);
            Assert.AreEqual(TraceKeys.ServerRecv, annotation.Value);
            Assert.IsNotNull(annotation.Timestamp);
            Assert.IsNotNull(annotation.Host);

            Assert.AreEqual(localEndpoint, annotation.Host);

            var binaryAnnotations = resultSpan.GetAnnotationsByType <BinaryAnnotation>();

            Assert.AreEqual(1, binaryAnnotations.Count());
            AssertBinaryAnnotations(binaryAnnotations, "http.path", requestUri.AbsolutePath);
        }
        public void ReceiveServerSpan()
        {
            var domain       = new Uri("http://server.com");
            var requestName  = fixture.Create <string>();
            var traceId      = fixture.Create <long>().ToString();
            var parentSpanId = fixture.Create <long>().ToString();
            var spanId       = fixture.Create <long>().ToString();
            var serverUri    = new Uri("https://" + clientServiceName + ":" + port + api);

            var spanTracer = new SpanTracer(spanCollectorStub, zipkinEndpointStub, zipkinNotToBeDisplayedDomainList, domain);

            var localEndpoint = new Endpoint {
                ServiceName = serverServiceName, Port = port
            };

            zipkinEndpointStub.Expect(x => x.GetLocalEndpoint(Arg.Is(domain.Host), Arg.Is(port))).Return(localEndpoint);

            var resultSpan = spanTracer.ReceiveServerSpan(requestName, traceId, parentSpanId, spanId, serverUri);

            Assert.AreEqual(requestName, resultSpan.Name);
            Assert.AreEqual(Int64.Parse(traceId, System.Globalization.NumberStyles.HexNumber), resultSpan.TraceId);
            Assert.AreEqual(Int64.Parse(parentSpanId, System.Globalization.NumberStyles.HexNumber), resultSpan.ParentId);
            Assert.AreEqual(Int64.Parse(spanId, System.Globalization.NumberStyles.HexNumber), resultSpan.Id);

            Assert.AreEqual(1, resultSpan.GetAnnotationsByType <Annotation>().Count());

            var annotation = resultSpan.Annotations[0] as Annotation;

            Assert.IsNotNull(annotation);
            Assert.AreEqual(ZipkinConstants.ServerReceive, annotation.Value);
            Assert.IsNotNull(annotation.Timestamp);
            Assert.IsNotNull(annotation.Host);

            Assert.AreEqual(localEndpoint, annotation.Host);

            var binaryAnnotations = resultSpan.GetAnnotationsByType <BinaryAnnotation>();

            Assert.AreEqual(1, binaryAnnotations.Count());

            AssertBinaryAnnotations(binaryAnnotations, "http.uri", serverUri.AbsolutePath);
        }
Example #6
0
        public Span StartServerTrace(Uri requestUri, string methodName)
        {
            if (!IsTraceOn)
            {
                return(null);
            }

            try
            {
                return(spanTracer.ReceiveServerSpan(
                           methodName.ToLower(),
                           TraceProvider.TraceId,
                           TraceProvider.ParentSpanId,
                           TraceProvider.SpanId,
                           requestUri));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #7
0
        public void ReceiveServerSpan()
        {
            var serviceName  = fixture.Create <string>();
            var requestName  = fixture.Create <string>();
            var traceId      = fixture.Create <long>().ToString();
            var parentSpanId = fixture.Create <long>().ToString();
            var spanId       = fixture.Create <long>().ToString();

            var spanTracer = new SpanTracer(spanCollectorStub, serviceName, zipkinEndpointStub);

            zipkinEndpointStub.Expect(x => x.GetEndpoint(serviceName)).Return(new Endpoint()
            {
                Service_name = serviceName
            });

            var resultSpan = spanTracer.ReceiveServerSpan(requestName, traceId, parentSpanId, spanId);

            Assert.AreEqual(requestName, resultSpan.Name);
            Assert.AreEqual(Int64.Parse(traceId, System.Globalization.NumberStyles.HexNumber), resultSpan.Trace_id);
            Assert.AreEqual(Int64.Parse(parentSpanId, System.Globalization.NumberStyles.HexNumber), resultSpan.Parent_id);
            Assert.AreEqual(Int64.Parse(spanId, System.Globalization.NumberStyles.HexNumber), resultSpan.Id);

            Assert.AreEqual(1, resultSpan.Annotations.Count);

            var annotation = resultSpan.Annotations[0] as Annotation;

            Assert.IsNotNull(annotation);
            Assert.AreEqual(zipkinCoreConstants.SERVER_RECV, annotation.Value);
            Assert.IsNotNull(annotation.Timestamp);
            Assert.IsNotNull(annotation.Host);

            var endpoint = annotation.Host as Endpoint;

            Assert.IsNotNull(endpoint);
            Assert.AreEqual(serviceName, endpoint.Service_name);

            AssertBinaryAnnotations(resultSpan.Binary_annotations, traceId, spanId, parentSpanId);
        }