Exemplo n.º 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)
        {
            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();
            });
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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();
            });
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 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)
        {
            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);
            }
        }
Exemplo n.º 6
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
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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>());
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 public void Setup()
 {
     _spanSerializer = new Mock <ISpanSerializer>();
     _spanSender     = new Mock <IZipkinSender>();
     _statistics     = new Mock <IStatistics>();
     _tracer         = new ZipkinTracer(_spanSender.Object, _spanSerializer.Object, _statistics.Object);
 }
Exemplo n.º 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();
            }
            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();
        }
        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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        public static void StartTracing(string collectionUrl)
        {
            var tracer = new ZipkinTracer(new HttpZipkinSender(collectionUrl, "application/json"), new JSONSpanSerializer());

            TraceManager.SamplingRate = 1;
            TraceManager.RegisterTracer(tracer);
            TraceManager.Start(new ConsoleLogger());
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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());
        }
        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);
        }
Exemplo n.º 19
0
        public void StatisticsAreUpdatedForRecord()
        {
            var statistics = new Mock <IStatistics>();
            var tracer     = new ZipkinTracer(Mock.Of <IZipkinSender>(), Mock.Of <ISpanSerializer>(), statistics.Object);
            var trace      = Trace.Create();

            Record(tracer, trace, Annotations.ServerRecv());

            statistics.Verify(s => s.UpdateRecordProcessed(), Times.Once());
        }
Exemplo n.º 20
0
        // ConfigureContainer is where you can register things directly
        // with Autofac. This runs after ConfigureServices so the things
        // here will override registrations made in ConfigureServices.
        // Don't build the container; that gets done for you. If you
        // need a reference to the container, you need to use the
        // "Without ConfigureContainer" mechanism shown later.
        public void ConfigureContainer(ContainerBuilder builder)
        {
            // builder.RegisterModule(new AutofacModule());
            // builder.RegisterInstance<IMetrics>(ConfigureMetrics()).SingleInstance();
            // builder.RegisterInstance<IHealth>(ConfigureHealth()).SingleInstance();

            var url    = "http://localhost:9411";
            var tracer = new ZipkinTracer(new ZipkinTracerOptions(url, "api", debug: true));

            builder.RegisterInstance <ITracer>(tracer);
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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);
        }
        public ZipkinKafkaIntegrationSpecs(ITestOutputHelper helper, ZipkinKafkaFixture fixture) : base(output: helper)
        {
            _appName = Sys.Name + ZipkinAppCounter.IncrementAndGet();
            Tracer   = new ZipkinTracer(new ZipkinTracerOptions(
                                            new Endpoint(_appName), ZipkinKafkaSpanReporter.Create(fixture.KafkaUri, Sys))
            {
                ScopeManager = new AsyncLocalScopeManager()
            });

            _httpBaseUri  = new Uri($"http://{fixture.ZipkinUrl}/");
            _zipkinClient = new HttpClient();
        }
Exemplo n.º 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);
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
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");//记录微服务名称 唯一性
 }
Exemplo n.º 29
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);
 }
Exemplo n.º 30
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);
        }