internal static object Run(string zipkinUri) { // 1. Configure exporter to export traces to Zipkin var exporter = new ZipkinTraceExporter( new ZipkinTraceExporterOptions() { Endpoint = new Uri(zipkinUri), ServiceName = "tracing-to-zipkin-service", }, Tracing.ExportComponent); exporter.Start(); // 2. Configure 100% sample rate for the purposes of the demo ITraceConfig traceConfig = Tracing.TraceConfig; ITraceParams currentConfig = traceConfig.ActiveTraceParams; var newConfig = currentConfig.ToBuilder() .SetSampler(Samplers.AlwaysSample) .Build(); traceConfig.UpdateActiveTraceParams(newConfig); // 3. Tracer is global singleton. You can register it via dependency injection if it exists // but if not - you can use it as follows: var tracer = Tracing.Tracer; var collector = new StackExchangeRedisCallsCollector(null, tracer, null, Tracing.ExportComponent); // connect to the server ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("localhost:6379"); connection.RegisterProfiler(collector.GetProfilerSessionsFactory()); // select a database (by default, DB = 0) IDatabase db = connection.GetDatabase(); // 4. Create a scoped span. It will end automatically when using statement ends using (var scope = tracer.SpanBuilder("Main").StartScopedSpan()) { Console.WriteLine("About to do a busy work"); for (int i = 0; i < 10; i++) { DoWork(db, i); } } // 5. Gracefully shutdown the exporter so it'll flush queued traces to Zipkin. Tracing.ExportComponent.SpanExporter.Dispose(); return(null); }
internal static object Run(string zipkinUri) { // Configure exporter to export traces to Zipkin var exporter = new ZipkinTraceExporter( new ZipkinTraceExporterOptions() { Endpoint = new Uri(zipkinUri), ServiceName = "tracing-to-zipkin-service", }); // Create a tracer. You may also need to register it as a global instance to make auto-collectors work.. var tracerFactory = new TracerFactory(new BatchingSpanProcessor(exporter)); var tracer = tracerFactory.GetTracer(string.Empty); var collector = new StackExchangeRedisCallsCollector(tracer); // connect to the server var connection = ConnectionMultiplexer.Connect("localhost:6379"); connection.RegisterProfiler(collector.GetProfilerSessionsFactory()); // select a database (by default, DB = 0) var db = connection.GetDatabase(); // Create a scoped span. It will end automatically when using statement ends using (tracer.WithSpan(tracer.SpanBuilder("Main").StartSpan())) { Console.WriteLine("About to do a busy work"); for (var i = 0; i < 10; i++) { DoWork(db, tracer); } } // Gracefully shutdown the exporter so it'll flush queued traces to Zipkin. exporter.ShutdownAsync(CancellationToken.None).GetAwaiter().GetResult(); return(null); }
internal static object Run(string zipkinUri) { // connect to the server var connection = ConnectionMultiplexer.Connect("localhost:6379"); // Configure exporter to export traces to Zipkin using (var tracerFactory = TracerFactory.Create(builder => builder .UseZipkin(o => { o.ServiceName = "redis-test"; o.Endpoint = new Uri(zipkinUri); }) .AddCollector(t => { var collector = new StackExchangeRedisCallsCollector(t); connection.RegisterProfiler(collector.GetProfilerSessionsFactory()); return(collector); }))) { var tracer = tracerFactory.GetTracer("redis-test"); // select a database (by default, DB = 0) var db = connection.GetDatabase(); // Create a scoped span. It will end automatically when using statement ends using (tracer.StartActiveSpan("Main", out _)) { Console.WriteLine("About to do a busy work"); for (var i = 0; i < 10; i++) { DoWork(db, tracer); } } return(null); } }
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.Configure <RedisOptions>(o => Configuration.Bind("Redis", o)); services.AddSingleton <RedisStore>(); services.AddSingleton <MessageBus>(); services.AddGrpc(); services.AddOpenTelemetry((resolver, builder) => { builder.SetSampler(Samplers.AlwaysSample); builder.UseJaeger(o => Configuration.Bind("Jaeger", o)); builder .UseZipkin(o => Configuration.Bind("Zipkin", o)); builder .AddCollector(c => { using var scope = resolver.CreateScope(); var provider = scope.ServiceProvider; var connection = provider.GetService <RedisStore>()?.Connection; var collector = new StackExchangeRedisCallsCollector(c); connection.RegisterProfiler(collector.GetProfilerSessionsFactory()); return(collector); }) .AddRequestCollector() .AddDependencyCollector(); }); services.AddHttpClient(); }