You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-monitor/app/asp-net-core.md
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,13 +23,11 @@ Application Insights can collect the following telemetry from your ASP.NET Core
23
23
24
24
We'll use an [MVC application](/aspnet/core/tutorials/first-mvc-app) example. If you're using the [Worker Service](/aspnet/core/fundamentals/host/hosted-services#worker-service-template), use the instructions in [Application Insights for Worker Service applications](./worker-service.md).
25
25
26
-
> [!NOTE]
27
-
> A preview [OpenTelemetry-based .NET offering](opentelemetry-enable.md?tabs=net) is available. For more information, see [OpenTelemetry overview](opentelemetry-overview.md).
26
+
A preview [OpenTelemetry-based .NET offering](opentelemetry-enable.md?tabs=net) is available. For more information, see [OpenTelemetry overview](opentelemetry-overview.md).
> You can also use the Microsoft.Extensions.Logging.ApplicationInsights package to capture logs. For more information, see [Application Insights logging with .NET](ilogger.md). For an example, see [Console application](ilogger.md#console-application).
30
+
You can also use the Microsoft.Extensions.Logging.ApplicationInsights package to capture logs. For more information, see [Application Insights logging with .NET](ilogger.md). For an example, see [Console application](ilogger.md#console-application).
33
31
34
32
## Supported scenarios
35
33
@@ -39,7 +37,7 @@ The [Application Insights SDK for ASP.NET Core](https://nuget.org/packages/Micro
39
37
***Hosting method**: In process or out of process
40
38
***Deployment method**: Framework dependent or self-contained
41
39
***Web server**: Internet Information Server (IIS) or Kestrel
42
-
***Hosting platform**: The Web Apps feature of Azure App Service, Azure Virtual Machines, Docker, Azure Kubernetes Service (AKS), and so on
40
+
***Hosting platform**: The Web Apps feature of Azure App Service, Azure Virtual Machines, Docker, and Azure Kubernetes Service (AKS)
43
41
***.NET Core version**: All officially [supported .NET Core versions](https://dotnet.microsoft.com/download/dotnet-core) that aren't in preview
44
42
***IDE**: Visual Studio, Visual Studio Code, or command line
45
43
@@ -48,6 +46,8 @@ The [Application Insights SDK for ASP.NET Core](https://nuget.org/packages/Micro
48
46
49
47
## Prerequisites
50
48
49
+
You need:
50
+
51
51
- A functioning ASP.NET Core application. If you need to create an ASP.NET Core application, follow this [ASP.NET Core tutorial](/aspnet/core/getting-started/).
52
52
- A valid Application Insights connection string. This string is required to send any telemetry to Application Insights. If you need to create a new Application Insights resource to get a connection string, see [Create an Application Insights resource](./create-new-resource.md).
53
53
@@ -61,9 +61,9 @@ For Visual Studio for Mac, use the [manual guidance](#enable-application-insight
1. Choose your subscription and Application Insights instance. Or you can create a new instance with **Create new**. Then select**Next**.
64
+
1. Choose your subscription and Application Insights instance. Or you can create a new instance with **Create new**. Select**Next**.
65
65
66
-
1. Add or confirm your Application Insights connection string. It should be prepopulated based on your selection in the previous step. Then select**Finish**.
66
+
1. Add or confirm your Application Insights connection string. It should be prepopulated based on your selection in the previous step. Select**Finish**.
67
67
68
68
1. After you add Application Insights to your project, check to confirm that you're using the latest stable release of the SDK. Go to **Project** > **Manage NuGet Packages** > **Microsoft.ApplicationInsights.AspNetCore**. If you need to, select **Update**.
69
69
@@ -75,7 +75,7 @@ For Visual Studio for Mac, use the [manual guidance](#enable-application-insight
75
75
76
76
We recommend that you always use the latest stable version. Find full release notes for the SDK on the [open-source GitHub repo](https://github.com/Microsoft/ApplicationInsights-dotnet/releases).
77
77
78
-
The following code sample shows the changes to be added to your project's `.csproj` file:
78
+
The following code sample shows the changes to add to your project's `.csproj` file:
79
79
80
80
```xml
81
81
<ItemGroup>
@@ -145,7 +145,7 @@ For Visual Studio for Mac, use the [manual guidance](#enable-application-insight
* Typically, `APPLICATIONINSIGHTS_CONNECTION_STRING` is used in [Azure Web Apps](./azure-web-apps.md?tabs=net). It can also be used in all places where this SDK is supported.
148
+
* Typically, `APPLICATIONINSIGHTS_CONNECTION_STRING` is used in [Web Apps](./azure-web-apps.md?tabs=net). It can also be used in all places where this SDK is supported.
149
149
150
150
> [!NOTE]
151
151
> A connection string specified in code wins over the environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING`, which wins over other options.
@@ -168,7 +168,7 @@ Run your application and make requests to it. Telemetry should now flow to Appli
168
168
169
169
### ILogger logs
170
170
171
-
The default configuration collects `ILogger` `Warning` logs and more severe logs. For more information, see the [How do I customize ILogger logs collection?](#how-do-i-customize-ilogger-logs-collection).
171
+
The default configuration collects `ILogger` `Warning` logs and more severe logs. For more information, see [How do I customize ILogger logs collection?](#how-do-i-customize-ilogger-logs-collection).
172
172
173
173
### Dependencies
174
174
@@ -178,7 +178,7 @@ Dependency collection is enabled by default. [Dependency tracking in Application
178
178
179
179
Support for [performance counters](./performance-counters.md) in ASP.NET Core is limited:
180
180
181
-
* SDK versions 2.4.1 and later collect performance counters if the application is running in Azure Web Apps (Windows).
181
+
* SDK versions 2.4.1 and later collect performance counters if the application is running in Web Apps (Windows).
182
182
* SDK versions 2.7.1 and later collect performance counters if the application is running in Windows and targets `NETSTANDARD2.0` or later.
183
183
* For applications that target the .NET Framework, all versions of the SDK support performance counters.
184
184
* SDK versions 2.8.0 and later support the CPU/memory counter in Linux. No other counter is supported in Linux. To get system counters in Linux and other non-Windows environments, use [EventCounters](#eventcounter).
@@ -283,16 +283,16 @@ This table has the full list of `ApplicationInsightsServiceOptions` settings:
|EnableHeartbeat | Enable/Disable the heartbeats feature, which periodically (15-min default) sends a custom metric named `HeartbeatState` with information about the runtime like .NET version and Azure environment information, if applicable. | True
287
-
|AddAutoCollectedMetricExtractor | Enable/Disable the `AutoCollectedMetrics extractor`, which is a telemetry processor that sends pre-aggregated metrics about requests/dependencies before sampling takes place. | True
286
+
|EnableHeartbeat | Enable/Disable the heartbeats feature. It periodically (15-min default) sends a custom metric named `HeartbeatState` with information about the runtime like .NET version and Azure environment information, if applicable. | True
287
+
|AddAutoCollectedMetricExtractor | Enable/Disable the `AutoCollectedMetrics extractor`. This telemetry processor sends pre-aggregated metrics about requests/dependencies before sampling takes place. | True
288
288
|RequestCollectionOptions.TrackExceptions | Enable/Disable reporting of unhandled exception tracking by the request collection module. | False in NETSTANDARD2.0 (because exceptions are tracked with `ApplicationInsightsLoggerProvider`). True otherwise.
289
289
|EnableDiagnosticsTelemetryModule | Enable/Disable `DiagnosticsTelemetryModule`. Disabling will cause the following settings to be ignored: `EnableHeartbeat`, `EnableAzureInstanceMetadataTelemetryModule`, and `EnableAppServicesHeartbeatTelemetryModule`. | True
290
290
291
291
For the most current list, see the [configurable settings in `ApplicationInsightsServiceOptions`](https://github.com/microsoft/ApplicationInsights-dotnet/blob/develop/NETCORE/src/Shared/Extensions/ApplicationInsightsServiceOptions.cs).
292
292
293
293
### Configuration recommendation for Microsoft.ApplicationInsights.AspNetCore SDK 2.15.0 and later
294
294
295
-
In `Microsoft.ApplicationInsights.AspNetCore` SDK version [2.15.0](https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.15.0) and later, we recommend configuring every setting available in `ApplicationInsightsServiceOptions`, including **ConnectionString** by using the application's `IConfiguration` instance. The settings must be under the section "ApplicationInsights", as shown in the following example. The following section from *appsettings.json* configures the connection string and disables adaptive sampling and performance counter collection.
295
+
In Microsoft.ApplicationInsights.AspNetCore SDK version [2.15.0](https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.15.0) and later, configure every setting available in `ApplicationInsightsServiceOptions`, including `ConnectionString`. Use the application's `IConfiguration` instance. The settings must be under the section `ApplicationInsights`, as shown in the following example. The following section from *appsettings.json* configures the connection string and disables adaptive sampling and performance counter collection.
296
296
297
297
```json
298
298
{
@@ -329,7 +329,7 @@ var app = builder.Build();
329
329
```
330
330
331
331
> [!NOTE]
332
-
> `builder.Services.AddSingleton<ITelemetryInitializer, MyCustomTelemetryInitializer>();` works for simple initializers. For others, the following is required: `builder.Services.AddSingleton(new MyCustomTelemetryInitializer() { fieldName = "myfieldName" });`
332
+
> `builder.Services.AddSingleton<ITelemetryInitializer, MyCustomTelemetryInitializer>();` works for simple initializers. For others, `builder.Services.AddSingleton(new MyCustomTelemetryInitializer() { fieldName = "myfieldName" });` is required.
333
333
334
334
### [ASP.NET Core 5 and earlier](#tab/netcoreold)
335
335
@@ -341,7 +341,7 @@ public void ConfigureServices(IServiceCollection services)
341
341
```
342
342
343
343
> [!NOTE]
344
-
> `services.AddSingleton<ITelemetryInitializer, MyCustomTelemetryInitializer>();` works for simple initializers. For others, the following is required: `services.AddSingleton(new MyCustomTelemetryInitializer() { fieldName = "myfieldName" });`
344
+
> `services.AddSingleton<ITelemetryInitializer, MyCustomTelemetryInitializer>();` works for simple initializers. For others, `services.AddSingleton(new MyCustomTelemetryInitializer() { fieldName = "myfieldName" });` is required.
345
345
346
346
---
347
347
@@ -396,7 +396,7 @@ public void ConfigureServices(IServiceCollection services)
396
396
397
397
### Add telemetry processors
398
398
399
-
You can add custom telemetry processors to `TelemetryConfiguration` by using the extension method `AddApplicationInsightsTelemetryProcessor` on `IServiceCollection`. You use telemetry processors in [advanced filtering scenarios](./api-filtering-sampling.md#itelemetryprocessor-and-itelemetryinitializer). Use the following example.
399
+
You can add custom telemetry processors to `TelemetryConfiguration` by using the extension method `AddApplicationInsightsTelemetryProcessor` on `IServiceCollection`. You use telemetry processors in [advanced filtering scenarios](./api-filtering-sampling.md#itelemetryprocessor-and-itelemetryinitializer). Use the following example:
400
400
401
401
### [ASP.NET Core 6 and later](#tab/netcorenew)
402
402
@@ -438,12 +438,12 @@ By default, the following automatic-collection modules are enabled. These module
438
438
*`RequestTrackingTelemetryModule`: Collects RequestTelemetry from incoming web requests.
439
439
*`DependencyTrackingTelemetryModule`: Collects [DependencyTelemetry](./asp-net-dependencies.md) from outgoing HTTP calls and SQL calls.
440
440
*`PerformanceCollectorModule`: Collects Windows PerformanceCounters.
441
-
*`QuickPulseTelemetryModule`: Collects telemetry for showing in Live Metrics portal.
442
-
*`AppServicesHeartbeatTelemetryModule`: Collects heartbeats (which are sent as custom metrics), about the Azure App Service environment where the application is hosted.
441
+
*`QuickPulseTelemetryModule`: Collects telemetry to show in the Live Metrics portal.
442
+
*`AppServicesHeartbeatTelemetryModule`: Collects heartbeats (which are sent as custom metrics), about the App Service environment where the application is hosted.
443
443
*`AzureInstanceMetadataTelemetryModule`: Collects heartbeats (which are sent as custom metrics), about the Azure VM environment where the application is hosted.
444
444
*`EventCounterCollectionModule`: Collects [EventCounters](eventcounters.md). This module is a new feature and is available in SDK version 2.8.0 and later.
445
445
446
-
To configure any default `TelemetryModule`, use the extension method `ConfigureTelemetryModule<T>` on `IServiceCollection`, as shown in the following example.
446
+
To configure any default `TelemetryModule`, use the extension method `ConfigureTelemetryModule<T>` on `IServiceCollection`, as shown in the following example:
447
447
448
448
### [ASP.NET Core 6 and later](#tab/netcorenew)
449
449
@@ -556,7 +556,7 @@ public void ConfigureServices(IServiceCollection services)
556
556
---
557
557
558
558
> [!NOTE]
559
-
> If you want to flush the buffer, see [Flushing data](api-custom-events-metrics.md#flushing-data). For example, if you're using the SDK in an application that shuts down.
559
+
> If you want to flush the buffer, see [Flushing data](api-custom-events-metrics.md#flushing-data). For example, you might need to flush the buffer if you're using the SDK in an application that shuts down.
560
560
561
561
### Disable telemetry dynamically
562
562
@@ -738,7 +738,7 @@ This limitation isn't applicable from version [2.15.0](https://www.nuget.org/pac
738
738
739
739
### Is this SDK supported for the new .NET Core 3.X Worker Service template applications?
740
740
741
-
This SDK requires `HttpContext`. Therefore, it doesn't work in any non-HTTPapplications, includingthe .NETCore 3.XWorkerServiceapplications. ToenableApplicationInsightsinsuchapplicationsbyusingthenewlyreleasedMicrosoft.ApplicationInsights.WorkerServiceSDK, see [ApplicationInsightsforWorkerServiceapplications (non-HTTPapplications)](worker-service.md).
741
+
This SDK requires `HttpContext`. It doesn't work in any non-HTTPapplications, includingthe .NETCore 3.XWorkerServiceapplications. ToenableApplicationInsightsinsuchapplicationsbyusingthenewlyreleasedMicrosoft.ApplicationInsights.WorkerServiceSDK, see [ApplicationInsightsforWorkerServiceapplications (non-HTTPapplications)](worker-service.md).
742
742
743
743
## Troubleshooting
744
744
@@ -756,4 +756,4 @@ For the latest updates and bug fixes, see the [release notes](./release-notes.md
0 commit comments