/// <summary> /// Подключение и настройка экземпляра объекта Jaeger.Tracer. /// С помощью AddSingleton() для добавления нового сервиса в /// контейнер дескрипторов. /// </summary> /// <param name="services"></param> /// <param name="setupAction"></param> /// <returns></returns> public static IServiceCollection AddTracing( this IServiceCollection services, Action <JaegerTracingOptions> setupAction = null) { if (setupAction != null) { services.ConfigureTracing(setupAction); } services.AddSingleton <ITracer>(x => { var options = x.GetService <IOptions <JaegerTracingOptions> >().Value; var tracer = ConfigureJaegerTracer(options); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return(tracer); }); services.AddOpenTracing(); return(services); }
public static IServiceCollection AddJaeger(this IServiceCollection services) { services.AddOpenTracing(); services.AddSingleton(serviceProvider => { var serviceName = Assembly.GetEntryAssembly().GetName().Name; var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var jaegerOptions = serviceProvider.GetRequiredService <IOptions <JaegerOptions> >(); Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", serviceName); Environment.SetEnvironmentVariable("JAEGER_AGENT_HOST", jaegerOptions.Value.Host); Environment.SetEnvironmentVariable("JAEGER_AGENT_PORT", jaegerOptions.Value.Port); ITracer tracer = new Tracer.Builder(serviceName) .WithLoggerFactory(loggerFactory) .WithSampler(new ConstSampler(sample: true)) .Build(); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return(tracer); }); //Evita loops infinitos quando o OpenTracing estiver rastreando solicitações HTTP para o Jaeger. services.Configure <HttpHandlerDiagnosticOptions>(options => { options.IgnorePatterns.Add(x => !x.RequestUri.IsLoopback); options.IgnorePatterns.Add(request => _jaegerUri.IsBaseOf(request.RequestUri)); }); 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(); string mysqlHost = Environment.GetEnvironmentVariable("MYSQL_DB_HOST"); string password = Environment.GetEnvironmentVariable("MYSQL_DB_PASSWORD"); string connectionString = String.Format("server={0};uid=root;password={1};port=3306;database=nagp_db;", mysqlHost, password); services.AddDbContext <UserDbContext>( options => options.UseMySql(connectionString)); services.AddSingleton(serviceProvider => { var loggerFactory = new LoggerFactory(); //Get configurations from environment variables var config = Jaeger.Configuration.FromEnv(loggerFactory); var tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); } return(tracer); }); services.AddOpenTracing(); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSingleton <ITracer>(cli => { Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", Configuration["LatencyTrace:JAEGER_SERVICE_NAME"]); Environment.SetEnvironmentVariable("JAEGER_AGENT_HOST", Configuration["LatencyTrace:JAEGER_AGENT_HOST"]); Environment.SetEnvironmentVariable("JAEGER_AGENT_PORT", Configuration["LatencyTrace:JAEGER_AGENT_PORT"]); Environment.SetEnvironmentVariable("JAEGER_SAMPLER_TYPE", Configuration["LatencyTrace:JAEGER_SAMPLER_TYPE"]); var loggerFactory = new LoggerFactory(); var config = Jaeger.Configuration.FromEnv(loggerFactory); var tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { // 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.AddHttpClient(); services.AddControllers(); services.AddSingleton <ITracer>(serviceProvider => { var serviceName = Assembly.GetEntryAssembly().GetName().Name; 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. if (GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return(tracer); }); services.Configure <HttpHandlerDiagnosticOptions>(options => options.IgnorePatterns.Add(x => !x.RequestUri.IsLoopback)); }
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", Configuration["JAEGER_SERVICE_NAME"]); Environment.SetEnvironmentVariable("JAEGER_AGENT_HOST", Configuration["JAEGER_AGENT_HOST"]); Environment.SetEnvironmentVariable("JAEGER_AGENT_PORT", Configuration["JAEGER_AGENT_PORT"]); Environment.SetEnvironmentVariable("JAEGER_SAMPLER_TYPE", Configuration["JAEGER_SAMPLER_TYPE"]); services.AddOpenTracing(); services.AddSingleton(serviceProvider => { var loggerFactory = new LoggerFactory(); var config = Jaeger.Configuration.FromEnv(loggerFactory); var tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return(tracer); }); services.AddEventBusSQS(Configuration) .AddOpenTracing(); services.AddHealthChecks() .AddSqsCheck <WeatherInEvent>(); }
public static IServiceCollection AddDistributedTracing(this IServiceCollection services, IConfiguration configuration) { services.AddOpenTracing(builder => { builder.ConfigureAspNetCore(options => { options.Hosting.IgnorePatterns.Add(x => { return( x.Request.Path == "/swagger" || x.Request.Path == "/swagger/index.html" || x.Request.Path == "/swagger/favicon-16x16.png" || x.Request.Path == "/swagger/v1/swagger.json" || x.Request.Path == "/ops/metrics" || x.Request.Path == "/ops/health" ); }); }); }); ILoggerFactory loggerFactory = services.BuildServiceProvider().GetRequiredService <ILoggerFactory>(); return(services.AddSingleton(serviceProvider => { var config = Jaeger.Configuration.FromIConfiguration(loggerFactory, configuration); var tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return tracer; })); }
public static IServiceCollection AddJaegerOpenTracing(this IServiceCollection services, IConfiguration configuration) { Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", configuration["JAEGER_SERVICE_NAME"]); Environment.SetEnvironmentVariable("JAEGER_AGENT_HOST", configuration["JAEGER_AGENT_HOST"]); Environment.SetEnvironmentVariable("JAEGER_AGENT_PORT", configuration["JAEGER_AGENT_PORT"]); Environment.SetEnvironmentVariable("JAEGER_SAMPLER_TYPE", configuration["JAEGER_SAMPLER_TYPE"]); services.AddSingleton(serviceProvider => { var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var config = Jaeger.Configuration.FromEnv(loggerFactory); var tracer = config.GetTracer(); 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); }
public override void OnEntry(MethodExecutionArgs args) { if (!GlobalTracer.IsRegistered()) { return; } var operationName = $"{args.Method.Name}.{args.Method.ReflectedType.Name}"; var tracer = GlobalTracer.Instance; var spanBuilder = tracer.BuildSpan(operationName); if (tracer.ActiveSpan != null) { spanBuilder.AsChildOf(tracer.ActiveSpan); } else if (TracerHttpHeaders.Value != null) { // check http var parentSpanCtx = tracer.Extract(BuiltinFormats.HttpHeaders, new TextMapExtractAdapter(TracerHttpHeaders.Value)); spanBuilder.AsChildOf(parentSpanCtx); } var activeScope = spanBuilder.StartActive(true); args.MethodExecutionTag = activeScope; }
/// <summary> /// Add Jaeger service. /// </summary> /// <param name="services">DI container.</param> /// <param name="configuration">Application configuration.</param> /// <param name="environment">Application environment.</param> /// <returns>Services with configured Jaeger.</returns> public static IServiceCollection AddJaegerService(this IServiceCollection services, IConfiguration configuration, IHostEnvironment environment) { var jaegerSettingsSection = configuration.GetSection("JaegerSettings"); services.Configure <JaegerSettings>(jaegerSettingsSection); var jaegerSettings = jaegerSettingsSection.Get <JaegerSettings>(); var agentHost = environment.IsProduction() ? jaegerSettings.DockerAgentHost : jaegerSettings.DefaultAgentHost; services.AddSingleton(serviceProvider => { Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", jaegerSettings.ServiceName); Environment.SetEnvironmentVariable("JAEGER_AGENT_HOST", agentHost); Environment.SetEnvironmentVariable("JAEGER_AGENT_PORT", jaegerSettings.AgentPort); Environment.SetEnvironmentVariable("JAEGER_SAMPLER_TYPE", jaegerSettings.SamplerType); var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var config = Configuration.FromEnv(loggerFactory); var tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return(tracer); }); return(services); }
//public static void Main(string[] args) public static async Task <int> Main(string[] args) { var tracer = GlobalTracer.Instance; Console.WriteLine(tracer.ToString()); Console.WriteLine(GlobalTracer.IsRegistered()); using (IScope scope = tracer.BuildSpan("ConversionRequestParent").StartActive(finishSpanOnDispose: false)) { var span = scope.Span; Console.WriteLine("lets go !"); for (int i = 0; i < 100; i++) { span.SetTag("amount", i); Thread.Sleep(30); SfxCurrencyConverter.s_instance.DoConversion(i); var ba = new Uri("http://localhost:5000/"); var c = new HttpClient { BaseAddress = ba }; //await c.GetAsync("default-handler"); await Task.Delay(100); } } Thread.Sleep(3000); return(0); }
public static IServiceCollection AddJnzTracer(this IServiceCollection services) { services.TryAddSingleton(serviceProvider => { var loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>(); var configuration = serviceProvider.GetRequiredService <IConfiguration>(); var senderResolver = new Jaeger.Senders.SenderResolver(loggerFactory); Jaeger.Configuration.SenderConfiguration .DefaultSenderResolver = senderResolver.RegisterSenderFactory <ThriftSenderFactory>(); var config = Jaeger.Configuration.FromIConfiguration(loggerFactory, configuration.GetSection("Jaeger")); var tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return(tracer); }); services.AddOpenTracing(); return(services); }
public void OneTimeSetUp() { _tracer = new MockTracer(); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(_tracer); } _singleValueHeaders = new Dictionary <string, string> { { "X-Forwarded-Port", "1234" }, { "X-Forwarded-Proto", "proto" }, { "Content-Type", "application/json" }, { "Content-Length", "1000" }, { "Access-Control-Allow-Origin", "*" }, { "Custom-Header", "CustomValue" }, { "newrelic", "dt-payload" }, }; _tags = new Dictionary <string, string> { { "testTag", "1234" }, }; AwsServiceHandler.UseDTWrapperValueFactory = new Func <bool>(() => true); }
public static async Task <int> Main(string[] args) { var tracer = GlobalTracer.Instance; Console.WriteLine(System.ComponentModel.TypeDescriptor.GetClassName(tracer)); Console.WriteLine(GlobalTracer.IsRegistered()); int x = 0; while (x < 10000) { string parentnum = x.ToString(); string parent = "parent" + parentnum; using (IScope scope = tracer.BuildSpan(parent).WithTag(Tags.SpanKind.Key, Tags.SpanKindServer).StartActive(finishSpanOnDispose: true)) { var span = scope.Span; span.SetTag("MyImportantTag", "MyImportantValue"); span.Log("My Important Log Statement"); x++; Thread.Sleep(50); Console.WriteLine(parent); var ba = new Uri("http://localhost:5000/"); var c = new HttpClient { BaseAddress = ba }; await c.GetAsync("default-handler"); } } Thread.Sleep(2000); return(0); }
public void IsRegistered_returns_true_after_registration() { Assert.False(GlobalTracer.IsRegistered()); GlobalTracer.Register(Substitute.For <ITracer>()); Assert.True(GlobalTracer.IsRegistered()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var elasticSettings = new ElasticSettings(); Configuration.GetSection("Elastic").Bind(elasticSettings); var node = new Uri("http://" + elasticSettings.ServerName.Replace("http://", "")); var settings = new ConnectionSettings(node); if (!string.IsNullOrEmpty(elasticSettings.UserName) || !string.IsNullOrEmpty(elasticSettings.Password)) { settings.BasicAuthentication(elasticSettings.UserName, elasticSettings.Password); } settings.DefaultMappingFor(typeof(ElasticIdentityUser), m => m.IndexName("users")); var elasticClient = new ElasticClient(settings); services.AddIdentity <ElasticIdentityUser, ElasticIdentityUserRole>() .AddElasticIdentity(elasticClient) .AddDefaultTokenProviders(); services.AddAuthentication(options => { options.DefaultSignInScheme = IdentityConstants.ExternalScheme; }); // Hosting doesn't add IHttpContextAccessor by default services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddOptions(); services.AddDataProtection(); // Add application services. services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddTransient <ISmsSender, AuthMessageSender>(); services.AddMvc(x => { x.EnableEndpointRouting = false; }); services.AddSingleton <ITracer>(cli => { Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", "ElasticIdentity.Sample.Mvc"); var loggerFactory = new LoggerFactory(); var config = Jaeger.Configuration.FromEnv(loggerFactory); var tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); } return(tracer); }); }
public bool IsEnabled(LogLevel logLevel) { // Filtering should be done via the general Logging filtering feature. ITracer tracer = _globalTracerAccessor.GetGlobalTracer(); return(!( (tracer is NoopTracer) || (tracer is GlobalTracer && !GlobalTracer.IsRegistered()))); }
static async Task Main(string[] args) { var connStr = @"Data Source=(LocalDB)\MSSQLLocalDB;Integrated Security=True;Database=TestSandbox"; IHost host = new HostBuilder() .ConfigureServices(collection => { collection.AddTransient <IDapperContext>(provider => new DapperContext(connStr)); collection.AddTransient <IDbManager, DbManager>(); collection.AddOpenTracing(builder => { builder .AddBcl() .AddSqlClient() .AddLoggerProvider(); }); collection.AddSingleton <ITracer>(cli => { string applicationName = "SandboxSqlClient"; string environment = "Test"; string jaegerAgentHost = "localhost"; Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", applicationName); Environment.SetEnvironmentVariable("JAEGER_AGENT_HOST", jaegerAgentHost); Environment.SetEnvironmentVariable("JAEGER_AGENT_PORT", "6831"); Environment.SetEnvironmentVariable("JAEGER_SAMPLER_TYPE", "const"); var loggerFactory = new LoggerFactory(); Jaeger.Configuration config = Jaeger.Configuration.FromEnv(loggerFactory); config.WithTracerTags(new Dictionary <string, string>() { { "environment", environment } }); ITracer tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return(tracer); }); }).UseConsoleLifetime().Build(); await host.StartAsync(); var dbManager = host.Services.GetService <IDbManager>(); dbManager.CreateDb(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Book Reviews API", Version = "v1" }); }); //HealthChecks services.AddHealthChecks() .AddCheck <ReviewsHealthCheck>("reviews_health_check", failureStatus: HealthStatus.Unhealthy, tags: new[] { Readiness }) .AddCheck <DetailsHealthCheck>("details_health_check", failureStatus: HealthStatus.Unhealthy, tags: new[] { Readiness }); services.AddOpenTracing(); // Adds the Jaeger Tracer. services.AddSingleton <ITracer>(serviceProvider => { string serviceName = serviceProvider.GetRequiredService <Microsoft.AspNetCore.Hosting.IWebHostEnvironment>().ApplicationName; if (System.Environment.GetEnvironmentVariable("JAEGER_SERVICE_NAME") == null) { Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", serviceName); } if (System.Environment.GetEnvironmentVariable("JAEGER_AGENT_HOST") == null) { Environment.SetEnvironmentVariable("JAEGER_AGENT_HOST", "localhost"); } if (System.Environment.GetEnvironmentVariable("JAEGER_AGENT_PORT") == null) { Environment.SetEnvironmentVariable("JAEGER_AGENT_PORT", "6831"); } if (System.Environment.GetEnvironmentVariable("JAEGER_SAMPLER_TYPE") == null) { Environment.SetEnvironmentVariable("JAEGER_SAMPLER_TYPE", "const"); } var loggerFactory = new LoggerFactory(); var config = Jaeger.Configuration.FromEnv(loggerFactory); var tracer = config.GetTracer(); if (!GlobalTracer.IsRegistered()) { // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); } return(tracer); }); }
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); }
public override void OnExit(MethodExecutionArgs args) { if (!GlobalTracer.IsRegistered()) { return; } var operationName = $"{args.Method.Name}.{args.Method.ReflectedType.Name}"; var activeScope = args.MethodExecutionTag as IScope; activeScope.Dispose(); System.Diagnostics.Debug.WriteLine($"[{operationName}]:OnExit"); }
public void Init() { //If no global tracer is registered (not running with scope-run), we register the Noop tracer if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(NoopTracerFactory.Create()); } var loggerFactory = new LoggerFactory(); _logger = loggerFactory.CreateLogger <GeoIntegrationTest>(); }
public void RegisterIfAbsent_called_multiple_times_does_not_throw_exception() { Assert.False(GlobalTracer.IsRegistered()); for (var i = 0; i < 10; i++) { var tracer = Substitute.For <ITracer>(); GlobalTracer.RegisterIfAbsent(tracer); Assert.True(GlobalTracer.IsRegistered()); } }
public static bool IsNoopTracer(this ITracer tracer) { if (tracer is NoopTracer) { return(true); } if (tracer is GlobalTracer && !GlobalTracer.IsRegistered()) { return(true); } return(false); }
public void TestFromIConfig() { var arrayDict = new Dictionary <string, string> { { Configuration.JaegerServiceName, "Test" }, }; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(arrayDict) .Build(); Assert.NotNull(Configuration.FromIConfiguration(_loggerFactory, configuration).GetTracer()); Assert.False(GlobalTracer.IsRegistered()); }
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); }
// 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); }
public void TraceEnter( string methodInfo, string[] paramNames, object[] paramValues) { if (!GlobalTracer.IsRegistered()) { Trace.TraceError(Error.TracerNotRegisteredOnEnter); return; } GlobalTracer.Instance .BuildSpan($"{this.name}{methodInfo}") .StartActive(); }
public static IServiceCollection AddZipkin(this IServiceCollection services) { services.AddSingleton <ITracer>(serviceProvider => { var configuration = serviceProvider.GetRequiredService <IConfiguration>(); //var tracer = new ZipkinTracer(new ZipkinTracerOptions(new Endpoint(configuration["ZIPKIN_SERVICE_NAME"]), ZipkinKafkaSpanReporter.Create(new ZipkinKafkaReportingOptions(new[] { configuration["ZIPKIN_URL"] }, debugLogging: true)))); var tracer = new ZipkinTracer(new ZipkinTracerOptions(configuration["ZIPKIN_URL"], configuration["ZIPKIN_SERVICE_NAME"], debug: true)); if (!GlobalTracer.IsRegistered()) { GlobalTracer.Register(tracer); } return(tracer); }); return(services); }
public static bool IsNoopTracer(this ITracer tracer) { if (tracer is NoopTracer) { return(true); } // There's no way to check the underlying tracer on the instance so we have to check the static method. if (tracer is GlobalTracer && !GlobalTracer.IsRegistered()) { return(true); } return(false); }