internal static object Run() { Console.WriteLine("Hello World!"); var collector = new DependenciesCollector(new DependenciesCollectorOptions(), tracer, Samplers.AlwaysSample); var exporter = new ZipkinTraceExporter( new ZipkinTraceExporterOptions() { Endpoint = new Uri("https://zipkin.azurewebsites.net/api/v2/spans"), ServiceName = typeof(Program).Assembly.GetName().Name, }, Tracing.ExportComponent); exporter.Start(); var scope = tracer.SpanBuilder("incoming request").SetSampler(Samplers.AlwaysSample).StartScopedSpan(); //Thread.Sleep(TimeSpan.FromSeconds(1)); HttpClient client = new HttpClient(); var t = client.GetStringAsync("http://bing.com"); t.Wait(); scope.Dispose(); Console.ReadLine(); return(null); }
internal static object Run() { Console.WriteLine("Hello World!"); var exporter = new ZipkinTraceExporter( new ZipkinTraceExporterOptions() { Endpoint = new Uri("https://zipkin.azurewebsites.net/api/v2/spans"), ServiceName = typeof(Program).Assembly.GetName().Name, }); var tracerFactory = new TracerFactory(new BatchingSpanProcessor(exporter)); var tracer = tracerFactory.GetTracer(nameof(HttpClientCollector)); using (new HttpClientCollector(new HttpClientCollectorOptions(), tracer)) { using (tracer.WithSpan(tracer.SpanBuilder("incoming request").SetSampler(Samplers.AlwaysSample).StartSpan())) { using (var client = new HttpClient()) { client.GetStringAsync("http://bing.com").GetAwaiter().GetResult(); } } Console.ReadLine(); exporter.ShutdownAsync(CancellationToken.None).GetAwaiter().GetResult(); 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 tracer = new Tracer(new BatchingSpanProcessor(exporter), TraceConfig.Default); // 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(i, 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() { Console.WriteLine("Hello World!"); using (new DependenciesCollector(new DependenciesCollectorOptions(), Tracer, Samplers.AlwaysSample)) { var exporter = new ZipkinTraceExporter( new ZipkinTraceExporterOptions() { Endpoint = new Uri("https://zipkin.azurewebsites.net/api/v2/spans"), ServiceName = typeof(Program).Assembly.GetName().Name, }, Tracing.ExportComponent); exporter.Start(); using (Tracer.WithSpan(Tracer.SpanBuilder("incoming request").SetSampler(Samplers.AlwaysSample).StartSpan())) { using (var client = new HttpClient()) { client.GetStringAsync("http://bing.com").GetAwaiter().GetResult(); } } Console.ReadLine(); return(null); } }
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); }
private static void ConfigureOpencensus(string zipkinUri, string appInsightsKey) { //if we want to have multiple tracers //we should use agent mode and send first to agent var ocExp = new OpenCensus.Exporter.Ocagent.OcagentExporter( Tracing.ExportComponent , "http://localhost:55678" , Environment.MachineName , "distributedtracingdemo" ); ocExp.Start(); if (!string.IsNullOrEmpty(zipkinUri)) { var zipK = new ZipkinTraceExporter( new ZipkinTraceExporterOptions() { Endpoint = new Uri(zipkinUri), ServiceName = "tracing-to-zipkin-service", }, Tracing.ExportComponent ); zipK.Start(); } if (!string.IsNullOrEmpty(appInsightsKey)) { var config = new TelemetryConfiguration(appInsightsKey); var appI = new ApplicationInsightsExporter( Tracing.ExportComponent, Stats.ViewManager, config); appI.Start(); } //Metrics //define the measure to be used // context fields defined, that will be attached var invokeView = View.Create(ViewName.Create("executioncounts"), "Number of execs", numberofInvocations, Count.Create(), new[] { tagEnv, tagMachine }); //register Stats.ViewManager.RegisterView(invokeView); // 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); }
public async Task ZipkinExporter_ExportAsync() { var zipkinExporter = new ZipkinTraceExporter( new ZipkinTraceExporterOptions { Endpoint = new Uri($"http://{this.serverHost}:{this.serverPort}"), }); var spans = new List <SpanData>(); for (int i = 0; i < this.NumberOfSpans; i++) { spans.Add(this.testSpan); } await zipkinExporter.ExportAsync(spans, CancellationToken.None).ConfigureAwait(false); }
private SpanExporter?CreateSpanExporter(ReplicaInfo replicaInfo) { if (string.Equals(_provider.Key, "zipkin", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(_provider.Value)) { var zipkin = new ZipkinTraceExporter(new ZipkinTraceExporterOptions() { ServiceName = replicaInfo.Service, Endpoint = new Uri($"{_provider.Value.TrimEnd('/')}/api/v2/spans") }); return(zipkin); } // TODO: Support Jaegar // TODO: Support ApplicationInsights return(null); }
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 var traceConfig = Tracing.TraceConfig; var 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; // 4. 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(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); }
static void ZipkinTest() { var exporter = new ZipkinTraceExporter( new ZipkinTraceExporterOptions() { Endpoint = new Uri("http://172.16.12.254:9411"), ServiceName = typeof(Program).Assembly.GetName().Name }, OpenTelemetry.Trace.Tracing.ExportComponent ); exporter.Start(); var traceConfig = Tracing.TraceConfig; var traceParams = traceConfig.ActiveTraceParams; var newConfig = traceParams.ToBuilder() .SetSampler(Samplers.AlwaysSample) .Build(); traceConfig.UpdateActiveTraceParams(newConfig); var tracer = Tracing.Tracer; var span = tracer.CurrentSpan; { var attrs = new Dictionary<string, IAttributeValue>() { ["param1"] = AttributeValue.LongAttributeValue(128) }; span.AddEvent("hogepiyo", attrs); } using (var scope = tracer.SpanBuilder("DoWork", SpanKind.Client).StartScopedSpan()) { var attrs = new Dictionary<string, IAttributeValue>() { ["param1"] = AttributeValue.LongAttributeValue(256) }; tracer.CurrentSpan.AddEvent("hogepiyo", attrs); } Tracing.ExportComponent.SpanExporter.Dispose(); Console.WriteLine("Hello World!"); }
public static object Run(string zipkinUri) { // 1. Configure exporter to export traces to Zipkin var exporter = new ZipkinTraceExporter( new ZipkinTraceExporterOptions() { Endpoint = new Uri(zipkinUri), ServiceName = "trace-A", }, 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); //Build application // Microsoft.Identity.Client var confidentialClientApplication = PublicClientApplicationBuilder .Create("efe9af1d-0c2a-499e-bc4c-1d23c22a8a87") .Build(); // Microsoft.Graph.auth DeviceCodeProvider authenticationProvider = new DeviceCodeProvider(confidentialClientApplication); var config = new GraphTelemetryConfiguration(); config.LatencyConfig = new LatencyConfig { authenticationLatencyIsEnabled = true, compressionHandlerLatencyIsEnabled = true, }; var client = new GraphServiceClient(authenticationProvider: authenticationProvider, config: config); using (var scope = Tracing.Tracer.SpanBuilder("'v1.0/me' full request latency ").StartScopedSpan()) { var user = client.Me.Request().GetAsync().GetAwaiter().GetResult(); Console.WriteLine("Succesfully captured full latency of /me"); } //using (var scope = Tracing.Tracer.SpanBuilder("v1.0/me/Drive/Root/Children ").StartScopedSpan()) //{ // var driveItemsStream = client.Me.Drive.Items["01ZJ3LUMVJPVXOFF43LVA23PKLT3KRFL54"].Content.Request().GetAsync().GetAwaiter().GetResult(); //} Tracing.ExportComponent.SpanExporter.Dispose(); return(null); }