Esempio 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);
 }
Esempio n. 2
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);
 }
        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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
        /// <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());
        }