public void TestReporterConfigurationInvalidLogSpans() { SetProperty(Configuration.JaegerReporterLogSpans, "X"); ReporterConfiguration reporterConfig = ReporterConfiguration.FromEnv(_loggerFactory); Assert.False(reporterConfig.LogSpans); }
public Tracer.Builder GetTracerBuilder() { if (ReporterConfig == null) { ReporterConfig = new ReporterConfiguration(_loggerFactory); } if (SamplerConfig == null) { SamplerConfig = new SamplerConfiguration(_loggerFactory); } if (_codecConfig == null) { _codecConfig = new CodecConfiguration(new Dictionary <IFormat <ITextMap>, List <Codec <ITextMap> > >()); } if (_metricsFactory == null) { _metricsFactory = NoopMetricsFactory.Instance; } IMetrics metrics = new MetricsImpl(_metricsFactory); IReporter reporter = ReporterConfig.GetReporter(metrics); ISampler sampler = SamplerConfig.CreateSampler(_serviceName, metrics); Tracer.Builder builder = new Tracer.Builder(_serviceName) .WithLoggerFactory(_loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .WithMetrics(metrics) .WithTags(_tracerTags); _codecConfig.Apply(builder); return(builder); }
public void TestReporterConfigurationInvalidFlushInterval() { SetProperty(Configuration.JaegerReporterFlushInterval, "X"); ReporterConfiguration reporterConfig = ReporterConfiguration.FromEnv(_loggerFactory); Assert.Null(reporterConfig.FlushInterval); }
public void TestReporterConfigurationFromIConfiguration() { var arrayDict = new Dictionary <string, string> { { Configuration.JaegerSamplerType, ConstSampler.Type }, { Configuration.JaegerSamplerParam, "1" }, { Configuration.JaegerReporterLogSpans, "true" }, { Configuration.JaegerAgentHost, "MyHost" }, { Configuration.JaegerAgentPort, "1234" }, { Configuration.JaegerReporterFlushInterval, "500" }, { Configuration.JaegerReporterMaxQueueSize, "1000" } }; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(arrayDict) .Build(); ReporterConfiguration reporterConfig = ReporterConfiguration.FromIConfiguration(_loggerFactory, configuration); Assert.True(reporterConfig.LogSpans); Assert.Equal("MyHost", reporterConfig.SenderConfig.AgentHost); Assert.Equal(1234, reporterConfig.SenderConfig.AgentPort); Assert.Equal(TimeSpan.FromMilliseconds(500), reporterConfig.FlushInterval); Assert.Equal(1000, reporterConfig.MaxQueueSize); }
public static IServiceCollection AddJaeger(this IServiceCollection services) { services.AddSingleton <ITracer>(serviceProvider => { var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var senderConfig = new SenderConfiguration(loggerFactory) .WithAgentHost(Environment.GetEnvironmentVariable("JAEGER_AGENT_HOST")) .WithAgentPort(Convert.ToInt32(Environment.GetEnvironmentVariable("JAEGER_AGENT_PORT"))); SenderConfiguration.DefaultSenderResolver = new SenderResolver(loggerFactory) .RegisterSenderFactory <ThriftSenderFactory>(); var config = Configuration.FromEnv(loggerFactory); var samplerConfiguration = new SamplerConfiguration(loggerFactory) .WithType(ConstSampler.Type) .WithParam(1); var reporterConfiguration = new ReporterConfiguration(loggerFactory) .WithSender(senderConfig) .WithLogSpans(true); var tracer = config .WithSampler(samplerConfiguration) .WithReporter(reporterConfiguration) .GetTracer(); GlobalTracer.Register(tracer); return(tracer); }); return(services); }
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>(); }
/// <summary> /// Returns <see cref="Configuration"/> object from environmental variables. /// </summary> public static Configuration FromEnv(ILoggerFactory loggerFactory) { ILogger logger = loggerFactory.CreateLogger <Configuration>(); return(new Configuration(GetProperty(JaegerServiceName), loggerFactory) .WithTracerTags(TracerTagsFromEnv(logger)) .WithReporter(ReporterConfiguration.FromEnv(loggerFactory)) .WithSampler(SamplerConfiguration.FromEnv(loggerFactory)) .WithCodec(CodecConfiguration.FromEnv(loggerFactory))); }
/// <summary> /// Returns <see cref="Configuration"/> object from a Configuration. /// </summary> public static Configuration FromIConfiguration(ILoggerFactory loggerFactory, IConfiguration configuration) { ILogger logger = loggerFactory.CreateLogger <Configuration>(); return(new Configuration(GetProperty(JaegerServiceName, logger, configuration), loggerFactory) .WithTracerTags(TracerTagsFromIConfiguration(logger, configuration)) .WithTraceId128Bit(GetPropertyAsBool(JaegerTraceId128Bit, logger, configuration).GetValueOrDefault(false)) .WithReporter(ReporterConfiguration.FromIConfiguration(loggerFactory, configuration)) .WithSampler(SamplerConfiguration.FromIConfiguration(loggerFactory, configuration)) .WithCodec(CodecConfiguration.FromIConfiguration(loggerFactory, configuration))); }
public static ITracer Init(string service) { var loggerFactory = NullLoggerFactory.Instance; var samplerConfig = SamplerConfiguration.FromEnv(loggerFactory) .WithType(ConstSampler.Type) .WithParam(1); var reporterConfig = ReporterConfiguration.FromEnv(loggerFactory); var config = new Jaeger.Configuration(service, loggerFactory) .WithSampler(samplerConfig) .WithReporter(reporterConfig); return(config.GetTracer()); }
public void TestReporterConfiguration() { SetProperty(Configuration.JaegerReporterLogSpans, "true"); SetProperty(Configuration.JaegerAgentHost, "MyHost"); SetProperty(Configuration.JaegerAgentPort, "1234"); SetProperty(Configuration.JaegerReporterFlushInterval, "500"); SetProperty(Configuration.JaegerReporterMaxQueueSize, "1000"); ReporterConfiguration reporterConfig = ReporterConfiguration.FromEnv(_loggerFactory); Assert.True(reporterConfig.LogSpans); Assert.Equal("MyHost", reporterConfig.SenderConfig.AgentHost); Assert.Equal(1234, reporterConfig.SenderConfig.AgentPort); Assert.Equal(TimeSpan.FromMilliseconds(500), reporterConfig.FlushInterval); Assert.Equal(1000, reporterConfig.MaxQueueSize); }
public void TestReporterConfigurationFromIConfiguration() { var arrayDict = new Dictionary <string, string> { { Configuration.JaegerReporterLogSpans, "X" }, }; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(arrayDict) .Build(); ReporterConfiguration reporterConfig = ReporterConfiguration.FromIConfiguration(_loggerFactory, configuration); Assert.False(reporterConfig.LogSpans); }
public Tracer.Builder GetTracerBuilder() { if (ReporterConfig == null) { ReporterConfig = new ReporterConfiguration(_loggerFactory); } if (SamplerConfig == null) { SamplerConfig = new SamplerConfiguration(_loggerFactory); } if (CodecConfig == null) { CodecConfig = new CodecConfiguration(_loggerFactory); } if (_metricsFactory == null) { _metricsFactory = NoopMetricsFactory.Instance; } IMetrics metrics = new MetricsImpl(_metricsFactory); IReporter reporter = ReporterConfig.GetReporter(metrics); ISampler sampler = SamplerConfig.GetSampler(ServiceName, metrics); Tracer.Builder builder = new Tracer.Builder(ServiceName) .WithLoggerFactory(_loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .WithMetrics(metrics) .WithTags(_tracerTags); if (UseTraceId128Bit) { builder = builder.WithTraceId128Bit(); } CodecConfig.Apply(builder); return(builder); }
public Configuration WithReporter(ReporterConfiguration reporterConfig) { ReporterConfig = reporterConfig; return(this); }