Esempio n. 1
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);
        }
Esempio n. 2
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);
        }