How to enable CodeLens for viewing Application Insights telemetry directly in Visual Studio for Web API projects

I had been using Application Insights for a while with a Web API project and found it immensely valuable for monitoring how the Web API was performing and discovering any issues in production.

I only recently stumbled across the fact that for ASP.NET projects, the Application Insights telemetry is surfaced and available in your source code within Visual Studio using CodeLens.

TBD

https://docs.microsoft.com/en-us/azure/azure-monitor/app/visual-studio-codelens

I was wondering why I wasn’t seeing this for my project and it seems you only get this magic happening automatically if your project is ASP.NET. My project was a Web API project.

Luckily it didn’t take long to find the answer here:
https://feedback.azure.com/forums/357324-application-insights/suggestions/15697332-support-code-lens-exception-display-for-all-net-p

I followed the steps posted on the comment of this thread. By adding this into an existing Product Group within the project .csproj file.

<ApplicationInsightsResourceId>/subscriptions/[subscription-id]/resourceGroups/[resource-group-name]/providers/microsoft.insights/components/[app-insights-resource-name]</ApplicationInsightsResourceId>

Note: When substituting values into the above, Resource Group and App Insights are the display name shown in Azure not the ids.

You will need to close and re-open the project in Visual Studio for the changes in the .csproj file to take affect. Once this happens you should be able to right-click on your project in Solution Explorer window and see an Application Insights menu option.

Now you’re all setup, learn more about how to use all this data that is at your fingertips!
https://docs.microsoft.com/en-us/azure/azure-monitor/app/visual-studio

TBD
Right-click the project and choose Application Insights, Search
Under Request Details, click through to the code
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: