Skip to content

Commit

Permalink
Adding support for pre-aggregated (standard) metrics. (#3047)
Browse files Browse the repository at this point in the history
Adding support for pre-aggregated (standard) metrics.
  • Loading branch information
RohitRanjanMS authored Dec 4, 2023
1 parent 9fad0f7 commit 095fae1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ public TimeSpan QuickPulseInitializationDelay
/// Disabled by default.
/// </summary>
public EventLevel? DiagnosticsEventListenerLogLevel { get; set; }


/// <summary>
/// Gets or sets the flag that enables standard metrics collection in ApplicationInsights.
/// Disabled by default.
/// </summary>
public bool EnableAutocollectedMetricsExtractor { get; set; } = false;

public string Format()
{
JObject sampling = null;
Expand Down Expand Up @@ -232,6 +238,7 @@ public string Format()
{ nameof(DependencyTrackingOptions), dependencyTrackingOptions },
{ nameof(TokenCredentialOptions), tokenCredentialOptions },
{ nameof(DiagnosticsEventListenerLogLevel), DiagnosticsEventListenerLogLevel?.ToString() },
{ nameof(EnableAutocollectedMetricsExtractor), EnableAutocollectedMetricsExtractor },
};

return options.ToString(Formatting.Indented);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ private static void SetupTelemetryConfiguration(
}
}

// Metrics extractor must be added before filtering and adaptive sampling telemetry processor to account for all the data.
if (options.EnableAutocollectedMetricsExtractor)
{
configuration.TelemetryProcessorChainBuilder
.Use((next) => new AutocollectedMetricsExtractor(next));
}

QuickPulseTelemetryProcessor quickPulseProcessor = null;
configuration.TelemetryProcessorChainBuilder
.Use((next) => new OperationFilteringTelemetryProcessor(next));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void DependencyInjectionConfiguration_Configures_With_InstrumentationKey(
Assert.Single(modules.OfType<PerformanceCollectorModule>());
Assert.Single(modules.OfType<AppServicesHeartbeatTelemetryModule>());
Assert.Single(modules.OfType<RequestTrackingTelemetryModule>());
// SelfDiagnosticsTelemetryModule is dabled by default and instead NullTelemetryModule is added
// SelfDiagnosticsTelemetryModule is disabled by default and instead NullTelemetryModule is added
Assert.Single(modules.OfType<NullTelemetryModule>());

var dependencyModule = modules.OfType<DependencyTrackingTelemetryModule>().Single();
Expand Down Expand Up @@ -135,6 +135,7 @@ public void DependencyInjectionConfiguration_Configures_With_ConnectionString()
{
o.ConnectionString = "InstrumentationKey=somekey;EndpointSuffix=applicationinsights.us";
o.DiagnosticsEventListenerLogLevel = EventLevel.Verbose;
o.EnableAutocollectedMetricsExtractor = true;
});
});

Expand Down Expand Up @@ -195,10 +196,11 @@ public void DependencyInjectionConfiguration_Configures_With_ConnectionString()
Assert.NotNull(providers[0]);

// Verify Processors
Assert.Equal(4, config.TelemetryProcessors.Count);
Assert.IsType<OperationFilteringTelemetryProcessor>(config.TelemetryProcessors[0]);
Assert.IsType<QuickPulseTelemetryProcessor>(config.TelemetryProcessors[1]);
Assert.IsType<FilteringTelemetryProcessor>(config.TelemetryProcessors[2]);
Assert.Equal(5, config.TelemetryProcessors.Count);
Assert.IsType<AutocollectedMetricsExtractor>(config.TelemetryProcessors[0]);
Assert.IsType<OperationFilteringTelemetryProcessor>(config.TelemetryProcessors[1]);
Assert.IsType<QuickPulseTelemetryProcessor>(config.TelemetryProcessors[2]);
Assert.IsType<FilteringTelemetryProcessor>(config.TelemetryProcessors[3]);
Assert.Empty(config.TelemetryProcessors.OfType<AdaptiveSamplingTelemetryProcessor>());

// Verify ApplicationIdProvider
Expand Down

0 comments on commit 095fae1

Please sign in to comment.