Пример #1
0
        public async Task StartServerTrace_WithoutMethodName_ReturnNullSpan()
        {
            var zipkinConfig      = new ZipkinConfig(new Uri("http://localhost"));
            var traceInfoAccessor = Substitute.For <ITraceInfoAccessor>();
            var spanTracer        = Substitute.For <ISpanTracer>();
            var logger            = Substitute.For <ILogger <ZipkinClient> >();

            var traceInfo = new TraceInfo("traceId", string.Empty, true, false, null, null, string.Empty);

            var zipkinClient = new ZipkinClient(zipkinConfig, traceInfoAccessor, spanTracer, logger);

            Assert.IsNull(await zipkinClient.StartServerTrace(null, null, traceInfo));
            Assert.IsNull(await zipkinClient.StartServerTrace(new Uri("http://localhost"), null, traceInfo));
        }
Пример #2
0
        public void Init(HttpApplication context)
        {
            context.BeginRequest += (sender, args) =>
            {
                string url = HttpContext.Current.Request.Path;

                var zipkinConfig = new ZipkinConfig();

                var traceProvider = new TraceProvider(new System.Web.HttpContextWrapper(HttpContext.Current), zipkinConfig.DontSampleListCsv, zipkinConfig.ZipkinSampleRate);
                var logger        = new MDLogger(LogManager.GetLogger(this.GetType()), traceProvider, new AssemblyInformation());

                ITracerClient zipkinClient = new ZipkinClient(traceProvider, url, logger);

                zipkinClient.StartServerTrace();

                HttpContext.Current.Items["zipkinClient"] = zipkinClient;

                var stopwatch = new Stopwatch();
                HttpContext.Current.Items["zipkinStopwatch"] = stopwatch;
                stopwatch.Start();
            };

            context.EndRequest += (sender, args) =>
            {
                var stopwatch = (Stopwatch)HttpContext.Current.Items["zipkinStopwatch"];
                stopwatch.Stop();

                var zipkinClient = (ITracerClient)HttpContext.Current.Items["zipkinClient"];

                zipkinClient.EndServerTrace(stopwatch.Elapsed.Milliseconds * 1000);
            };
        }
Пример #3
0
        private void Application_BeginRequest(Object source,
                                              EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext     context     = application.Context;
            Span            span        = _client.StartServerTrace(context.Request.Url, context.Request.HttpMethod);

            context.Items.Add("span", span);
        }
        public override async Task Invoke(IOwinContext context)
        {
            if (_config.Bypass != null && _config.Bypass(context.Request))
            {
                await Next.Invoke(context);

                return;
            }

            var zipkin = new ZipkinClient(_config, context);
            var span   = zipkin.StartServerTrace(context.Request.Uri, context.Request.Method);
            await Next.Invoke(context);

            zipkin.EndServerTrace(span);
        }
Пример #5
0
        public void StartServerTrace_WithSpanTracerException_DoesntThrow()
        {
            var zipkinConfig      = new ZipkinConfig(new Uri("http://localhost"));
            var traceInfoAccessor = Substitute.For <ITraceInfoAccessor>();
            var spanTracer        = Substitute.For <ISpanTracer>();
            var logger            = Substitute.For <ILogger <ZipkinClient> >();

            var traceInfo = new TraceInfo("traceId", string.Empty, true, false, null, null, string.Empty);

            spanTracer.WhenForAnyArgs(x => x.ReceiveServerSpan(null, null, null)).Throw <Exception>();

            var zipkinClient = new ZipkinClient(zipkinConfig, traceInfoAccessor, spanTracer, logger);

            Assert.DoesNotThrowAsync(() => zipkinClient.StartServerTrace(new Uri("http://localhost"), "POST", traceInfo));
        }
Пример #6
0
        public async Task StartServerTrace_WithTraceOn_ReceiveSpan()
        {
            var traceInfo         = new TraceInfo(string.Empty, string.Empty, true, false, new Uri("http://localhost"), null);
            var span              = new Span("span", traceInfo);
            var zipkinConfig      = new ZipkinConfig(new Uri("http://localhost"));
            var traceInfoAccessor = Substitute.For <ITraceInfoAccessor>();
            var spanTracer        = Substitute.For <ISpanTracer>();
            var logger            = Substitute.For <ILogger <ZipkinClient> >();

            var traceInfoServer = new TraceInfo("traceId", string.Empty, true, false, null, null, string.Empty);

            spanTracer.ReceiveServerSpan(null, null, null).ReturnsForAnyArgs(span);

            var zipkinClient = new ZipkinClient(zipkinConfig, traceInfoAccessor, spanTracer, logger);

            Assert.AreSame(await zipkinClient.StartServerTrace(new Uri("http://localhost"), "POST", traceInfoServer), span);
        }