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 StartStopExporter() { var config = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel(), }; var exporter = new ApplicationInsightsExporter(SpanExporter.Create(), Stats.Stats.ViewManager, config); exporter.Start(); await Task.Delay(100); var sw = Stopwatch.StartNew(); exporter.Stop(); sw.Stop(); Assert.InRange(sw.ElapsedMilliseconds, 0, 1000); }
internal static object Run() { SimpleEventQueue eventQueue = new SimpleEventQueue(); ExportComponent exportComponent = ExportComponent.CreateWithInProcessStores(eventQueue); TelemetryConfiguration.Active.InstrumentationKey = "instrumentation-key"; var exporter = new ApplicationInsightsExporter(exportComponent, Stats.ViewManager, TelemetryConfiguration.Active); exporter.Start(); var tagContextBuilder = Tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5")); var spanBuilder = Tracer .SpanBuilder("incoming request") .SetRecordEvents(true) .SetSampler(Samplers.AlwaysSample); Stats.ViewManager.RegisterView(VideoSizeView); using (tagContextBuilder.BuildScoped()) { using (Tracer.WithSpan(spanBuilder.StartSpan())) { Tracer.CurrentSpan.AddEvent("Start processing video."); Thread.Sleep(TimeSpan.FromMilliseconds(10)); StatsRecorder.NewMeasureMap().Put(VideoSize, 25 * MiB).Record(); Tracer.CurrentSpan.AddEvent("Finished processing video."); } } Thread.Sleep(TimeSpan.FromMilliseconds(5100)); var viewData = Stats.ViewManager.GetView(VideoSizeViewName); Console.WriteLine(viewData); Console.WriteLine("Done... wait for events to arrive to backend!"); Console.ReadLine(); exportComponent.SpanExporter.Dispose(); return(null); }