// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext <UserDBContext>(options => options .UseMySQL(Configuration.GetConnectionString("DefaultConnection"))); services.AddTransient <IUserData, UserDataAccess>(); // Adds the Jaeger Tracer. services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); var jeagerurl = "jaeger-agent"; var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) .WithSender(new UdpSender(jeagerurl, 6831, 0)) .Build(); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .Build(); GlobalTracer.Register(tracer); return(tracer); }); //Adds Jaegar Service services.AddOpenTracing(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddTransient <IOrderDetails, SqlOrderDetails>(); var url = Environment.GetEnvironmentVariable("UserServiceUrl"); services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); var jeagerurl = Environment.GetEnvironmentVariable("JaegerURL") ?? ""; var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) .WithSender(new UdpSender("127.0.0.1", 6831, 0)) .Build(); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); }
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); // OpenTracing Tracer if (Configuration.GetSection("OpenTracing:Agent").Exists()) { string agentHost = Configuration.GetSection("OpenTracing:Agent").GetValue<string>("Host"); int agentPort = Configuration.GetSection("OpenTracing:Agent").GetValue<int>("Port"); int agentMaxPacketSize = Configuration.GetSection("OpenTracing:Agent").GetValue<int>("MaxPacketSize"); var reporter = new RemoteReporter.Builder() .WithSender(new UdpSender(string.IsNullOrEmpty(agentHost) ? UdpSender.DefaultAgentUdpHost : agentHost, agentPort <= 0 ? UdpSender.DefaultAgentUdpCompactPort : agentPort, agentMaxPacketSize <= 0 ? 0 : agentMaxPacketSize)) .Build(); ITracer tracer = new Tracer.Builder(Assembly.GetEntryAssembly().GetName().Name) // service name .WithReporter(reporter) .WithSampler(new ConstSampler(true)) // always send the span .Build(); GlobalTracer.Register(tracer); // ×¢ÈëTracer services.AddSingleton(tracer); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) .WithSender(new UdpSender(Environment.GetEnvironmentVariable("JAEGERUI") != null ? Environment.GetEnvironmentVariable("JAEGERUI") : "jaegerui", 6831, 0)) .Build(); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddOpenTracing(); services.AddOptions(); services.AddSingleton <IOrderBDC, OrderBDC.Classes.OrderBDC>(); }
public void TestTraceId64Bit() { var tracer = new Tracer.Builder("name") .Build(); Assert.False(tracer.UseTraceId128Bit); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddOpenTracing(); services.AddTransient <HttpClient>(); // Adds the Jaeger Tracer. services.AddSingleton <ITracer>(serviceProvider => { string serviceName = serviceProvider.GetRequiredService <IHostingEnvironment>().ApplicationName; // This will log to a default localhost installation of Jaeger. var tracer = new Tracer.Builder(serviceName) .WithSampler(new ConstSampler(true)) .Build(); // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); return(tracer); }); // Prevent endless loops when OpenTracing is tracking HTTP requests to Jaeger. services.Configure <HttpHandlerDiagnosticOptions>(options => { options.IgnorePatterns.Add(x => !x.RequestUri.IsLoopback); }); }
public static IServiceCollection AddJaeger(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddSingleton <ITracer>(serviceProvider => { var serviceName = Assembly.GetEntryAssembly().GetName().Name; var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var sampler = new ConstSampler(sample: true); var tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); // Prevent endless loops when OpenTracing is tracking HTTP requests to Jaeger. services.Configure <HttpHandlerDiagnosticOptions>(options => { options.IgnorePatterns.Add(request => _jaegerUri.IsBaseOf(request.RequestUri)); }); return(services); }
public void TestActiveSpanAutoReference() { InMemoryReporter reporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("test") .WithReporter(reporter) .WithSampler(new ConstSampler(true)) .Build(); using (IScope parent = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true)) { tracer.BuildSpan("child").StartActive(finishSpanOnDispose: true).Dispose(); } Assert.Equal(2, reporter.GetSpans().Count); Span childSpan = reporter.GetSpans()[0]; Span parentSpan = reporter.GetSpans()[1]; Assert.Equal("child", childSpan.OperationName); Assert.Single(childSpan.GetReferences()); Assert.Equal("parent", parentSpan.OperationName); Assert.Empty(parentSpan.GetReferences()); Assert.Equal(References.ChildOf, childSpan.GetReferences()[0].Type); Assert.Equal(parentSpan.Context, childSpan.GetReferences()[0].Context); Assert.Equal(parentSpan.Context.TraceId, childSpan.Context.TraceId); Assert.Equal(parentSpan.Context.SpanId, childSpan.Context.ParentId); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext <UserDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("UserDBConnection"))); services.AddScoped <IUserManager, UserManager>(); services.AddScoped <IUserDal, UserDal>(); services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); var reporter = new RemoteReporter.Builder().WithLoggerFactory(loggerFactory) .WithSender(new UdpSender("jaeger-agent", 6831, 0)).Build(); ITracer tracer = new Tracer.Builder(serviceName).WithLoggerFactory(loggerFactory). WithSampler(sampler).WithReporter(reporter).Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); Jaeger.Configuration.SenderConfiguration.DefaultSenderResolver = new SenderResolver(loggerFactory) .RegisterSenderFactory <ThriftSenderFactory>(); ISampler sampler = new ConstSampler(sample: true); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); services.AddHttpClient <UsersAPIClient>((client) => client.BaseAddress = new Uri(Configuration["UsersAPIUri"] + "api/")); services.AddHttpClient <OrdersAPIClient>((client) => client.BaseAddress = new Uri(Configuration["OrdersAPIUri"] + "api/")); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "OrderDetailsAPI", Version = "v1" }); }); }
public void TestNoAutoRefWithExistingRefs() { InMemoryReporter reporter = new InMemoryReporter(); Tracer tracer = new Tracer.Builder("test") .WithReporter(reporter) .WithSampler(new ConstSampler(true)) .Build(); ISpan initialSpan = tracer.BuildSpan("initial").Start(); using (IScope parent = tracer.BuildSpan("parent").StartActive(finishSpanOnDispose: true)) { tracer.BuildSpan("child").AsChildOf(initialSpan.Context).StartActive(finishSpanOnDispose: true).Dispose(); } initialSpan.Finish(); Assert.Equal(3, reporter.GetSpans().Count); Span childSpan = reporter.GetSpans()[0]; Span parentSpan = reporter.GetSpans()[1]; Span initSpan = reporter.GetSpans()[2]; Assert.Empty(initSpan.GetReferences()); Assert.Empty(parentSpan.GetReferences()); Assert.Equal(initSpan.Context.TraceId, childSpan.Context.TraceId); Assert.Equal(initSpan.Context.SpanId, childSpan.Context.ParentId); Assert.Equal(0L, initSpan.Context.ParentId); Assert.Equal(0L, parentSpan.Context.ParentId); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddScoped <IAggregatorService, AggregatorService>(); services.AddSingleton <ITracer>(serviceProvider => { string serviceName = serviceProvider.GetRequiredService <IWebHostEnvironment>().ApplicationName; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); string jaegerHost = Configuration.GetValue <string>("Values:jaeger-host"); var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) .WithSender(new UdpSender(jaegerHost, 6831, 0)) // todo: .Build(); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); }
public static IServiceCollection AddJaeger(this IServiceCollection services) { var options = GetJaegerOptions(services); if (!options.Enabled) { var defaultTracer = DShopDefaultTracer.Create(); services.AddSingleton(defaultTracer); return(services); } services.AddSingleton <ITracer>(sp => { var loggerFactory = sp.GetRequiredService <ILoggerFactory>(); var reporter = new RemoteReporter .Builder() .WithSender(new UdpSender(options.UdpHost, options.UdpPort, options.MaxPacketSize)) .WithLoggerFactory(loggerFactory) .Build(); var sampler = GetSampler(options); var tracer = new Tracer .Builder(options.ServiceName) .WithReporter(reporter) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); return(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext <ApplicationDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddScoped(typeof(IDbIntializer), typeof(DBInitializer)); services.AddSingleton <ITracer>(serviceProvider => { string serviceName = serviceProvider.GetRequiredService <IWebHostEnvironment>().ApplicationName; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); string jaegerHost = Configuration.GetValue <string>("Values:jaeger-host"); var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) .WithSender(new UdpSender(jaegerHost, 6831, 0)) // todo: .Build(); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddHttpClient(); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Customers API", Version = "v1" }); }); services.AddOpenTracing(); }
public void ConfigureServices(IServiceCollection services) { services.AddHttpClient(); services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); Jaeger.Configuration.SenderConfiguration.DefaultSenderResolver = new SenderResolver(loggerFactory) .RegisterSenderFactory <ThriftSenderFactory>(); ISampler sampler = new ConstSampler(sample: true); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); services.AddControllers(); services.AddDbContext <UsersDbContext>(options => options.UseMySQL(Configuration.GetConnectionString("UsersDB"))); services.AddScoped <UnitOfWork>(); services.AddHealthChecks(); services.AddSwaggerGen(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <RelatoriosRepository>(opt => opt.UseInMemoryDatabase("Relatorios")); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddOpenTracing(); // Adds the Jaeger Tracer. services.AddSingleton <ITracer>(serviceProvider => { string serviceName = serviceProvider.GetRequiredService <IHostingEnvironment>().ApplicationName; // This will log to a default localhost installation of Jaeger. var tracer = new Tracer.Builder(serviceName) .WithSampler(new ConstSampler(true)) .Build(); // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); return(tracer); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) .WithSender(new UdpSender("jagerservice", 6831, 0)) .Build(); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); // Use "OpenTracing.Contrib.NetCore" to automatically generate spans for ASP.NET Core, Entity Framework Core, ... // See https://github.com/opentracing-contrib/csharp-netcore for details. services.AddOpenTracing(); // Adds the Jaeger Tracer. services.AddSingleton <ITracer>(serviceProvider => { var serviceName = serviceProvider.GetRequiredService <IWebHostEnvironment>().ApplicationName; var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); // This is necessary to pick the correct sender, otherwise a NoopSender is used! Jaeger.Configuration.SenderConfiguration.DefaultSenderResolver = new SenderResolver(loggerFactory) .RegisterSenderFactory <ThriftSenderFactory>(); // This will log to a default localhost installation of Jaeger. var tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(new ConstSampler(true)) .Build(); // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); return(tracer); }); }
/// <summary> /// Configures OpenTracing with Jaeger Instrumentation from Environment Variables /// https://github.com/jaegertracing/jaeger-client-csharp /// </summary> /// <remarks> /// The `JAEGER_SERVICE_NAME` variable is required to be set /// </remarks> /// <param name="services"></param> private void ConfigureOpenTracing(IServiceCollection services) { services.AddOpenTracing(); services.AddSingleton <ITracer>(serviceProvider => { ITracer tracer; try { tracer = Jaeger.Configuration.FromEnv(serviceProvider.GetService <ILoggerFactory>()).GetTracer(); } catch (ArgumentException ex) { if (ex.Message == "Service name must not be null or empty") { tracer = new Tracer.Builder(serviceProvider.GetRequiredService <IHostEnvironment>().ApplicationName) .WithSampler(new ConstSampler(false)) .Build(); } else { throw; } } GlobalTracer.Register(tracer); return(tracer); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddOpenTracing(); // Adds the Jaeger Tracer. services.AddSingleton <ITracer>(serviceProvider => { string serviceName = serviceProvider.GetRequiredService <IHostingEnvironment>().ApplicationName; var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var sampler = new ConstSampler(sample: true); var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) // optional, defaults to no logging //.WithMaxQueueSize(...) // optional, defaults to 100 //.WithFlushInterval(...) // optional, defaults to TimeSpan.FromSeconds(1) .WithSender(new UdpSender("192.168.1.172", 6831, 0)) // optional, defaults to UdpSender("localhost", 6831, 0) .Build(); // This will log to a default localhost installation of Jaeger. var tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .Build(); GlobalTracer.Register(tracer); return(tracer); }); }
public static void AddJaeger(this ContainerBuilder builder) { builder.Register(context => { var configuration = context.Resolve <IConfiguration>(); var options = new JaegerOptions(); configuration.GetSection("jaeger").Bind(options); return(options); }).SingleInstance(); builder.Register <ITracer>(context => { var loggerFactory = context.Resolve <ILoggerFactory>(); var options = context.Resolve <JaegerOptions>(); var reporter = new RemoteReporter .Builder() .WithSender(new UdpSender(options.UdpHost, options.UdpPort, options.MaxPacketSize)) .WithLoggerFactory(loggerFactory) .Build(); var sampler = GetSampler(options); var tracer = new Tracer .Builder(options.ServiceName) .WithReporter(reporter) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }).SingleInstance(); }
public Tracer GetTracer(string serviceName, ILoggerFactory loggerFactory) { if (CacheTracers.ContainsKey(serviceName)) { return(CacheTracers[serviceName]); } var traceBuilder = new Tracer.Builder(serviceName) .WithSampler(new ConstSampler(true)) .WithLoggerFactory(loggerFactory); //var loggerFactory = traceBuilder.LoggerFactory; var metrics = traceBuilder.Metrics; //try result: 16686:X 14268:OK var sender = new HttpSender(EndPoint); var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) .WithMetrics(metrics) .WithSender(sender) .Build(); var tracer = traceBuilder .WithReporter(reporter) .Build(); CacheTracers.Add(serviceName, tracer); return(tracer); }
public static IServiceCollection ConfigurationJaeger(this IServiceCollection services) { services.AddMvc(options => { options.Filters.AddService <TracingActionFilter>(); }); services.AddScoped <TracingActionFilter>(); services.AddSingleton(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); var reporter = new RemoteReporter.Builder().WithLoggerFactory(loggerFactory).WithSender(new UdpSender("jaeger_easy", 6831, 0)).Build(); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithReporter(reporter) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); return(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddTransient <RequestTracingHandler>(); services.AddHttpClient("default") .AddHttpMessageHandler <RequestTracingHandler>(); services.AddSingleton <ITracer>(serviceProvider => { var serviceName = serviceProvider .GetRequiredService <IHostingEnvironment>() .ApplicationName; var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var tracer = new Tracer.Builder(serviceName) .WithSampler(new ConstSampler(true)) .WithLoggerFactory(loggerFactory) .Build(); // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); return(tracer); }); services.Configure <HttpHandlerDiagnosticOptions>(options => { options.IgnorePatterns.Add(x => !x.RequestUri.IsLoopback); }); services.AddOpenTracing(b => b.AddAspNetCore()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddDiscoveryClient(Configuration); services.AddHttpClient <AggregatorController>(); services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddHttpClient(); services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); var reporter = new RemoteReporter.Builder() .WithLoggerFactory(loggerFactory) .WithSender(new UdpSender("jaeger-agent.default.svc.cluster.local", 6831, 0)) .Build(); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .WithReporter(reporter) .Build(); GlobalTracer.Register(tracer); return(tracer); }); services.AddOpenTracing(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
private void ConfigureServices(IServiceCollection services) { //services.AddSingleton<ILogBase>(provider => new LogBase(new FileInfo(@"c:\temp\log.txt"))); services.AddSingleton <MainWindow>(); services.AddSingleton <IAlumnadoService, AlumandoService>(); // Use "OpenTracing.Contrib.NetCore" to automatically generate spans for ASP.NET Core, Entity Framework Core, ... // See https://github.com/opentracing-contrib/csharp-netcore for details. services.AddOpenTracing(); // Adds the Jaeger Tracer. services.AddSingleton <ITracer>(serviceProvider => { string serviceName = "wpf-example"; // This will log to a default localhost installation of Jaeger. var tracer = new Tracer.Builder(serviceName) .WithSampler(new ConstSampler(true)) .Build(); // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); return(tracer); }); }
public static IServiceCollection AddJaeger(this IServiceCollection services) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddSingleton <ITracer>(serviceProvider => { string serviceName = Assembly.GetEntryAssembly().GetName().Name; ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); ISampler sampler = new ConstSampler(sample: true); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(sampler) .Build(); GlobalTracer.Register(tracer); return(tracer); }); return(services); }