private ITracerClient SetupZipkinClient(IZipkinConfig zipkinConfig = null)
        {
            spanCollectorStub = MockRepository.GenerateStub <SpanCollector>(new Uri("http://localhost"), (uint)0, logger);

            traceProvider.Stub(x => x.TraceId).Return(fixture.Create <string>());
            traceProvider.Stub(x => x.SpanId).Return(fixture.Create <string>());
            traceProvider.Stub(x => x.ParentSpanId).Return(fixture.Create <string>());
            traceProvider.Stub(x => x.IsSampled).Return(true);

            var context = MockRepository.GenerateStub <IOwinContext>();
            var request = MockRepository.GenerateStub <IOwinRequest>();

            context.Stub(x => x.Request).Return(request);
            context.Stub(x => x.Environment).Return(new Dictionary <string, object> {
                { TraceProvider.Key, traceProvider }
            });

            IZipkinConfig zipkinConfigSetup = zipkinConfig;

            if (zipkinConfig == null)
            {
                zipkinConfigSetup = CreateZipkinConfigWithDefaultValues();
            }

            return(new ZipkinClient(logger, zipkinConfigSetup, context, spanCollectorStub));
        }
Beispiel #2
0
        public void CTOR_initializesSpanCollector()
        {
            SpanCollector.spanQueue = null;

            spanCollector = new SpanCollector(new Uri("http://localhost"), 0);

            Assert.IsNotNull(SpanCollector.spanQueue);
        }
Beispiel #3
0
        public void GetInstance()
        {
            SpanCollector.spanQueue = null;

            spanCollector = SpanCollector.GetInstance(new Uri("http://localhost"), 0, logger);

            Assert.IsNotNull(SpanCollector.spanQueue);
        }
Beispiel #4
0
 public MockTracerAgent(int port)
 {
     _listener = new HttpListener();
     _listener.Prefixes.Add($"http://localhost:{port}/");
     _listener.Start();
     _collector = new SpanCollector(_listener);
     Port       = port;
 }
        public void CTOR_initializesSpanCollector()
        {
            SpanCollector.spanQueue = null;

            clientProviderStub = MockRepository.GenerateStub<IClientProvider>();
            spanCollector = new SpanCollector(clientProviderStub, 0);

            Assert.IsNotNull(SpanCollector.spanQueue);
        }
Beispiel #6
0
        public void Collect_NullSpan_NotCollect()
        {
            var collection = new BlockingCollection <Span>();
            var collector  = new SpanCollector(collection);

            collector.Collect(null);

            Assert.AreEqual(collection.Count, 0);
        }
Beispiel #7
0
        private void SetupSpanCollector()
        {
            spanCollector = new SpanCollector(new Uri("http://localhost"), 0);

            SpanCollector.spanQueue = fixture.Create <BlockingCollection <Span> >();
            spanProcessorStub       = MockRepository.GenerateStub <SpanProcessor>(new Uri("http://localhost"),
                                                                                  SpanCollector.spanQueue, (uint)0);
            spanCollector.spanProcessor = spanProcessorStub;
        }
        public void CTOR_initializesSpanCollector()
        {
            SpanCollector.spanQueue = null;

            clientProviderStub = MockRepository.GenerateStub <IClientProvider>();
            spanCollector      = new SpanCollector(clientProviderStub, 0);

            Assert.IsNotNull(SpanCollector.spanQueue);
        }
        private void SetupSpanCollector()
        {
            clientProviderStub = MockRepository.GenerateStub <IClientProvider>();
            spanCollector      = new SpanCollector(clientProviderStub, 0);

            SpanCollector.spanQueue     = fixture.Create <BlockingCollection <Span> >();
            spanProcessorStub           = MockRepository.GenerateStub <SpanProcessor>(SpanCollector.spanQueue, clientProviderStub, 0);
            spanCollector.spanProcessor = spanProcessorStub;
        }
Beispiel #10
0
        static SpanCollector GetInstance(Uri uri, uint maxProcessorBatchSize)
        {
            TaskHelper.Execute(syncObj, () => instance == null,
                               () =>
            {
                instance = new SpanCollector(uri, maxProcessorBatchSize);
            });

            return(instance);
        }
        public void CTOR_doesntReinitializeSpanCollector()
        {
            var spanQueue = new BlockingCollection<Span>();
            SpanCollector.spanQueue = spanQueue;

            clientProviderStub = MockRepository.GenerateStub<IClientProvider>();
            spanCollector = new SpanCollector(clientProviderStub, 0);

            Assert.IsTrue(System.Object.ReferenceEquals(SpanCollector.spanQueue, spanQueue));
        }
Beispiel #12
0
        public void CTOR_doesntReinitializeSpanCollector()
        {
            var spanQueue = new BlockingCollection <Span>();

            SpanCollector.spanQueue = spanQueue;

            spanCollector = new SpanCollector(new Uri("http://localhost"), 0);

            Assert.IsTrue(System.Object.ReferenceEquals(SpanCollector.spanQueue, spanQueue));
        }
        private ITracerClient SetupZipkinClient()
        {
            spanCollectorStub = MockRepository.GenerateStub <SpanCollector>(MockRepository.GenerateStub <IClientProvider>(), 0);
            spanCollectorBuilder.Expect(x => x.Build(Arg <string> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything)).Return(spanCollectorStub);

            traceProvider.Expect(x => x.TraceId).Return(fixture.Create <string>());
            traceProvider.Expect(x => x.IsSampled).Return(true);

            return(new ZipkinClient(traceProvider, requestName, logger, CreateZipkinConfigWithDefaultValues(), spanCollectorBuilder));
        }
        public MockTracerAgent()
        {
            _listener = new HttpListener();
            _listener.Prefixes.Add("http://localhost:9696/");
            _listener.Start();
            _collector = new SpanCollector(_listener);

            Environment.SetEnvironmentVariable("DD_TRACE_AGENT_HOSTNAME", "localhost");
            Environment.SetEnvironmentVariable("DD_TRACE_AGENT_PORT", "9696");
        }
        public void CTOR_doesntReinitializeSpanCollector()
        {
            var spanQueue = new BlockingCollection <Span>();

            SpanCollector.spanQueue = spanQueue;

            clientProviderStub = MockRepository.GenerateStub <IClientProvider>();
            spanCollector      = new SpanCollector(clientProviderStub, 0);

            Assert.IsTrue(System.Object.ReferenceEquals(SpanCollector.spanQueue, spanQueue));
        }
Beispiel #16
0
        public void Collect_NewSpan_AddedToCollection()
        {
            var collection = new BlockingCollection <Span>();
            var collector  = new SpanCollector(collection);

            var traceInfo = new TraceInfo(string.Empty, string.Empty, true, false, null, IPAddress.Loopback);

            collector.Collect(new Span(string.Empty, traceInfo));

            Assert.AreEqual(collection.Count, 1);
        }
Beispiel #17
0
        public void TryTake_EmptyCollection_NotReturnSpan()
        {
            var collection = new BlockingCollection <Span>();
            var collector  = new SpanCollector(collection);

            Span span;
            var  ret = collector.TryTake(out span);

            Assert.IsFalse(ret);
            Assert.IsNull(span);
        }
        public void CTOR_WithNullLogger()
        {
            var zipkinConfigStub = CreateZipkinConfigWithValues(fixture.Create <string>(), "123", "123", fixture.Create <string>(), "goo,bar", "0.5");

            spanCollectorStub = MockRepository.GenerateStub <SpanCollector>(MockRepository.GenerateStub <IClientProvider>(), 0);
            spanCollectorBuilder.Expect(x => x.Build(Arg <string> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything)).Return(spanCollectorStub);

            var zipkinClient = new ZipkinClient(traceProvider, requestName, logger, zipkinConfigStub, spanCollectorBuilder);

            Assert.IsFalse(zipkinClient.isTraceOn);
        }
        public void CTOR_WithNullTraceProvider()
        {
            var zipkinConfigStub = CreateZipkinConfigWithDefaultValues();

            spanCollectorStub = MockRepository.GenerateStub <SpanCollector>(MockRepository.GenerateStub <IClientProvider>(), 0);
            spanCollectorBuilder.Expect(x => x.Build(Arg <string> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything)).Return(spanCollectorStub);
            var zipkinClient = new ZipkinClient(null, requestName, logger, zipkinConfigStub, spanCollectorBuilder);

            Assert.IsFalse(zipkinClient.isTraceOn);
            logger.AssertWasCalled(x => x.Error(Arg <string> .Is.Anything));
        }
Beispiel #20
0
        public void CTOR_WithTraceIdNullOrEmpty()
        {
            var zipkinConfigStub = CreateZipkinConfigWithDefaultValues();

            AddTraceId(string.Empty);
            AddSampled(false);

            spanCollectorStub = MockRepository.GenerateStub <SpanCollector>(new Uri("http://localhost"), (uint)0);
            var zipkinClient = new ZipkinClient(zipkinConfigStub, owinContext, spanCollectorStub);

            Assert.IsFalse(zipkinClient.IsTraceOn);
        }
        public void CTOR_WithIsSampledFalse()
        {
            var zipkinConfigStub = CreateZipkinConfigWithDefaultValues();

            AddTraceId(fixture.Create <string>());
            AddSampled(false);

            spanCollectorStub = MockRepository.GenerateStub <SpanCollector>(new Uri("http://localhost"), (uint)0, logger);
            var zipkinClient = new ZipkinClient(logger, zipkinConfigStub, owinContext, spanCollectorStub);

            Assert.IsFalse(zipkinClient.IsTraceOn);
        }
        public void CTOR_WithNullWhiteListCsv()
        {
            traceProvider.Expect(x => x.TraceId).Return(fixture.Create <string>());
            traceProvider.Expect(x => x.IsSampled).Return(true);

            var zipkinConfigStub = CreateZipkinConfigWithValues(fixture.Create <string>(), "123", "123", fixture.Create <string>(), null, "0.5");

            spanCollectorStub = MockRepository.GenerateStub <SpanCollector>(MockRepository.GenerateStub <IClientProvider>(), 0);
            spanCollectorBuilder.Expect(x => x.Build(Arg <string> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything)).Return(spanCollectorStub);
            var zipkinClient = new ZipkinClient(traceProvider, requestName, logger, zipkinConfigStub, spanCollectorBuilder);

            Assert.IsTrue(zipkinClient.isTraceOn);
        }
        public void CTOR_WithIsSampledFalse()
        {
            var zipkinConfigStub = CreateZipkinConfigWithDefaultValues();

            traceProvider.Expect(x => x.TraceId).Return(fixture.Create <string>());
            traceProvider.Expect(x => x.IsSampled).Return(false);

            spanCollectorStub = MockRepository.GenerateStub <SpanCollector>(MockRepository.GenerateStub <IClientProvider>(), 0);
            spanCollectorBuilder.Expect(x => x.Build(Arg <string> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything)).Return(spanCollectorStub);
            var zipkinClient = new ZipkinClient(traceProvider, requestName, logger, zipkinConfigStub, spanCollectorBuilder);

            Assert.IsFalse(zipkinClient.isTraceOn);
        }
 public void Init()
 {
     fixture            = new Fixture();
     logger             = MockRepository.GenerateStub <ILog>();
     spanCollectorStub  = MockRepository.GenerateStub <SpanCollector>(new Uri("http://localhost"), (uint)0, logger);
     zipkinEndpointStub = MockRepository.GenerateStub <ServiceEndpoint>();
     zipkinNotToBeDisplayedDomainList = new List <string> {
         ".xyz.net"
     };
     serverServiceName = "xyz-sandbox";
     clientServiceName = "abc-sandbox";
     port = 42;
     api  = "/api/method1";
 }
Beispiel #25
0
        public void TryTake_NotEmptyCollection_ReturnSpan()
        {
            var traceInfo = new TraceInfo(string.Empty, "TestSpanId", true, false, null, IPAddress.Loopback);
            var span      = new Span(string.Empty, traceInfo);

            var collection = new BlockingCollection <Span>();
            var collector  = new SpanCollector(collection);

            collection.Add(span);

            Span spanTaken;
            var  ret = collector.TryTake(out spanTaken);

            Assert.IsTrue(ret);
            Assert.AreSame(spanTaken, span);
        }
Beispiel #26
0
        public void TryTake_NotEmptyCollection_ClearCollection()
        {
            var traceInfo  = new TraceInfo(string.Empty, "TestSpanId", true, false, null, IPAddress.Loopback);
            var span       = new Span(string.Empty, traceInfo);
            var collection = new BlockingCollection <Span>();
            var collector  = new SpanCollector(collection);

            collection.Add(span);

            Assert.AreEqual(collection.Count, 1);

            Span spanTaken;

            collector.TryTake(out spanTaken);

            Assert.AreEqual(collection.Count, 0);
        }
Beispiel #27
0
        public ZipkinClient(IZipkinConfig zipkinConfig, HttpContext context, SpanCollector collector = null)
        {
            if (zipkinConfig == null)
            {
                throw new ArgumentNullException(nameof(zipkinConfig));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var traceProvider = new TraceProvider(zipkinConfig, context);

            IsTraceOn = !zipkinConfig.Bypass(context.Request) && IsTraceProviderSamplingOn(traceProvider);

            if (!IsTraceOn)
            {
                return;
            }

            zipkinConfig.Validate();
            ZipkinConfig = zipkinConfig;
            try
            {
                spanCollector = collector ?? GetInstance(
                    zipkinConfig.ZipkinBaseUri,
                    zipkinConfig.SpanProcessorBatchSize);

                spanCollector.Start();

                spanTracer = new SpanTracer(
                    spanCollector,
                    new ServiceEndpoint(),
                    zipkinConfig.NotToBeDisplayedDomainList,
                    zipkinConfig.Domain(context.Request));

                TraceProvider = traceProvider;
            }
            catch (Exception ex)
            {
                IsTraceOn = false;
            }
        }
        private void SetupSpanCollector()
        {
            clientProviderStub = MockRepository.GenerateStub<IClientProvider>();
            spanCollector = new SpanCollector(clientProviderStub, 0);

            SpanCollector.spanQueue = fixture.Create<BlockingCollection<Span>>();
            spanProcessorStub = MockRepository.GenerateStub<SpanProcessor>(SpanCollector.spanQueue, clientProviderStub, 0);
            spanCollector.spanProcessor = spanProcessorStub;
        }
Beispiel #29
0
 public void Init()
 {
     fixture            = new Fixture();
     spanCollectorStub  = MockRepository.GenerateStub <SpanCollector>(MockRepository.GenerateStub <IClientProvider>(), 0);
     zipkinEndpointStub = MockRepository.GenerateStub <ServiceEndpoint>();
 }