コード例 #1
0
        public static JaegerOptions Create()
        {
            var jaegerOptions = new JaegerOptions();

            foreach (var propertyInfo in jaegerOptions.GetType().GetProperties())
            {
                var configValue  = Environment.GetEnvironmentVariable($"JAEGER_{propertyInfo.Name.ToUpperSnakeCase()}");
                var defaultValue = propertyInfo.GetValue(jaegerOptions);

                propertyInfo.SetValue(jaegerOptions, configValue ?? defaultValue, null);
            }

            return(jaegerOptions);
        }
コード例 #2
0
        public static JaegerOptions Create(IConfiguration configuration)
        {
            var jaegerOptions = new JaegerOptions();

            foreach (var propertyInfo in jaegerOptions.GetType().GetProperties())
            {
                var configValue  = configuration[$"JAEGER_{propertyInfo.Name.ToUpperSnakeCase()}"];
                var defaultValue = propertyInfo.GetValue(jaegerOptions);

                propertyInfo.SetValue(jaegerOptions, configValue ?? defaultValue, null);
            }

            return(jaegerOptions);
        }
コード例 #3
0
        public static IServiceCollection AddJaegerTracing(this IServiceCollection services, Action <JaegerOptions> configure)
        {
            services.Configure(configure);

            var options = new JaegerOptions();

            configure?.Invoke(options);
            services.AddOpenTracing();

            // Add ITracer
            services.AddSingleton(serviceProvider =>
            {
                var configuration = serviceProvider.GetService <IConfiguration>();
                var loggerFactory = serviceProvider.GetService <ILoggerFactory>();

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

                var tracerConfig = GetTracerConfig(options, loggerFactory);

                // Tracer
                var tracer = tracerConfig.GetTracer();

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

                return(tracer);
            });

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

            return(services);
        }
コード例 #4
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);
        }
コード例 #5
0
 public static IServiceCollection AddJaegerTracing(this IServiceCollection services, JaegerOptions options)
 {
     return(services.AddJaegerTracing(configure =>
     {
         options.CopyTo(configure);
     }));
 }