This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
TestApplicationInsights.cs
73 lines (58 loc) · 2.81 KB
/
TestApplicationInsights.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
namespace Samples
{
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.ApplicationInsights.Extensibility;
using OpenCensus.Exporter.ApplicationInsights;
using OpenCensus.Stats;
using OpenCensus.Stats.Aggregations;
using OpenCensus.Stats.Measures;
using OpenCensus.Tags;
using OpenCensus.Trace;
using OpenCensus.Trace.Sampler;
internal class TestApplicationInsights
{
private static ITracer tracer = Tracing.Tracer;
private static ITagger tagger = Tags.Tagger;
private static IStatsRecorder statsRecorder = Stats.StatsRecorder;
private static readonly IMeasureLong VideoSize = MeasureLong.Create("my.org/measure/video_size", "size of processed videos", "By");
private static readonly ITagKey FrontendKey = TagKey.Create("my.org/keys/frontend");
private static long MiB = 1 << 20;
private static readonly IViewName VideoSizeViewName = ViewName.Create("my.org/views/video_size");
private static readonly IView VideoSizeView = View.Create(
VideoSizeViewName,
"processed video size over time",
VideoSize,
Distribution.Create(BucketBoundaries.Create(new List<double>() { 0.0, 16.0 * MiB, 256.0 * MiB })),
new List<ITagKey>() { FrontendKey });
internal static object Run()
{
TelemetryConfiguration.Active.InstrumentationKey = "instrumentation-key";
var exporter = new ApplicationInsightsExporter(Tracing.ExportComponent, Stats.ViewManager, TelemetryConfiguration.Active);
exporter.Start();
ITagContextBuilder 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 (var scopedTags = tagContextBuilder.BuildScoped())
{
using (var scopedSpan = spanBuilder.StartScopedSpan())
{
tracer.CurrentSpan.AddAnnotation("Start processing video.");
Thread.Sleep(TimeSpan.FromMilliseconds(10));
statsRecorder.NewMeasureMap().Put(VideoSize, 25 * MiB).Record();
tracer.CurrentSpan.AddAnnotation("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();
return null;
}
}
}