Microsoft Azure Developer Associate AZ-204 Practice Question
An ASP.NET Core Web API deployed to Azure App Service has the Microsoft.ApplicationInsights.AspNetCore SDK installed. You need to record a custom event named "FileProcessed" from inside a controller action and ensure that the event is automatically correlated with the incoming request telemetry (that is, it carries the same operation-id and parent-id).
Which implementation meets the requirement?
Retrieve RequestTelemetry from HttpContext.Features and add a property named "FileProcessed" to it.
Add a TelemetryClient parameter to the controller constructor, store it in a field, and call _telemetryClient.TrackEvent("FileProcessed"); inside the action.
Inside the action create a new instance: var tc = new TelemetryClient(); tc.TrackEvent("FileProcessed");
Call ILogger.LogInformation("FileProcessed"); because the logging provider forwards log messages as custom events.
In an ASP.NET Core application the TelemetryClient that the Application Insights SDK registers with the dependency-injection (DI) container is initialized with the current telemetry context, including operation and correlation identifiers that link items that occur during the same request. Resolving that singleton or scoped instance through constructor injection and then calling TrackEvent keeps the automatic correlation intact.
Instantiating a new TelemetryClient manually bypasses the SDK's request tracking module, so the event is sent without the correct operation context. Writing through ILogger produces trace telemetry, not a custom event, and altering HttpContext features does not create a standalone custom event. Therefore, injecting TelemetryClient and calling TrackEvent inside the action is the correct approach.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is TelemetryClient in Application Insights SDK?
Open an interactive chat with Bash
What is dependency injection (DI) and why is it used with TelemetryClient?
Open an interactive chat with Bash
What is event correlation in Application Insights and why is it necessary?
Open an interactive chat with Bash
Microsoft Azure Developer Associate AZ-204
Monitor and troubleshoot Azure solutions
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .