Soru

Zorluk: ZorConfigure Application Insights Instrumentation and Telemetry

You are configuring Application Insights telemetry in a C# console application. You need to enrich all telemetry sent to Application Insights with a custom cloud role name by implementing and registering a telemetry initializer.

Complete the code snippet by identifying the correct types and properties for each blank.

Cevap:using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

// A custom initializer to enrich all telemetry with cloud role details
public class CloudRoleNameInitializer : 【ITelemetryInitializer】
{
public void Initialize(【ITelemetry】 telemetry)
{
telemetry.Context.Cloud.RoleName = "OrderProcessingService";
}
}

// In the application startup code:
var config = TelemetryConfiguration.CreateDefault();
config.ConnectionString = "ConnectionStringValue";
config.【TelemetryInitializers】.Add(new CloudRoleNameInitializer());

Cevap

Blank 1 should be filled with ITelemetryInitializer, Blank 2 with ITelemetry, and Blank 3 with TelemetryInitializers.
To write a custom telemetry initializer, you must implement the ITelemetryInitializer interface, which has a single Initialize method taking an ITelemetry argument. To run it, you must add it to the TelemetryInitializers collection on the active TelemetryConfiguration.

Adım Adım Çözüm

1
Implement the telemetry initializer interface.
The class must implement the ITelemetryInitializer interface to hook into the Application Insights telemetry pipeline.
The Application Insights SDK uses this interface to identify custom initializers.
2
Define the input parameter type for the Initialize method.
The method signature must accept an ITelemetry object.
This object represents the raw telemetry data being processed and exposes the Context property to allow modification of metadata like Cloud Role Name.
3
Register the initializer instance in the active configuration.
Add the custom initializer to the TelemetryInitializers collection on the configuration object.
This ensures the SDK executes the initializer for all generated telemetry data before transmission.

Anahtar Kavram

Programmatic configuration of Application Insights Telemetry Initializers in C#
Tahmini Süre:2m 0s
Bu soruyu puanla