Soru

Zorluk: OrtaConfigure Application Insights Instrumentation and Telemetry

Complete the C# code below to define a custom telemetry processor that filters out successful dependency telemetry and register it within the ASP.NET Core dependency injection container.

Cevap:public class DependencyFilter : 【ITelemetryProcessor】
{
private ITelemetryProcessor Next { get; set; }

public DependencyFilter(ITelemetryProcessor next)
{
this.Next = next;
}

public void Process(ITelemetry item)
{
if (item is DependencyTelemetry dependency && dependency.Success == true)
{
return; // Filter out
}
this.Next.Process(item);
}
}

// In Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddApplicationInsightsTelemetry();
builder.Services.【AddApplicationInsightsTelemetryProcessor】<DependencyFilter>();

Cevap

Implement the ITelemetryProcessor interface for the filter class, and register the class in the ServiceCollection using the AddApplicationInsightsTelemetryProcessor extension method.
To create a custom telemetry filter, the class must implement ITelemetryProcessor and its Process method. To register it in an ASP.NET Core application, use the AddApplicationInsightsTelemetryProcessor service extension method. This registers the processor so it is executed for every telemetry item passing through the telemetry pipeline.

Adım Adım Çözüm

1
Identify the interface required to implement a custom telemetry filtering mechanism in Application Insights.
The correct interface is ITelemetryProcessor, which defines the Process method.
ITelemetryProcessor is the standard interface in the Application Insights SDK for custom telemetry filters that run in the telemetry pipeline.
2
Identify the service collection extension method used to register the custom telemetry processor.
The correct extension method is AddApplicationInsightsTelemetryProcessor.
This method ensures that the telemetry processor is correctly integrated into the Application Insights pipeline along with dependency injection dependencies.

Anahtar Kavram

Custom Telemetry Filtering using ITelemetryProcessor and AddApplicationInsightsTelemetryProcessor in ASP.NET Core
Bu soruyu puanla