Ejemplo n.º 1
0
 public void TestSenderWithAuthTokenUsesHttpSender()
 {
     Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration(_loggerFactory)
                                                             .WithEndpoint("https://jaeger-collector:14268/api/traces")
                                                             .WithAuthToken("authToken");
     Assert.True(senderConfiguration.GetSender() is HttpSender);
 }
Ejemplo n.º 2
0
        public ISender GetSender(ILoggerFactory loggerFactory, Configuration.SenderConfiguration senderConfiguration)
        {
            var logger = loggerFactory.CreateLogger <ThriftSenderFactory>();

            if (!string.IsNullOrEmpty(senderConfiguration.Endpoint))
            {
                HttpSender.Builder httpSenderBuilder = new HttpSender.Builder(senderConfiguration.Endpoint);
                if (!string.IsNullOrEmpty(senderConfiguration.AuthUsername) && !string.IsNullOrEmpty(senderConfiguration.AuthPassword))
                {
                    logger.LogDebug("Using HTTP Basic authentication with data from the environment variables.");
                    httpSenderBuilder.WithAuth(senderConfiguration.AuthUsername, senderConfiguration.AuthPassword);
                }
                else if (!string.IsNullOrEmpty(senderConfiguration.AuthToken))
                {
                    logger.LogDebug("Auth Token environment variable found.");
                    httpSenderBuilder.WithAuth(senderConfiguration.AuthToken);
                }

                logger.LogDebug("Using the HTTP Sender to send spans directly to the endpoint.");
                return(httpSenderBuilder.Build());
            }

            logger.LogDebug("Using the UDP Sender to send spans to the agent.");
            return(new UdpSender(
                       StringOrDefault(senderConfiguration.AgentHost, UdpSender.DefaultAgentUdpHost),
                       senderConfiguration.AgentPort.GetValueOrDefault(UdpSender.DefaultAgentUdpCompactPort),
                       0 /* max packet size */));
        }
Ejemplo n.º 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddSingleton <ITracer>(sp =>
            {
                var loggerFactory  = sp.GetRequiredService <ILoggerFactory>();
                string serviceName = sp.GetRequiredService <IHostingEnvironment>().ApplicationName;

                var samplerConfiguration = new Configuration.SamplerConfiguration(loggerFactory)
                                           .WithType(ConstSampler.Type)
                                           .WithParam(1);

                var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory)
                                          .WithAgentHost("localhost")
                                          .WithAgentPort(6831);

                var reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
                                            .WithLogSpans(true)
                                            .WithSender(senderConfiguration);

                var tracer = (Tracer) new Configuration(serviceName, loggerFactory)
                             .WithSampler(samplerConfiguration)
                             .WithReporter(reporterConfiguration)
                             .GetTracer();


                //GlobalTracer.Register(tracer);

                return(tracer);
            });
            services.AddOpenTracing();
        }
        public ISender GetSender(ILoggerFactory loggerFactory, Configuration.SenderConfiguration senderConfiguration)
        {
            var logger = loggerFactory.CreateLogger <GrpcSenderFactory>();

            ChannelCredentials credentials;

            if (!string.IsNullOrEmpty(senderConfiguration.GrpcRootCertificate))
            {
                logger.LogDebug("Using TLS gRPC channel with data from the configuration.");

                KeyCertificatePair keypair = null;
                if (!string.IsNullOrEmpty(senderConfiguration.GrpcClientChain) &&
                    !string.IsNullOrEmpty(senderConfiguration.GrpcClientKey))
                {
                    var clientcert = File.ReadAllText(senderConfiguration.GrpcClientChain);
                    var clientkey  = File.ReadAllText(senderConfiguration.GrpcClientKey);
                    keypair = new KeyCertificatePair(clientcert, clientkey);
                }

                var rootcert = File.ReadAllText(senderConfiguration.GrpcRootCertificate);
                credentials = new SslCredentials(rootcert, keypair);
            }
            else
            {
                logger.LogDebug("Using insecure gRPC channel without credentials.");
                credentials = ChannelCredentials.Insecure;
            }

            logger.LogDebug("Using the gRPC Sender to send spans directly to the endpoint.");
            return(new GrpcSender(
                       StringOrDefault(senderConfiguration.GrpcTarget, GrpcSender.DefaultCollectorGrpcTarget),
                       credentials,
                       0 /* max packet size */));
        }
Ejemplo n.º 5
0
 public void TestSenderWithBasicAuthUsesHttpSender()
 {
     Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration(_loggerFactory)
                                                             .WithEndpoint("https://jaeger-collector:14268/api/traces")
                                                             .WithAuthUsername("username")
                                                             .WithAuthPassword("password");
     Assert.True(senderConfiguration.GetSender() is HttpSender);
 }
Ejemplo n.º 6
0
        public TraceService(ILoggerFactory loggerFactory, IOptions <JaegerOptions> options)
        {
            this.loggerFactory = loggerFactory;
            var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory).WithAgentHost(options.Value.Host);

            this.samplerConfiguration  = new Configuration.SamplerConfiguration(loggerFactory).WithType(ConstSampler.Type).WithParam(1);
            this.reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory).WithLogSpans(true).WithSender(senderConfiguration);
            this.tracers = new ConcurrentDictionary <string, ITracer>();
        }
Ejemplo n.º 7
0
        public void TestResolveWithTest1SelectedWithoutFactoriesReturnsNoopSender()
        {
            var senderResolver = new SenderResolver(_loggerFactory);
            var configuration  = new Configuration.SenderConfiguration(_loggerFactory)
                                 .WithSenderFactory(FACTORY_NAME_TEST1);

            var sender = senderResolver.Resolve(configuration);

            Assert.IsType <NoopSender>(sender);
        }
        public void TestCustomSender()
        {
            String endpoint = "https://custom-sender-endpoint:14268/api/traces";

            SetProperty(Configuration.JaegerEndpoint, "https://jaeger-collector:14268/api/traces");
            CustomSender customSender = new CustomSender(endpoint);

            Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration(_loggerFactory)
                                                                    .WithSender(customSender);
            Assert.Equal(endpoint, ((CustomSender)senderConfiguration.GetSender()).Endpoint);
        }
Ejemplo n.º 9
0
        public static IServiceCollection AddJaegerTracing(
            this IServiceCollection services,
            Action <JaegerTracingOptions> setupAction = null)
        {
            if (setupAction != null)
            {
                services.ConfigureJaegerTracing(setupAction);
            }

            services.AddSingleton <ITracer>(cli =>
            {
                var options = cli.GetService <IOptions <JaegerTracingOptions> >().Value;

                var senderConfig = new Configuration.SenderConfiguration(options.LoggerFactory)
                                   .WithAgentHost(options.JaegerAgentHost)
                                   .WithAgentPort(options.JaegerAgentPort);

                var reporter = new RemoteReporter.Builder()
                               .WithLoggerFactory(options.LoggerFactory)
                               .WithSender(senderConfig.GetSender())
                               .Build();

                var sampler = new GuaranteedThroughputSampler(options.SamplingRate, options.LowerBound);

                var tracer = new Tracer.Builder(options.ServiceName)
                             .WithLoggerFactory(options.LoggerFactory)
                             .WithReporter(reporter)
                             .WithSampler(sampler)
                             .Build();

                // Allows code that can't use dependency injection to have access to the tracer.
                if (!GlobalTracer.IsRegistered())
                {
                    GlobalTracer.Register(tracer);
                }

                return(tracer);
            });


            services.AddOpenTracing(builder => {
                builder.ConfigureAspNetCore(options => {
                    options.Hosting.IgnorePatterns.Add(x => {
                        return(x.Request.Path == "/health");
                    });
                    options.Hosting.IgnorePatterns.Add(x => {
                        return(x.Request.Path == "/metrics");
                    });
                });
            });

            return(services);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Resolves a sender by passing the given <see cref="Configuration.SenderConfiguration"/> down to the
        /// <see cref="ISenderFactory"/>. The factory is loaded either based on the value from the environment variable
        /// <see cref="Configuration.JaegerSenderFactory"/> or, in its absence or failure to deliver a <see cref="ISender"/>,
        /// via reflection. If no factories are found, a <see cref="NoopSender"/> is returned. If multiple factories
        /// are available, the factory whose <see cref="ISenderFactory.FactoryName"/> matches the JAEGER_SENDER_FACTORY env var is
        /// selected. If none matches, <see cref="NoopSender"/> is returned.
        /// </summary>
        /// <param name="senderConfiguration">The configuration to pass down to the factory</param>
        /// <returns>The resolved <see cref="ISender"/>, or <see cref="NoopSender"/></returns>
        public ISender Resolve(Configuration.SenderConfiguration senderConfiguration)
        {
            var senderFactory = GetSenderFactory(senderConfiguration.SenderFactory);

            if (senderFactory != null)
            {
                return(GetSenderFromFactory(senderFactory, senderConfiguration));
            }

            _logger.LogWarning("No suitable sender found. Using NoopSender, meaning that data will not be sent anywhere!");
            return(NoopSender.Instance);
        }
Ejemplo n.º 11
0
 private ISender GetSenderFromFactory(ISenderFactory senderFactory, Configuration.SenderConfiguration configuration)
 {
     try
     {
         var sender = senderFactory.GetSender(_loggerFactory, configuration);
         _logger.LogDebug($"Using sender {sender}");
         return(sender);
     }
     catch (Exception e)
     {
         _logger.LogWarning("Failed to get a sender from the sender factory.", e);
         throw;
     }
 }
Ejemplo n.º 12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            // Use "OpenTracing.Contrib.NetCore" to automatically generate spans for ASP.NET Core, Entity Framework Core, ...
            // See https://github.com/opentracing-contrib/csharp-netcore for details.
            services.AddOpenTracing();

            // Adds the Jaeger Tracer.
            services.AddSingleton <ITracer>(serviceProvider =>
            {
                // string serviceName = serviceProvider.GetRequiredService<IWebHostEnvironment>().ApplicationName;

                // This will log to a default localhost installation of Jaeger.
                //var tracer = new Tracer.Builder(serviceName)
                //    .WithSampler(new ConstSampler(true))
                //    .Build();

                // var loggerFactory = new LoggerFactory(); // get Microsoft.Extensions.Logging ILoggerFactory
                // var serviceName = "testService";

                //Jaeger.Configuration.SenderConfiguration.DefaultSenderResolver = new SenderResolver(loggerFactory)
                //    .RegisterSenderFactory<ThriftSenderFactory>();
                ////Configuration config = new Configuration(serviceName, loggerFactory)
                ////    // .WithSampler(...)   // optional, defaults to RemoteControlledSampler with HttpSamplingManager on localhost:5778
                ////    .WithReporter(Jaeger.Configuration.ReporterConfiguration.FromEnv(loggerFactory)); // optional, defaults to RemoteReporter with UdpSender on localhost:6831 when ThriftSenderFactory is registered
                //Configuration config = Jaeger.Configuration.FromEnv(loggerFactory);

                //ITracer tracer = config.GetTracer().wi;

                //// Allows code that can't use DI to also access the tracer.
                //GlobalTracer.Register(tracer);

                var senderResolver = new SenderResolver(loggerFactory).RegisterSenderFactory <ThriftSenderFactory>();

                var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory)
                                          .WithSenderResolver(senderResolver).WithEndpoint("http://192.168.1.34:14268/api/traces"); // optional, defaults to Configuration.SenderConfiguration.DefaultSenderResolver


                var reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
                                            .WithSender(senderConfiguration) // optional, defaults to UdpSender at localhost:6831 when ThriftSenderFactory is registered
                                            .WithLogSpans(true);             // optional, defaults to no LoggingReporter

                var tracer = new Configuration("campaignUI", loggerFactory)
                             .WithReporter(reporterConfiguration) // optional, defaults to RemoteReporter with UdpSender at localhost:6831 when ThriftSenderFactory is registered
                             .GetTracer();

                return(tracer);
            });
        }
Ejemplo n.º 13
0
        public static IServiceCollection AddJaegerTracingForService(this IServiceCollection services, Action <JaegerTracingOptions> setupAction = null)
        {
            // Run setup action
            if (setupAction != null)
            {
                services.ConfigureJaegerTracing(setupAction);
            }

            // Configure Open Tracing with non-default behavior, skipping ASP.Net and Entity Framework
            services.AddOpenTracingCoreServices(builder =>
                                                builder.AddCoreFx()
                                                .AddLoggerProvider());

            services.AddSingleton <ITracer>(serviceProvider =>
            {
                // Get the options for the various parts of the tracer
                var options = serviceProvider.GetService <IOptions <JaegerTracingOptions> >().Value;

                var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>();

                var senderConfig = new Configuration.SenderConfiguration(loggerFactory)
                                   .WithAgentHost(options.JaegerAgentHost)
                                   .WithAgentPort(options.JaegerAgentPort);

                var sender = senderConfig.GetSender();

                var reporter = new RemoteReporter.Builder()
                               .WithLoggerFactory(loggerFactory)
                               .WithSender(sender)
                               .Build();

                var sampler = new GuaranteedThroughputSampler(options.SamplingRate, options.LowerBound);

                var tracer = new Tracer.Builder(options.ServiceName)
                             .WithLoggerFactory(loggerFactory)
                             .WithReporter(reporter)
                             .WithSampler(sampler)
                             .Build();

                // Allows code that can't use dependency injection to have access to the tracer.
                if (!GlobalTracer.IsRegistered())
                {
                    GlobalTracer.Register(tracer);
                }

                return(tracer);
            });

            return(services);
        }
Ejemplo n.º 14
0
        // Jaeger for .NET Core sources:
        // https://github.com/jaegertracing/jaeger-client-csharp
        // https://medium.com/imaginelearning/jaeger-tracing-on-kubernetes-with-net-core-8b5feddb6f2f
        // https://itnext.io/jaeger-tracing-on-kubernetes-with-asp-net-core-and-traefik-86b1d9fd5489


        // Note: redundant code in this file, can refactor

        public static IServiceCollection AddJaegerTracingForApi(this IServiceCollection services,
                                                                Action <JaegerTracingOptions> setupAction,
                                                                Action <AspNetCoreDiagnosticOptions> aspnetOptionsAction)
        {
            services.ConfigureJaegerTracing(setupAction);

            // Configure Open Tracing with default behavior for .NET
            services.AddOpenTracing(builder =>
            {
                builder.ConfigureAspNetCore(aspnetOptionsAction);
            });

            services.AddSingleton <ITracer>(serviceProvider =>
            {
                // Get the options for the various parts of the tracer
                var options = serviceProvider.GetService <IOptions <JaegerTracingOptions> >().Value;

                var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>();

                var senderConfig = new Configuration.SenderConfiguration(loggerFactory)
                                   .WithAgentHost(options.JaegerAgentHost)
                                   .WithAgentPort(options.JaegerAgentPort);

                var sender = senderConfig.GetSender();

                var reporter = new RemoteReporter.Builder()
                               .WithLoggerFactory(loggerFactory)
                               .WithSender(sender)
                               .Build();

                var sampler = new GuaranteedThroughputSampler(options.SamplingRate, options.LowerBound);

                var tracer = new Tracer.Builder(options.ServiceName)
                             .WithLoggerFactory(loggerFactory)
                             .WithReporter(reporter)
                             .WithSampler(sampler)
                             .Build();

                // Allows code that can't use dependency injection to have access to the tracer.
                if (!GlobalTracer.IsRegistered())
                {
                    GlobalTracer.Register(tracer);
                }

                return(tracer);
            });

            return(services);
        }
Ejemplo n.º 15
0
        public void TestResolveWithTest2SelectedWithTest2FactoryReturnsFlexibleSender()
        {
            var configuration = new Configuration.SenderConfiguration(_loggerFactory)
                                .WithSenderFactory(FACTORY_NAME_TEST2);
            var senderResolver = new SenderResolver(_loggerFactory)
                                 .RegisterSenderFactory(_test2SenderFactory);

            var sender = senderResolver.Resolve(configuration);

            Assert.IsType <FlexibleSenderFactory.Sender>(sender);

            var flexibleSender = (FlexibleSenderFactory.Sender)sender;

            Assert.Equal(FACTORY_NAME_TEST2, flexibleSender.FactoryName);
            Assert.Equal(configuration, flexibleSender.SenderConfiguration);
        }
        private static ITracer GetTracer(string serviceName, ILoggerFactory loggerFactory, string collectorAddress)
        {
            Configuration.SamplerConfiguration samplerConfiguration = new Configuration.SamplerConfiguration(loggerFactory)
                                                                      .WithParam(1)
                                                                      .WithType("const");
            Configuration.SenderConfiguration senderConfig = new Configuration.SenderConfiguration(loggerFactory)
                                                             .WithEndpoint(collectorAddress);
            Configuration.ReporterConfiguration reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
                                                                        .WithSender(senderConfig);
            Configuration configuration = new Configuration(serviceName, loggerFactory)
                                          .WithReporter(reporterConfiguration)
                                          .WithSampler(samplerConfiguration);
            var tracer = configuration.GetTracerBuilder().WithTraceId128Bit().WithLoggerFactory(loggerFactory).Build();

            return(tracer);
        }
Ejemplo n.º 17
0
        public static Tracer Init(string serviceName, ILoggerFactory loggerFactory)
        {
            var samplerConfig = new Configuration.SamplerConfiguration(loggerFactory)
                                .WithType(ConstSampler.Type)
                                .WithParam(1);

            var senderConfig = new Configuration.SenderConfiguration(loggerFactory)
                               .WithEndpoint("http://localhost:14268/api/traces");

            var reporterConfig = new Configuration.ReporterConfiguration(loggerFactory)
                                 .WithLogSpans(true)
                                 .WithSender(senderConfig);

            return((Tracer) new Configuration(serviceName, loggerFactory)
                   .WithSampler(samplerConfig)
                   .WithReporter(reporterConfig)
                   .GetTracer());
        }
Ejemplo n.º 18
0
        public static Tracer Init(string serviceName, ILoggerFactory loggerFactory)
        {
            var samplerConfiguration = new Configuration.SamplerConfiguration(loggerFactory)
                                       .WithType(ConstSampler.Type)
                                       .WithParam(1);

            var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory)
                                      .WithAgentHost("srvdocker2-t")
                                      .WithAgentPort(46831);

            var reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
                                        .WithSender(senderConfiguration)
                                        .WithLogSpans(true);

            return((Tracer) new Configuration(serviceName, loggerFactory)
                   .WithSampler(samplerConfiguration)
                   .WithReporter(reporterConfiguration)
                   .GetTracer());
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Построение нового экземпляра класса Jaeger.Tracer для
        /// отправки запросов и метрики в удаленный сервис-агента.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static ITracer ConfigureJaegerTracer(ITracerOptions options = null)
        {
            var senderConfig = new Configuration.SenderConfiguration(options.LoggerFactory)
                               .WithAgentHost(options.JaegerAgentHost)
                               .WithAgentPort(options.JaegerAgentPort);

            var reporter = new RemoteReporter.Builder()
                           .WithLoggerFactory(options.LoggerFactory)
                           .WithSender(senderConfig.GetSender())
                           .Build();

            var sampler = new GuaranteedThroughputSampler(options.SamplingRate, options.LowerBound);

            return(new Jaeger.Tracer.Builder(options.ServiceName)
                   .WithLoggerFactory(options.LoggerFactory)
                   .WithReporter(reporter)
                   .WithSampler(sampler)
                   .Build());
        }
Ejemplo n.º 20
0
        private static Tracer InitTracer(string serviceName, ILoggerFactory loggerFactory)
        {
            Configuration.SenderConfiguration sender = new Configuration.SenderConfiguration(loggerFactory)
                                                       .WithAgentHost("127.0.0.1")
                                                       .WithAgentPort(6831);

            Configuration.SamplerConfiguration samplerConfiguration = new Configuration.SamplerConfiguration(loggerFactory)
                                                                      .WithType(ConstSampler.Type)
                                                                      .WithParam(1);

            Configuration.ReporterConfiguration reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
                                                                        .WithSender(sender)
                                                                        .WithLogSpans(true);

            return((Tracer) new Configuration(serviceName, loggerFactory)
                   .WithSampler(samplerConfiguration)
                   .WithReporter(reporterConfiguration)
                   .GetTracer());
        }
        public static ITracer Create(string serviceName, ILoggerFactory loggerFactory)
        {
            Configuration.SenderConfiguration.DefaultSenderResolver = new SenderResolver(loggerFactory)
                                                                      .RegisterSenderFactory <ThriftSenderFactory>();

#if CONFIG_DRIVEN
            try{
                if (System.String.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("JAEGER_SERVICE_NAME")))
                {
                    System.Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", serviceName);
                }
                return((ITracer)Configuration.FromEnv(loggerFactory).GetTracer());
            }
            catch (System.Exception err)
            {
                System.Console.WriteLine(err.ToString());
                return(OpenTracing.Noop.NoopTracerFactory.Create());
            }
#else
            var samplerConfiguration = new Configuration.SamplerConfiguration(loggerFactory)
                                       .WithType(ConstSampler.Type)
                                       .WithParam(1);

            var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory);



            var reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
                                        .WithSender(senderConfiguration)
                                        .WithLogSpans(true);

            return((Tracer) new Configuration(serviceName, loggerFactory)
                   .WithSampler(samplerConfiguration)
                   .WithReporter(reporterConfiguration)
                   .GetTracer());
#endif
        }
Ejemplo n.º 22
0
        private static Configuration GetTracerConfig(JaegerOptions options, ILoggerFactory loggerFactory)
        {
            // Sender
            var senderConfig = new Configuration.SenderConfiguration(loggerFactory);

            senderConfig.WithAgentHost(options.AgentHost)
            .WithAgentPort(options.AgentPort)
            .WithEndpoint(options.Endpoint);

            if (!string.IsNullOrEmpty(options.User))
            {
                senderConfig.WithAuthUsername(options.User)
                .WithAuthPassword(options.Password);
            }
            if (!string.IsNullOrEmpty(options.AuthToken))
            {
                senderConfig.WithAuthToken(options.AuthToken);
            }

            // Sampler
            var samplerConfig = new Configuration.SamplerConfiguration(loggerFactory)
                                .WithSamplingEndpoint(options.SamplingEndpoint)
                                .WithType(ConstSampler.Type);

            // Reporter
            var reporterConfig = new Configuration.ReporterConfiguration(loggerFactory);

            reporterConfig.WithSender(senderConfig);

            // Configuration
            var tracerConfig = new Configuration(options.ServiceName, loggerFactory)
                               .WithSampler(samplerConfig)
                               .WithReporter(reporterConfig);

            return(tracerConfig);
        }
        public static Tracer Init(string serviceName, ILoggerFactory loggerFactory)
        {
            var senderConfiguration = new Configuration.SenderConfiguration(loggerFactory)
                                      .WithAgentHost("jaeger").WithAgentPort(6831);

            var samplerConfiguration = new Configuration.SamplerConfiguration(loggerFactory)
                                       .WithType(ConstSampler.Type)
                                       .WithParam(1);

            var reporterConfiguration = new Configuration.ReporterConfiguration(loggerFactory)
                                        .WithSender(senderConfiguration)
                                        .WithLogSpans(true);

            //var config = Configuration.FromEnv(loggerFactory);
            //config.WithSampler(samplerConfiguration);
            //config.WithReporter(reporterConfiguration);

            //return (Tracer)config.GetTracer();

            return((Tracer) new Configuration(serviceName, loggerFactory)
                   .WithSampler(samplerConfiguration)
                   .WithReporter(reporterConfiguration)
                   .GetTracer());
        }
 public Sender(string factoryName, Configuration.SenderConfiguration senderConfiguration)
 {
     FactoryName         = factoryName;
     SenderConfiguration = senderConfiguration;
 }
 public ISender GetSender(ILoggerFactory loggerFactory, Configuration.SenderConfiguration senderConfiguration)
 {
     return(new Sender(FactoryName, senderConfiguration));
 }
Ejemplo n.º 26
0
        public static IServiceCollection AddElectJaeger(this IServiceCollection services,
                                                        [NotNull] Action <ElectJaegerOptions> configure)
        {
            services.Configure(configure);

            var electJaegerOptions = configure.GetValue();

            if (!electJaegerOptions.IsEnable)
            {
                return(services);
            }

            // Add open Tracing
            services.AddOpenTracing();

            // Add ITracer
            services.AddSingleton(serviceProvider =>
            {
                var loggerFactory = GetLoggerFactory(serviceProvider);

                // Sampler
                var samplerConfig = new Configuration.SamplerConfiguration(loggerFactory);
                samplerConfig.WithSamplingEndpoint(
                    $"http://{electJaegerOptions.SamplerDomain}:{electJaegerOptions.SamplerPort}");
                samplerConfig.WithType(ConstSampler.Type);
                samplerConfig = electJaegerOptions.AfterSamplerConfig?.Invoke(samplerConfig) ?? samplerConfig;

                // Sender
                var senderConfig = new Configuration.SenderConfiguration(loggerFactory);
                senderConfig.WithAgentHost(electJaegerOptions.ReporterDomain);
                senderConfig.WithAgentPort(electJaegerOptions.ReporterPort);
                senderConfig.WithEndpoint(electJaegerOptions.TracesEndpoint);
                if (!string.IsNullOrWhiteSpace(electJaegerOptions.AuthUsername))
                {
                    senderConfig.WithAuthUsername(electJaegerOptions.AuthUsername);
                }

                if (!string.IsNullOrWhiteSpace(electJaegerOptions.AuthPassword))
                {
                    senderConfig.WithAuthPassword(electJaegerOptions.AuthPassword);
                }

                if (!string.IsNullOrWhiteSpace(electJaegerOptions.AuthToken))
                {
                    senderConfig.WithAuthToken(electJaegerOptions.AuthToken);
                }

                // Reporter
                var reporterConfig = new Configuration.ReporterConfiguration(loggerFactory);
                reporterConfig.WithSender(senderConfig);

                reporterConfig = electJaegerOptions.AfterReporterConfig?.Invoke(reporterConfig) ?? reporterConfig;

                // Global Config

                Configuration.SenderConfiguration.DefaultSenderResolver =
                    new SenderResolver(loggerFactory)
                    .RegisterSenderFactory <ThriftSenderFactory>();

                var config =
                    new Configuration(electJaegerOptions.ServiceName, loggerFactory)
                    .WithSampler(samplerConfig)
                    .WithReporter(reporterConfig);

                config = electJaegerOptions.AfterGlobalConfig?.Invoke(config) ?? config;

                // Tracer
                var tracer = config.GetTracer();
                tracer     = electJaegerOptions.AfterTracer?.Invoke(tracer) ?? tracer;

                // Register Tracer
                if (!GlobalTracer.IsRegistered())
                {
                    GlobalTracer.Register(tracer);
                }

                return(tracer);
            });

            services.Configure <HttpHandlerDiagnosticOptions>(options =>
            {
                options.IgnorePatterns.Add(x => !x.RequestUri.IsLoopback);
            });

            return(services);
        }