Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IConfiguration Configuration)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var applicationName = Configuration.GetValue <string>("applicationName");

            var lifetime = app.ApplicationServices.GetService <IApplicationLifetime>();

            lifetime.ApplicationStarted.Register(() => {
                TraceManager.SamplingRate = 1.0f;
                var logger     = new TracingLogger(loggerFactory, "zipkin4net");
                var httpSender = new HttpZipkinSender("http://localhost:9411", "application/json");
                var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());
                TraceManager.RegisterTracer(tracer);
                TraceManager.Start(logger);
            });

            lifetime.ApplicationStopped.Register(() => TraceManager.Stop());
            app.UseTracing(applicationName);

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Пример #2
0
        public void Configuration(IAppBuilder appBuilder)
        {
            //Setup tracing
            TraceManager.SamplingRate = 1.0f;
            var logger     = new ConsoleLogger();
            var httpSender = new HttpZipkinSender("http://localhost:9411", "application/json");
            var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());

            TraceManager.RegisterTracer(tracer);
            TraceManager.Start(logger);
            //

            //Stop TraceManager on app dispose
            var properties = new AppProperties(appBuilder.Properties);
            var token      = properties.OnAppDisposing;

            if (token != CancellationToken.None)
            {
                token.Register(() =>
                {
                    TraceManager.Stop();
                });
            }
            //

            // Setup Owin Middleware
            appBuilder.UseZipkinTracer(System.Configuration.ConfigurationManager.AppSettings["applicationName"]);
            //

            appBuilder.Run(RunHandler);
        }
Пример #3
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            // Zipkin Configuration

            var zipkinHttpClient = new HttpClient(new SetOtIgnoreHandler
            {
                InnerHandler = new HttpClientHandler()
            });

            var zipkinSender = new HttpZipkinSender(zipkinHttpClient, "http://localhost:9411", "application/json");
            var zipkinTracer = new ZipkinTracer(zipkinSender, new JSONSpanSerializer(), new Statistics());

            TraceManager.SamplingRate = 1.0f;

            TraceManager.RegisterTracer(zipkinTracer);
            TraceManager.Start(this);

            // OpenTracing -> Zipkin Configuration

            string serviceName = Assembly.GetEntryAssembly().GetName().Name;
            var    otTracer    = new OtTracer(
                serviceName,
                new AsyncLocalScopeManager(),
                Propagations.B3String);

            GlobalTracer.Register(otTracer);

            return(Task.CompletedTask);
        }
Пример #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            var config = ConfigureSettings.CreateConfiguration();

            loggerFactory.AddConsole();

            app.UseCors("CorsPolicy");
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var         lifetime   = app.ApplicationServices.GetService <IApplicationLifetime> ();
            IStatistics statistics = new Statistics();

            lifetime.ApplicationStarted.Register(() => {
                TraceManager.SamplingRate = 1.0f;
                var logger     = new TracingLogger(loggerFactory, "zipkin4net");
                var httpSender = new HttpZipkinSender("http://localhost:9411", "application/json");
                var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer(), statistics);
                TraceManager.RegisterTracer(tracer);
                TraceManager.Start(logger);
            });

            lifetime.ApplicationStopped.Register(() => TraceManager.Stop());
            app.UseTracing("userdetailsService");
            // Run (app, config);
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            var config = ConfigureSettings.AppSettingConfig;

            var applicationName = config["applicationName"];
            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}
            //else
            //{
            //    app.UseExceptionHandler("/Home/Error");
            //    app.UseHsts();
            //}
            var lifetime = app.ApplicationServices.GetService <IApplicationLifetime>();

            lifetime.ApplicationStarted.Register(() =>
            {
                TraceManager.SamplingRate = 1.0f;
                var logger     = new TracingLogger(loggerFactory, "zipkin4net");
                var httpSender = new HttpZipkinSender(ConfigEx.zipkinAddr, "application/json");
                var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());
                TraceManager.RegisterTracer(tracer);
                TraceManager.Start(logger);
            });
            lifetime.ApplicationStopped.Register(() => TraceManager.Stop());
            //监控名称。
            app.UseTracing(applicationName);
            Run(app, config);
        }
Пример #6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            var config = ConfigureSettings.CreateConfiguration();

            var applicationName = config["applicationName"];

            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var lifetime = app.ApplicationServices.GetService <IApplicationLifetime>();

            lifetime.ApplicationStarted.Register(() => {
                TraceManager.SamplingRate = 1.0f;
                var logger     = new TracingLogger(loggerFactory, "Criteo.Profiling.Tracing");
                var httpSender = new HttpZipkinSender("http://localhost:9411", "application/json");
                var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());
                TraceManager.RegisterTracer(tracer);
                TraceManager.Start(logger);
            });
            lifetime.ApplicationStopped.Register(() => TraceManager.Stop());
            app.UseTracing(applicationName);
            Run(app, config);
        }
Пример #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            var         lifetime   = app.ApplicationServices.GetService <IApplicationLifetime> ();
            IStatistics statistics = new Statistics();

            lifetime.ApplicationStarted.Register(() => {
                TraceManager.SamplingRate = 1.0f;
                var logger                = new TracingLogger(loggerFactory, "zipkin4net");
                var httpSender            = new HttpZipkinSender(Configuration.GetConnectionString("Zipkin"), "application/json");
                var tracer                = new ZipkinTracer(httpSender, new JSONSpanSerializer(), statistics);
                TraceManager.Trace128Bits = true;
                TraceManager.RegisterTracer(tracer);
                TraceManager.Start(logger);
            });

            lifetime.ApplicationStopped.Register(() => TraceManager.Stop());
            app.UseTracing("report");

            app.UseMvc();
        }
Пример #8
0
 /// <summary>
 /// 向ZipKin服务器注册服务管道
 /// <paramref name="loggerFactory"/>
 /// <paramref name="strZipKinServerUrl">默认本机:http://localhost:9411</paramref>
 /// </summary>
 public static ResponseData <string> RegisterHandle(ILoggerFactory loggerFactory)
 {
     #region RegisterService
     try
     {
         TraceManager.SamplingRate = 1.0f;
         var logger     = new TracingLogger(loggerFactory, "zipkin4net");
         var httpSender = new HttpZipkinSender(ZipKinServerUrl, "application/json");
         var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());
         TraceManager.RegisterTracer(tracer);
         TraceManager.Start(logger);
         return(new ResponseData <string>
         {
             Code = "200",
             Messages = "Success",
             Data = "注册完成"
         });
     }
     catch (Exception ex)
     {
         return(new ResponseData <string>
         {
             Data = "注册失败",
             Code = "-100",
             Messages = ex.Message
         });
     }
     #endregion
 }
Пример #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            var applicationName = "car-loan";

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var zipkinEndpoint = Environment.GetEnvironmentVariable("PROXY_ENDPOINT") + ":9411";

            var lifetime = app.ApplicationServices.GetService <Microsoft.AspNetCore.Hosting.IApplicationLifetime>();

            lifetime.ApplicationStarted.Register(() => {
                TraceManager.SamplingRate = 1.0f;
                var logger     = new TracingLogger(loggerFactory, "zipkin4net");
                var httpSender = new HttpZipkinSender(zipkinEndpoint, "application/json");
                var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());
                TraceManager.RegisterTracer(tracer);
                TraceManager.Start(logger);
            });
            lifetime.ApplicationStopped.Register(() => TraceManager.Stop());

            app.UseTracing(applicationName);

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Пример #10
0
        public ZipkinTracer(Uri collectorUri)
        {
            if (collectorUri == null)
            {
                throw new ArgumentNullException(nameof(collectorUri));
            }

            IZipkinSender   sender;
            ISpanSerializer serializer;

            if (collectorUri.Scheme == "http" || collectorUri.Scheme == "https")
            {
                sender     = new HttpZipkinSender(collectorUri.AbsoluteUri, "application/json");
                serializer = new JSONSpanSerializer();
            }
            else
            {
                throw new ArgumentException("Unrecognized Zipkin endpoint", nameof(collectorUri));
            }

            TraceManager.SamplingRate = 1.0f;
            TraceManager.Trace128Bits = true;
            var tracer = new zipkin4net.Tracers.Zipkin.ZipkinTracer(sender, serializer, new Statistics());

            TraceManager.RegisterTracer(tracer);
            TraceManager.Start(new NullLogger());
        }
Пример #11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
            var appName   = this.Configuration["applicationName"];
            var zipkinUrl = this.Configuration["zipkinUrl"];

            if (!string.IsNullOrWhiteSpace(zipkinUrl))
            {
                var lifetime = app.ApplicationServices.GetService <IApplicationLifetime>();
                lifetime.ApplicationStarted.Register(
                    () =>
                {
                    TraceManager.SamplingRate = 1.0f;
                    var logger     = new TracingLogger(loggerFactory, "zipkin4net");
                    var httpSender = new HttpZipkinSender("http://localhost:9411", "application/json");
                    var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());
                    TraceManager.RegisterTracer(tracer);
                    TraceManager.Start(logger);
                });
                lifetime.ApplicationStopped.Register(() => TraceManager.Stop());
                app.UseTracing(appName);
            }
        }
        public void Start()
        {
            // Zipkin Configuration

            var zipkinHttpClient = new HttpClient(new SetOtIgnoreHandler
            {
                InnerHandler = new HttpClientHandler()
            });

            var zipkinSender = new HttpZipkinSender(zipkinHttpClient, "http://localhost:9411", "application/json");
            var zipkinTracer = new ZipkinTracer(zipkinSender, new JSONSpanSerializer());

            TraceManager.SamplingRate = 1.0f;

            TraceManager.RegisterTracer(zipkinTracer);
            TraceManager.Start(this);

            // OpenTracing -> Zipkin Configuration

            string serviceName = Assembly.GetEntryAssembly().GetName().Name;
            var    otTracer    = new OtTracer(
                serviceName,
                new AsyncLocalScopeManager(),
                new ZipkinHttpTraceInjector(),
                new ZipkinHttpTraceExtractor());

            GlobalTracer.Register(otTracer);
        }
Пример #13
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            var         lifetime   = app.ApplicationServices.GetService <Microsoft.Extensions.Hosting.IHostApplicationLifetime>();
            IStatistics statistics = new Statistics();

            lifetime.ApplicationStarted.Register(() =>
            {
                TraceManager.SamplingRate = 1.0f;
                var logger     = new TracingLogger(loggerFactory, "zipkin4net");
                var httpSender = new HttpZipkinSender(Configuration.GetSection("OpenTelemetry:Zipkin:HttpZipkinSender").Get <string>(), "application/json");
                var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer(), statistics);
                TraceManager.RegisterTracer(tracer);
                TraceManager.Start(logger);
            });
            lifetime.ApplicationStopped.Register(() => TraceManager.Stop());
            app.UseTracing(Configuration.GetSection("OpenTelemetry:Zipkin:ServiceName").Get <string>());
        }
Пример #14
0
        public void RegisterZipkinService(IApplicationBuilder app,
                                          ILoggerFactory loggerFactory,
                                          IApplicationLifetime lifetime)
        {
            lifetime.ApplicationStarted.Register(() =>
            {
                //记录数据密度,1.0代表全部记录
                TraceManager.SamplingRate = 1.0f;
                //数据保存到内存
                var logger     = new TracingLogger(loggerFactory, "zipkin4net");
                var httpSender = new HttpZipkinSender("http://localhost:9411", "application/json");
                var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer(), new Statistics());

                var consoleTracer = new ConsoleTracer();
                TraceManager.RegisterTracer(tracer);
                TraceManager.RegisterTracer(consoleTracer);
                TraceManager.Start(logger);
            });

            lifetime.ApplicationStopped.Register(() =>
            {
                TraceManager.Stop();
            });
            app.UseTracing("contact_api");
        }
Пример #15
0
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
            var sender = new HttpZipkinSender("http://localhost:9411", "application/json");
            var tracer = new ZipkinTracer(sender, new JSONSpanSerializer());

            TraceManager.RegisterTracer(tracer);
        }
Пример #16
0
        public static void StartZipkin(string zipkinServer)
        {
            TraceManager.SamplingRate = 1.0f;
            var httpSender = new HttpZipkinSender(zipkinServer, "application/json");
            var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());

            TraceManager.RegisterTracer(tracer);
            TraceManager.Start(new ZipkinConsoleLogger());
        }
Пример #17
0
        private static ITracer ConfigureTracer(string connection)
        {
            IStatistics statistics = new Statistics();

            TraceManager.SamplingRate = 1.0f;
            var httpSender = new HttpZipkinSender(connection, "application/json");

            return(new ZipkinTracer(httpSender, new JSONSpanSerializer(), statistics));
        }
Пример #18
0
        public void sendDataShouldNotAddASlashIfAlreadyPresent()
        {
            var url    = "http://localhost/";
            var sender = new HttpZipkinSender(httpClient, url, contentType);

            sender.Send(content);
            mockMessageHandler.Verify(h => h.Send(It.Is <HttpRequestMessage>(
                                                      m => m.RequestUri.Equals(url + "api/v1/spans")
                                                      )));
        }
        private void InitialiseZipkinSetup()
        {
            TraceManager.SamplingRate = 1.0f;
            var logger     = new TracingRestClient.Logger();
            var httpSender = new HttpZipkinSender(zipkinServerName, "application/json");
            var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());

            TraceManager.RegisterTracer(tracer);
            TraceManager.Start(logger);
        }
Пример #20
0
        public Task InitializeAsync()
        {
            TraceManager.SamplingRate = _options.Rate;

            var httpSender = new HttpZipkinSender(_options.TraceEndpoint, "application/json");
            var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer(), new Statistics());

            TraceManager.RegisterTracer(tracer);

            return(Task.CompletedTask);
        }
Пример #21
0
        /// <summary>
        /// Initialize TraceManager with Tracer- holds Zipkin Server configuration like server URL, trace data format, Sampling rate.
        /// </summary>
        public static void InitializeTraceConfig(String zipkinServerUrl)
        {
            ILogger       logger   = new MyLogger();
            IZipkinSender zkSender = new HttpZipkinSender(zipkinServerUrl, "application/json");

            //1.0 implies full tracing without sampling ie., records all traces.
            TraceManager.SamplingRate = 1.0f;
            var tracer = new ZipkinTracer(zkSender, new JSONSpanSerializer());

            TraceManager.RegisterTracer(tracer);
            TraceManager.Start(logger);
        }
Пример #22
0
        public void sendDataShouldSendOnSpansEndPoint()
        {
            var contentType = "application/x-thrift";
            var sender      = new HttpZipkinSender(httpClient, url, contentType);

            sender.Send(content);
            mockMessageHandler.Verify(h => h.Send(It.Is <HttpRequestMessage>(
                                                      m => m.RequestUri.Equals(url + "/api/v1/spans") &&
                                                      m.Content.Headers.GetValues("Content-Type").Contains(contentType) &&
                                                      m.Content.Headers.GetValues("Content-Length").Contains(content.Length.ToString()) &&
                                                      m.Method == HttpMethod.Post
                                                      )));
        }
Пример #23
0
        private void StartZipkinTracer()
        {
            var zipkinCollector = Configuration.GetValue <string>("Zipkin:Collector");

            var logger     = new TracingLogger(LoggerFactory, "zipkin4net");
            var httpSender = new HttpZipkinSender(zipkinCollector, "application/json");
            var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer(), new Statistics());

            TraceManager.SamplingRate = 1.0f;
            TraceManager.RegisterTracer(tracer);

            TraceManager.Start(logger);
        }
Пример #24
0
        private void RegisterZipkinTrace()
        {
            TraceManager.SamplingRate = 1.0f;
            var loggerFactory = GlobalObject.App.ApplicationServices.GetService <ILoggerFactory>();
            var logger        = new TracingLogger(loggerFactory, "zipkin4net");
            var httpSender    = new HttpZipkinSender("http://47.97.126.205:9411", "application/json");
            var tracer        = new ZipkinTracer(httpSender, new JSONSpanSerializer(), new Statistics());
            var consoleTracer = new ConsoleTracer();

            TraceManager.RegisterTracer(tracer);
            TraceManager.RegisterTracer(consoleTracer);
            TraceManager.Start(logger);
        }
Пример #25
0
        public void Start()
        {
            var configOfZipkin = _appConfigurationManager.GetConfig <AppConfigOfZipkin>();

            TraceManager.SamplingRate = 1.0f;
            _loggerFactory.AddConsole();
            var logger     = new TracingLogger(_loggerFactory, "zipkin4net");
            var httpSender = new HttpZipkinSender(configOfZipkin.Address, "application/json");
            var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());

            TraceManager.RegisterTracer(tracer);
            TraceManager.Start(logger);
        }
Пример #26
0
        /// <summary>
        /// 启用zipkin中间件
        /// </summary>
        /// <param name="app"></param>
        /// <param name="servierName">收集日志(服务名称)</param>
        /// <param name="zipkinUri">Zpikin 地址</param>
        /// <param name="loggerName">日志名称</param>
        /// <returns></returns>
        public static IApplicationBuilder UserZipKin(this IApplicationBuilder app, ILoggerFactory loggerFactory,
                                                     string servierName, string zipkinUri, string loggerName, float logpercent = 1)
        {
            var applicationLife = app.ApplicationServices.GetService <IApplicationLifetime>();

            if (applicationLife == null)
            {
                throw new ArgumentNullException(nameof(applicationLife));
            }

            if (string.IsNullOrWhiteSpace(servierName))
            {
                throw new ArgumentNullException(nameof(servierName));
            }
            if (string.IsNullOrWhiteSpace(zipkinUri))
            {
                throw new ArgumentNullException(nameof(zipkinUri));
            }
            if (string.IsNullOrWhiteSpace(loggerName))
            {
                throw new ArgumentNullException(nameof(loggerName));
            }

            //服务启动时候注入zipkin
            applicationLife.ApplicationStarted.Register(() =>
            {
                //收集日志比例
                TraceManager.SamplingRate = logpercent;

                var logger = new TracingLogger(loggerFactory, loggerName);

                //配置zipkin 服务器地址
                var httpSender = new HttpZipkinSender(zipkinUri, "application/json");

                //追踪器
                var tracer = new ZipkinTracer(httpSender, new JSONSpanSerializer(), new Statistics());

                //控制台追踪器
                var consoleTracer = new zipkin4net.Tracers.ConsoleTracer();
                TraceManager.RegisterTracer(tracer);
                TraceManager.RegisterTracer(consoleTracer);
                TraceManager.Start(logger);
            });

            applicationLife.ApplicationStopped.Register(() =>
            {
                TraceManager.Stop();
            });
            app.UseTracing(servierName);
            return(app);
        }
Пример #27
0
 public static void RegisterZipkin(this IApplicationBuilder app, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory)
 {
     applicationLifetime.ApplicationStarted.Register(() =>
     {
         TraceManager.SamplingRate = 1.0f;                                                          //记录数据密度,1.0表示全部记录
         var logger     = new TracingLogger(loggerFactory, "zipkin4net");
         var httpsender = new HttpZipkinSender("http://localhost:9411", "application/json");        //服务器地址
         var tracer     = new ZipkinTracer(httpsender, new JSONSpanSerializer(), new Statistics()); //注册zipkin
         TraceManager.RegisterTracer(tracer);
         TraceManager.Start(logger);                                                                //放到内存中的数据
     });
     applicationLifetime.ApplicationStopped.Register(() => TraceManager.Stop());
     app.UseTracing("UserApi");//记录微服务名称 唯一性
 }
Пример #28
0
 public static void UserZipkinCore(this IApplicationBuilder app, IHostApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory, string zipKinControllerUrl, string serviceName)
 {
     applicationLifetime.ApplicationStarted.Register(() =>
     {
         TraceManager.SamplingRate = 1.0f;
         var logger     = new TracingLogger(loggerFactory, "zipkin4net");
         var httpSender = new HttpZipkinSender(zipKinControllerUrl, "application/json");
         var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());
         TraceManager.RegisterTracer(tracer);
         TraceManager.Start(logger);
     });
     applicationLifetime.ApplicationStopped.Register(() => TraceManager.Stop());
     app.UseTracing(serviceName);
 }
Пример #29
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            //Configure logs

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            loggerFactory.AddAzureWebAppDiagnostics();
            loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);

            var pathBase = Configuration["PATH_BASE"];

            if (!string.IsNullOrEmpty(pathBase))
            {
                loggerFactory.CreateLogger("init").LogDebug($"Using PATH BASE '{pathBase}'");
                app.UsePathBase(pathBase);
            }


            /// set up Zipkin tracing services
            var applicationName = Configuration["applicationName"];
            var lifetime        = app.ApplicationServices.GetService <IApplicationLifetime>();

            lifetime.ApplicationStarted.Register(() => {
                TraceManager.SamplingRate = 1.0f;
                var logger     = new TracingLogger(loggerFactory, "zipkin4net");
                var httpSender = new HttpZipkinSender("http://localhost:9411", "application/json");
                var stats      = new Statistics();
                var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer(), stats);
                TraceManager.RegisterTracer(tracer);
                TraceManager.Start(logger);
            });
            lifetime.ApplicationStopped.Register(() => TraceManager.Stop());
            app.UseTracing(applicationName);

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
            app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200));
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

            app.UseCors("CorsPolicy");

            app.UseMvcWithDefaultRoute();

            app.UseSwagger()
            .UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Catalog.API V1");
            });

            ConfigureEventBus(app);
        }
Пример #30
0
        public void Configuration(IAppBuilder appBuilder)
        {
            TraceManager.SamplingRate = 1.0f;
            var logger     = new ConsoleLogger();
            var httpSender = new HttpZipkinSender("http://localhost:9411", "application/json");
            var tracer     = new ZipkinTracer(httpSender, new JSONSpanSerializer());

            TraceManager.RegisterTracer(tracer);
            TraceManager.Start(logger);
            // Setup Owin Middleware
            appBuilder.UseZipkinTracer("RestSharpZipkin");
            appBuilder.Run(RestSharpClientTrace);

            //
        }