internal static object Run() { var config = new TelemetryConfiguration { InstrumentationKey = "instrumentation-key" }; SpanExporter exporter = new ApplicationInsightsTraceExporter(config); var metricExporter = new ApplicationInsightsMetricExporter(Stats.ViewManager, config); metricExporter.Start(); var tagContextBuilder = Tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5")); var tracerFactory = new TracerFactory(new BatchingSpanProcessor(exporter)); var tracer = tracerFactory.GetTracer(string.Empty); 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(); exporter.ShutdownAsync(CancellationToken.None).GetAwaiter().GetResult(); metricExporter.Stop(); return(null); }
public async Task StartStopExporter() { var config = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel(), }; var exporter = new ApplicationInsightsMetricExporter(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() { var metricExporter = new ApplicationInsightsMetricExporter(Stats.ViewManager, new TelemetryConfiguration("instrumentation-key")); metricExporter.Start(); var tagContextBuilder = Tagger.CurrentBuilder.Put(FrontendKey, TagValue.Create("mobile-ios9.3.5")); using (var tracerFactory = TracerFactory.Create(builder => builder .UseApplicationInsights(config => config.InstrumentationKey = "instrumentation-key"))) { var tracer = tracerFactory.GetTracer("application-insights-test"); var span = tracer.StartSpan("incoming request"); Stats.ViewManager.RegisterView(VideoSizeView); using (tagContextBuilder.BuildScoped()) { using (tracer.WithSpan(span)) { 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(); metricExporter.Stop(); return(null); } }