Soru

Zorluk: OrtaConfigure Application Insights Instrumentation and Telemetry

You are developing a C# .NET 8 console application that runs on-premises and needs to manually send custom exception reports to Azure Application Insights. You retrieve the connection string from a secure local store.

You write the following code:

csharp
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

var connectionString = GetSecureConnectionString();
var configuration = TelemetryConfiguration.CreateDefault();
// INSERT CODE HERE
var telemetryClient = new TelemetryClient(configuration);

You need to complete the code to ensure that the Application Insights SDK is properly initialized and telemetry data is transmitted to the correct Azure resource. Which line of code should you insert?

  1. configuration.ConnectionString = connectionString;Cevap
  2. B
    configuration.InstrumentationKey = connectionString;
  3. C
    telemetryClient.Context.ConnectionString = connectionString;
  4. D
    telemetryClient.InstrumentationKey = connectionString;

Cevap

Assign the retrieved connection string to the ConnectionString property of the TelemetryConfiguration object.
Assigning the connection string to configuration.ConnectionString correctly configures the telemetry endpoint and credentials for the TelemetryConfiguration object, which is then passed to the TelemetryClient constructor. This ensures that the SDK knows where to send telemetry data.

Adım Adım Çözüm

1
Identify the configuration object used to initialize the telemetry client.
The TelemetryConfiguration object named configuration is used to initialize TelemetryClient.
The SDK requires the endpoint and credentials specified in the connection string to target the correct resource.
2
Set the appropriate property on the TelemetryConfiguration object.
Assign the connection string to the ConnectionString property.
Setting ConnectionString is the standard method to configure telemetry routing in modern Azure SDKs.

Anahtar Kavram

Configuring Application Insights manually using TelemetryConfiguration and ConnectionString
Bu soruyu puanla