Page 50 - MSDN Magazine, May 2017
P. 50

Figure 8 Number of Telemetry Items in Application Insights and Estimated Number of Originally Collected Items
default enables adaptive sampling when collecting data. All telemetry stored in the services has a column called itemCount. It represents the sampling ratio at the moment of data collection. Because the hash calculation algorithm is stateless, this number doesn’t represent the actual number of sampled out telemetry, it only tells the statistical ratio of telem- etrysampledin.Toquicklyanalyze if your telemetry has been sampled, you can execute the following ana- lytical query to compare the number of records stored with the number of records processed by the service:
requests | summarize sum(itemCount), count()
If you see the difference between those two numbers, then sampling has been enabled and your data set has been reduced.
Data Reduction in Action
Let’s review all these techniques. We’re
process or server processes the data, telemetry with a hash value below threshold will be consistently sampled in. In simplified form you can codify this algorithm like this:
If exist(UserID): Hash(UserID) = (returns value [0..100])
ElseIf exist(OperationID): Hash(OperationID) (returns value [0..100]) Else: Random [0..100]
As you can see from here, as long as UserID or OperationID is shared among all related telemetry items, it all will have the same hash value and consistently be sampled in or out. Application Insights by
Figure 9 Marking Slow Dependency Calls
for Collection and Exempt Them from Sampling
going to use a console application to highlight main concepts. The application pings bing.com in a loop and stores telemetry data in Application Insights. It treats each loop execu- tion as a request telemetry, automatically collects dependency data and correlates all telemetry to the appropriate “request” to which it belongs. To initialize the Application Insights SDK, you need to perform three simple steps. First, you have to initialize configuration with the Instrumentation Key. Instrumentation Key is an identifier used to associate telemetry data with the Application Insights resource
and can be obtained in the Azure Portal when creating it:
// Set Instrumentation Key
var configuration = new TelemetryConfiguration(); configuration.InstrumentationKey = "fb8a0b03-235a-4b52-b491-307e9fd6b209";
Next, you need to initialize the Dependency Tracking module to automatically collect dependency information:
// Automatically collect dependency calls
var dependencies = new DependencyTrackingTelemetryModule(); dependencies.Initialize(configuration);
Last, you have to add Telemetry Initializer that adds common correlation id to all related telemetry:
// Automatically correlate all telemetry data with request configuration.TelemetryInitializers.Add(new
OperationCorrelationTelemetryInitializer());
At this point, the Application Insights SDK is fully initialized and you can access all APIs via TelemetryClient object and code the main loop, as shown in Figure 3.
When you execute this application, you’ll see the screen shown in Figure 4 in a console window.
All the telemetry will be sent to the cloud and can be accessed using the Azure Portal. During the development, it’s easier to an- alyze telemetry in Visual Studio. So if you run the code in Visual Studio under debugger, you’ll see telemetry right away in the Appli- cation Insights Search tab. It will look like what’s shown in Figure 5.
internal class DependencyExampleTelemetryProcessor : ITelemetryProcessor {
private ITelemetryProcessor next;
public DependencyExampleTelemetryProcessor(ITelemetryProcessor next) {
this.next = next; }
public void Process(ITelemetry item) {
// Check telemetry type
if (item is DependencyTelemetry) {
var r = item as DependencyTelemetry;
if (r.Duration > TimeSpan.FromMilliseconds(100)) {
// If dependency duration > 100 ms then "sample in"
// this telemetry by setting sampling percentage to 100 ((ISupportSampling)item).SamplingPercentage = 100;
} }
// Continue with the next telemetry processor
this.next.Process(item); }
}
44 msdn magazine
DevOps


































































































   48   49   50   51   52