private static ISampler GetJaegerSampler(JaegerOptions options)
 {
     return(options.Sampler switch
     {
         "const" => new ConstSampler(true),
         "rate" => new RateLimitingSampler(options.MaxTracesPerSecond),
         "probabilistic" => new ProbabilisticSampler(options.SamplingRate),
         _ => new ConstSampler(true),
     });
        public static IServiceCollection ConfigureTracingServices(this IServiceCollection services)
        {
            JaegerOptions jaegerOptions = GetJaegerOptions(services);

            if (!jaegerOptions.Enabled)
            {
                return(services);
            }

            services.AddSingleton <ITracer>(serviceProvider =>
            {
                ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>();

                RemoteReporter reporter = new RemoteReporter
                                          .Builder()
                                          .WithSender(new UdpSender(jaegerOptions.UdpHost, jaegerOptions.UdpPort, jaegerOptions.MaxPacketSize))
                                          .WithLoggerFactory(loggerFactory)
                                          .Build();

                ISampler sampler = GetJaegerSampler(jaegerOptions);

                Tracer tracer = new Tracer
                                .Builder(jaegerOptions.ServiceName)
                                .WithReporter(reporter)
                                .WithSampler(sampler)
                                .Build();

                GlobalTracer.Register(tracer);

                return(tracer);
            });

            services.AddOpenTracing();

            return(services);
        }