예제 #1
0
 private static RemoteReporter BuildRemoteReporter(JaegerOptions options, ILoggerFactory loggerFactory)
 {
     DeimosLogger.JaegerLogger.UdpRemoteReporter(options.UdpHost, options.UdpPort);
     return(new RemoteReporter.Builder()
            .WithSender(new UdpSender(options.UdpHost, options.UdpPort, options.MaxPacketSize))
            .WithLoggerFactory(loggerFactory)
            .Build());
 }
 private static ISampler GetSampler(JaegerOptions options)
 {
     return(options.Sampler switch
     {
         "const" => new ConstSampler(true),
         "rate" => new RateLimitingSampler(options.MaxTracesPerSecond),
         "probabilistic" => new ProbabilisticSampler(options.SamplingRate),
         _ => new ConstSampler(true),
     });
예제 #3
0
 private static ITracer BuildTracer(JaegerOptions options, ApplicationOptions appOptions, ILoggerFactory loggerFactory)
 {
     return(new Tracer.Builder(appOptions.ApplicationName.DashToLower())
            .WithLoggerFactory(loggerFactory)
            .WithReporter(BuildRemoteReporter(options, loggerFactory))
            .WithSampler(options.GetSampler())
            .WithTag("app.instance.id", appOptions.ApplicationInstanceId)
            .WithTag("app", appOptions.ApplicationName)
            .Build());
 }
예제 #4
0
    private static ISampler GetSampler(JaegerOptions options)
    {
        switch (options.Sampler)
        {
        case "const": return(new ConstSampler(true));

        case "rate": return(new RateLimitingSampler(options.MaxTracesPerSecond));

        case "probabilistic": return(new ProbabilisticSampler(options.SamplingRate));

        default: return(new ConstSampler(true));
        }
    }
예제 #5
0
        private static ISolariBuilder ConfigureTracer(ISolariBuilder builder, JaegerOptions options)
        {
            builder.Services.AddSingleton(sp =>
            {
                var loggerFactory             = sp.GetRequiredService <ILoggerFactory>();
                ApplicationOptions appOptions = sp.GetService <IOptions <ApplicationOptions> >().Value;
                ITracer tracer = BuildTracer(options, appOptions, loggerFactory);
                GlobalTracer.Register(tracer);
                DeimosLogger.JaegerLogger.ConfiguredTracer();
                DeimosLogger.JaegerLogger.UsingJaegerTracing();
                return(tracer);
            });

            return(builder);
        }
예제 #6
0
        public void ShouldAddJaegerTracingWithJaegerOptions()
        {
            //Arrange
            var serviceCollection = new ServiceCollection();
            var jaegerOptions     = new JaegerOptions();

            serviceCollection.AddLogging()
            .AddJaegerTracing(jaegerOptions);

            //Act
            var tracer = serviceCollection.BuildServiceProvider().GetService <ITracer>();

            //Assert
            Assert.NotNull(tracer);
        }
예제 #7
0
        private static Tracer GetTracer(JaegerOptions options)
        {
            var sampler  = new ConstSampler(true);
            var reporter = new RemoteReporter.Builder()
                                                                                     //.WithMaxQueueSize(...)            // optional, defaults to 100
                                                                                     //.WithFlushInterval(...)           // optional, defaults to TimeSpan.FromSeconds(1)
                           .WithSender(new UdpSender(options.Host, options.Port, 0)) // optional, defaults to UdpSender("localhost", 6831, 0)
                           .Build();

            // This will log to a default localhost installation of Jaeger.
            var tracer = new Tracer.Builder(options.ServiceName)
                         .WithSampler(sampler)
                         .WithReporter(reporter)
                         .Build();

            return(tracer);
        }
        private static ITraceWriter CreateTraceWriter(TracerSettings settings, IDogStatsd statsd)
        {
            IMetrics metrics = statsd != null
                ? new DogStatsdMetrics(statsd)
                : new NullMetrics();

            switch (settings.Exporter)
            {
            case ExporterType.Zipkin:
                return(new ExporterWriter(new ZipkinExporter(settings.AgentUri), metrics));

            case ExporterType.Jaeger:
                return(new ExporterWriter(new JaegerExporter(JaegerOptions.FromTracerSettings(settings)), metrics));

            default:
                return(new AgentWriter(new Api(settings.AgentUri, TransportStrategy.Get(settings), statsd), metrics, maxBufferSize: settings.TraceBufferSize));
            }
        }
        internal static JaegerExporter BuildExporter(int?payloadSize = null)
        {
            var clientMock = new Mock <IJaegerClient>();

            clientMock
            .Setup(x => x.Send(It.IsAny <byte[]>()))
            .Returns <byte[]>((buffer) => buffer?.Length ?? 0);
            clientMock
            .Setup(x => x.Send(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns <byte[], int, int>((buffer, offset, count) => count);

            var options = new JaegerOptions
            {
                TransportClient = clientMock.Object
            };

            if (payloadSize.HasValue)
            {
                options.MaxPayloadSizeInBytes = payloadSize.Value;
            }

            return(new JaegerExporter(options));
        }
예제 #10
0
    public static IConveyBuilder AddJaeger(this IConveyBuilder builder, JaegerOptions options,
                                           string sectionName = SectionName, Action <IOpenTracingBuilder> openTracingBuilder = null)
    {
        if (Interlocked.Exchange(ref _initialized, 1) == 1)
        {
            return(builder);
        }

        builder.Services.AddSingleton(options);
        if (!options.Enabled)
        {
            var defaultTracer = ConveyDefaultTracer.Create();
            builder.Services.AddSingleton(defaultTracer);
            return(builder);
        }

        if (!builder.TryRegister(RegistryName))
        {
            return(builder);
        }

        if (options.ExcludePaths is not null)
        {
            builder.Services.Configure <AspNetCoreDiagnosticOptions>(o =>
            {
                foreach (var path in options.ExcludePaths)
                {
                    o.Hosting.IgnorePatterns.Add(x => x.Request.Path == path);
                }
            });
        }

        builder.Services.AddOpenTracing(x => openTracingBuilder?.Invoke(x));

        builder.Services.AddSingleton <ITracer>(sp =>
        {
            var loggerFactory = sp.GetRequiredService <ILoggerFactory>();
            var maxPacketSize = options.MaxPacketSize <= 0 ? 64967 : options.MaxPacketSize;
            var senderType    = string.IsNullOrWhiteSpace(options.Sender) ? "udp" : options.Sender?.ToLowerInvariant();
            ISender sender    = senderType switch
            {
                "http" => BuildHttpSender(options.HttpSender),
                "udp" => new UdpSender(options.UdpHost, options.UdpPort, maxPacketSize),
                _ => throw new Exception($"Invalid Jaeger sender type: '{senderType}'.")
            };

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

            var sampler = GetSampler(options);

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

            GlobalTracer.Register(tracer);

            return(tracer);
        });

        return(builder);
    }
예제 #11
0
 public JaegerTracerFactory(IOptions <JaegerOptions> options)
 {
     _options = options.Value ?? throw new ArgumentNullException(nameof(options));
 }