Skip to content

Commit 4059012

Browse files
committed
fixes
1 parent ba1032b commit 4059012

File tree

4 files changed

+91
-97
lines changed

4 files changed

+91
-97
lines changed

articles/azure-monitor/app/asp-net-core.md

Lines changed: 86 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The [Application Insights SDK for ASP.NET Core](https://nuget.org/packages/Micro
3232
* **IDE**: Visual Studio, VS Code, or command line.
3333

3434
> [!NOTE]
35-
> If you are using ASP.NET Core 3.0-preview along with Application Insights, please use the [2.8.0-beta3](https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.8.0-beta3) version or higher. This is the only version known to work well with ASP.NET Core 3.0. Also, Visual Studio based onboarding is not yet supported for ASP.NET Core 3.0 apps.
35+
> If you are using ASP.NET Core 3.0 along with Application Insights, please use the [2.8.0](https://www.nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore/2.8.0) version or higher. This is the only version that supports ASP.NET Core 3.0.
3636
3737
## Prerequisites
3838

@@ -113,24 +113,26 @@ The [Application Insights SDK for ASP.NET Core](https://nuget.org/packages/Micro
113113

114114
* `SET APPINSIGHTS_INSTRUMENTATIONKEY=putinstrumentationkeyhere`
115115

116-
Typically, `APPINSIGHTS_INSTRUMENTATIONKEY` specifies the instrumentation key for applications deployed to Web Apps.
116+
Typically, `APPINSIGHTS_INSTRUMENTATIONKEY` specifies the instrumentation key for applications deployed to Azure Web Apps.
117117

118118
> [!NOTE]
119119
> An instrumentation key specified in code wins over the environment variable `APPINSIGHTS_INSTRUMENTATIONKEY`, which wins over other options.
120120

121121
## Run your application
122122

123-
Run your application and make requests to it. Telemetry should now flow to Application Insights. The Application Insights SDK automatically collects the following telemetry.
123+
Run your application and make requests to it. Telemetry should now flow to Application Insights. The Application Insights SDK automatically collects incoming web requests to your application, along with the following telemetry as well.
124124

125-
|Requests/dependencies |Details|
126-
|---------------|-------|
127-
|Requests | Incoming web requests to your application. |
128-
|HTTP or HTTPS | Calls made with `HttpClient`. |
129-
|SQL | Calls made with `SqlClient`. |
130-
|[Azure Storage](https://www.nuget.org/packages/WindowsAzure.Storage/) | Calls made with the Azure Storage client. |
131-
|[EventHubs client SDK](https://www.nuget.org/packages/Microsoft.Azure.EventHubs) | Version 1.1.0 and later. |
132-
|[ServiceBus client SDK](https://www.nuget.org/packages/Microsoft.Azure.ServiceBus)| Version 3.0.0 and later. |
133-
|Azure Cosmos DB | Tracked automatically only if HTTP/HTTPS is used. Application Insights doesn't capture TCP mode. |
125+
### Live Metrics
126+
127+
[Live Metrics](https://docs.microsoft.com/azure/application-insights/app-insights-live-stream) can be used to quickly verify if Application Insights is setup correctly. While it might take a few minutes before telemetry starts appearing in the portal and analytics, Live Metrics would show CPU usage of the running process in near real-time. It can also show other telemetry like Requests, Dependencies, Traces etc.
128+
129+
### ILogger logs
130+
131+
Logs emitted via `ILogger` of severity `Warning` or greater are automatically captured. Follow [ILogger docs](ilogger.md#control-logging-level) to customize which log levels are captured by Application Insights.
132+
133+
### Dependencies
134+
135+
Dependency collection is enabled by default. [This](asp-net-dependencies.md#automatically-tracked-dependencies) article explains the dependencies that are automatically collected, and also contain steps to do manual tracking.
134136

135137
### Performance counters
136138

@@ -139,20 +141,12 @@ Support for [performance counters](https://azure.microsoft.com/documentation/art
139141
* SDK versions 2.4.1 and later collect performance counters if the application is running in Azure Web Apps (Windows).
140142
* SDK versions 2.7.1 and later collect performance counters if the application is running in Windows and targets `NETSTANDARD2.0` or later.
141143
* For applications targeting the .NET Framework, all versions of the SDK support performance counters.
142-
* SDK Versions 2.8.0-beta3 and later support cpu/memory counter in Linux. No other counter is supported in Linux. The recommended way to get system counters in Linux (and other non-Windows environments) is by using [EventCounters](#eventcounter)
144+
* SDK Versions 2.8.0 and later support cpu/memory counter in Linux. No other counter is supported in Linux. The recommended way to get system counters in Linux (and other non-Windows environments) is by using [EventCounters](#eventcounter)
143145

144146
### EventCounter
145147

146148
`EventCounterCollectionModule` is enabled by default, and it will collect a default set of counters from .NET Core 3.0 apps. The [EventCounter](eventcounters.md) tutorial lists the default set of counters collected. It also has instructions on customizing the list.
147149

148-
### ILogger logs
149-
150-
Logs emitted via `ILogger` of severity `Warning` or greater are automatically captured. Follow [ILogger docs](ilogger.md#control-logging-level) to customize which log levels are captured by Application Insights.
151-
152-
### Live Metrics
153-
154-
[Live Metrics](https://docs.microsoft.com/azure/application-insights/app-insights-live-stream) can be used to quickly verify if Application Insights is setup correctly. While it might take a few minutes before telemetry starts appearing in the portal and analytics, Live Metrics would show CPU usage of the running process in near real-time. It can also show other telemetry like Requests, Dependencies, Traces etc.
155-
156150
## Enable client-side telemetry for web applications
157151

158152
The preceding steps are enough to help you start collecting server-side telemetry. If your application has client-side components, follow the next steps to start collecting [usage telemetry](https://docs.microsoft.com/azure/azure-monitor/app/usage-overview).
@@ -186,17 +180,17 @@ You can customize the Application Insights SDK for ASP.NET Core to change the de
186180
You can modify a few common settings by passing `ApplicationInsightsServiceOptions` to `AddApplicationInsightsTelemetry`, as in this example:
187181

188182
```csharp
189-
public void ConfigureServices(IServiceCollection services)
190-
{
191-
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions aiOptions
192-
= new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
193-
// Disables adaptive sampling.
194-
aiOptions.EnableAdaptiveSampling = false;
195-
196-
// Disables QuickPulse (Live Metrics stream).
197-
aiOptions.EnableQuickPulseMetricStream = false;
198-
services.AddApplicationInsightsTelemetry(aiOptions);
199-
}
183+
public void ConfigureServices(IServiceCollection services)
184+
{
185+
Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions aiOptions
186+
= new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
187+
// Disables adaptive sampling.
188+
aiOptions.EnableAdaptiveSampling = false;
189+
190+
// Disables QuickPulse (Live Metrics stream).
191+
aiOptions.EnableQuickPulseMetricStream = false;
192+
services.AddApplicationInsightsTelemetry(aiOptions);
193+
}
200194
```
201195

202196
Full List of settings in `ApplicationInsightsServiceOptions`
@@ -224,49 +218,49 @@ Use [telemetry initializers](https://docs.microsoft.com/azure/azure-monitor/app/
224218
Add any new `TelemetryInitializer` to the `DependencyInjection` container as shown in the following code. The SDK automatically picks up any `TelemetryInitializer` that's added to the `DependencyInjection` container.
225219

226220
```csharp
227-
public void ConfigureServices(IServiceCollection services)
228-
{
229-
services.AddSingleton<ITelemetryInitializer, MyCustomTelemetryInitializer>();
230-
}
221+
public void ConfigureServices(IServiceCollection services)
222+
{
223+
services.AddSingleton<ITelemetryInitializer, MyCustomTelemetryInitializer>();
224+
}
231225
```
232226

233227
### Removing TelemetryInitializers
234228

235229
Telemetry initializers are present by default. To remove all or specific telemetry initializers, use the following sample code *after* you call `AddApplicationInsightsTelemetry()`.
236230

237231
```csharp
238-
public void ConfigureServices(IServiceCollection services)
239-
{
240-
services.AddApplicationInsightsTelemetry();
241-
242-
// Remove a specific built-in telemetry initializer
243-
var tiToRemove = services.FirstOrDefault<ServiceDescriptor>
244-
(t => t.ImplementationType == typeof(AspNetCoreEnvironmentTelemetryInitializer));
245-
if (tiToRemove != null)
246-
{
247-
services.Remove(tiToRemove);
248-
}
232+
public void ConfigureServices(IServiceCollection services)
233+
{
234+
services.AddApplicationInsightsTelemetry();
249235

250-
// Remove all initializers
251-
// This requires importing namespace by using Microsoft.Extensions.DependencyInjection.Extensions;
252-
services.RemoveAll(typeof(ITelemetryInitializer));
236+
// Remove a specific built-in telemetry initializer
237+
var tiToRemove = services.FirstOrDefault<ServiceDescriptor>
238+
(t => t.ImplementationType == typeof(AspNetCoreEnvironmentTelemetryInitializer));
239+
if (tiToRemove != null)
240+
{
241+
services.Remove(tiToRemove);
253242
}
243+
244+
// Remove all initializers
245+
// This requires importing namespace by using Microsoft.Extensions.DependencyInjection.Extensions;
246+
services.RemoveAll(typeof(ITelemetryInitializer));
247+
}
254248
```
255249

256250
### Adding telemetry processors
257251

258252
You can add custom telemetry processors to `TelemetryConfiguration` by using the extension method `AddApplicationInsightsTelemetryProcessor` on `IServiceCollection`. You use telemetry processors in [advanced filtering scenarios](https://docs.microsoft.com/azure/azure-monitor/app/api-filtering-sampling#filtering-itelemetryprocessor) to allow for more direct control over what's included or excluded from the telemetry you send to the Application Insights service. Use the following example.
259253

260254
```csharp
261-
public void ConfigureServices(IServiceCollection services)
262-
{
263-
// ...
264-
services.AddApplicationInsightsTelemetry();
265-
services.AddApplicationInsightsTelemetryProcessor<MyFirstCustomTelemetryProcessor>();
255+
public void ConfigureServices(IServiceCollection services)
256+
{
257+
// ...
258+
services.AddApplicationInsightsTelemetry();
259+
services.AddApplicationInsightsTelemetryProcessor<MyFirstCustomTelemetryProcessor>();
266260

267-
// If you have more processors:
268-
services.AddApplicationInsightsTelemetryProcessor<MySecondCustomTelemetryProcessor>();
269-
}
261+
// If you have more processors:
262+
services.AddApplicationInsightsTelemetryProcessor<MySecondCustomTelemetryProcessor>();
263+
}
270264
```
271265

272266
### Configuring or removing default TelemetryModules
@@ -281,42 +275,42 @@ The following automatic-collection modules are enabled by default. These modules
281275
* `QuickPulseTelemetryModule` - Collects telemetry for showing in Live Metrics portal.
282276
* `AppServicesHeartbeatTelemetryModule` - Collects heart beats (which are send as custom metrics), about Azure App Service environment where application is hosted.
283277
* `AzureInstanceMetadataTelemetryModule` - Collects heart beats (which are send as custom metrics), about Azure VM environment where application is hosted.
284-
* `EventCounterCollectionModule` - Collects [EventCounters.](#eventcounter). This module is a new feature and is available in SDK Version 2.8.0-beta3 and higher.
278+
* `EventCounterCollectionModule` - Collects [EventCounters.](#eventcounter). This module is a new feature and is available in SDK Version 2.8.0 and higher.
285279

286280
To configure any default `TelemetryModule`, use the extension method `ConfigureTelemetryModule<T>` on `IServiceCollection`, as shown in the following example.
287281

288282
```csharp
289283
using Microsoft.ApplicationInsights.DependencyCollector;
290284
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector;
291285

292-
public void ConfigureServices(IServiceCollection services)
293-
{
294-
services.AddApplicationInsightsTelemetry();
286+
public void ConfigureServices(IServiceCollection services)
287+
{
288+
services.AddApplicationInsightsTelemetry();
289+
290+
// The following configures DependencyTrackingTelemetryModule.
291+
// Similarly, any other default modules can be configured.
292+
services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) =>
293+
{
294+
module.EnableW3CHeadersInjection = true;
295+
});
296+
297+
// The following removes all default counters from EventCounterCollectionModule, and adds a single one.
298+
services.ConfigureTelemetryModule<EventCounterCollectionModule>(
299+
(module, o) =>
300+
{
301+
module.Counters.Clear();
302+
module.Counters.Add(new EventCounterCollectionRequest("System.Runtime", "gen-0-size"));
303+
}
304+
);
295305

296-
// The following configures DependencyTrackingTelemetryModule.
297-
// Similarly, any other default modules can be configured.
298-
services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) =>
299-
{
300-
module.EnableW3CHeadersInjection = true;
301-
});
302-
303-
// The following removes all default counters from EventCounterCollectionModule, and adds a single one.
304-
services.ConfigureTelemetryModule<EventCounterCollectionModule>(
305-
(module, o) =>
306-
{
307-
module.Counters.Clear();
308-
module.Counters.Add(new EventCounterCollectionRequest("System.Runtime", "gen-0-size"));
309-
}
310-
);
311-
312-
// The following removes PerformanceCollectorModule to disable perf-counter collection.
313-
// Similarly, any other default modules can be removed.
314-
var performanceCounterService = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(PerformanceCollectorModule));
315-
if (performanceCounterService != null)
316-
{
317-
services.Remove(performanceCounterService);
318-
}
306+
// The following removes PerformanceCollectorModule to disable perf-counter collection.
307+
// Similarly, any other default modules can be removed.
308+
var performanceCounterService = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(PerformanceCollectorModule));
309+
if (performanceCounterService != null)
310+
{
311+
services.Remove(performanceCounterService);
319312
}
313+
}
320314
```
321315

322316
### Configuring a telemetry channel
@@ -360,7 +354,8 @@ Note that the above does not prevent any auto collection modules from collecting
360354
### Does Application Insights support ASP.NET Core 3.0?
361355

362356
Yes. Update to [Application Insights SDK for ASP.NET Core](https://nuget.org/packages/Microsoft.ApplicationInsights.AspNetCore) version 2.8.0 or higher. Older versions of the SDK do not support ASP.NET Core 3.0.
363-
Also, if you are using Visual Studio based instructions from [here](#enable-application-insights-server-side-telemetry-visual-studio), please update to the latest version of Visual Studio 2019 (16.3.0) to onboard. Previous versions of Visual Studio do not support automatic onboarding.
357+
358+
Also, if you are using Visual Studio based instructions from [here](#enable-application-insights-server-side-telemetry-visual-studio), please update to the latest version of Visual Studio 2019 (16.3.0) to onboard. Previous versions of Visual Studio do not support automatic onboarding for ASP.NET Core 3.0 apps.
364359

365360
### How can I track telemetry that's not automatically collected?
366361

@@ -393,9 +388,7 @@ For more information about custom data reporting in Application Insights, see [A
393388
394389
### Some Visual Studio templates used the UseApplicationInsights() extension method on IWebHostBuilder to enable Application Insights. Is this usage still valid?
395390

396-
Yes, enabling Application Insights with this method is valid. This technique is used in Visual Studio onboarding and in the Web Apps extensions. However, we recommend using `services.AddApplicationInsightsTelemetry()` because it provides overloads to control some configuration. Both methods do the same thing internally, so if you don't need to apply custom configuration, you can call either method.
397-
398-
`IWebHostBuilder` is replaced with `IHostBuilder` in ASP.NET Core 3.0, and to avoid confusion, Application Insights version 2.8.0 onwards is marking the UseApplicationInsights() method as obsolete, and will be removed in the next major version.
391+
While the extension method `UseApplicationInsights()` is still supported, its marked obsolete in Application Insights SDK version 2.8.0 onwards. It'll be removed in the next major version of the SDK. The recommended way to enable Application Insights telemetry is by using `services.AddApplicationInsightsTelemetry()` because it provides overloads to control some configuration. Also, in ASP.NET Core 3.0 apps, `services.AddApplicationInsightsTelemetry()` is the only way to enable application insights.
399392

400393
### I'm deploying my ASP.NET Core application to Web Apps. Should I still enable the Application Insights extension from Web Apps?
401394

@@ -442,6 +435,10 @@ using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
442435
}
443436
```
444437

438+
### Is this SDK supported for the new .NET Core 3.0 Worker Service template applications?
439+
440+
This SDK requires `HttpContext`, and hence does not work in any non-http applications, including the .NET Core 3.0 Worker Service applications. Refer to [this](worker-service.md) document for enabling application insights in such applications, using the newly release Microsoft.ApplicationInsights.WorkerService SDK.
441+
445442
## Open-source SDK
446443

447444
[Read and contribute to the code](https://github.com/Microsoft/ApplicationInsights-aspnetcore#recent-updates).

articles/azure-monitor/app/azure-web-apps.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ms.author: mbullwin
1313
---
1414
# Monitor Azure App Service performance
1515

16-
Enabling monitoring on your .NET and .NET Core based web applications running on [Azure App Services](https://docs.microsoft.com/azure/app-service/) is now easier than ever. Whereas previously you needed to manually install a site extension, the latest extension/agent is now built into the app service image by default. This article will walk you through enabling Application Insights monitoring as well as provide preliminary guidance for automating the process for large-scale deployments.
16+
Enabling monitoring on your ASP.NET and ASP.NET Core based web applications running on [Azure App Services](https://docs.microsoft.com/azure/app-service/) is now easier than ever. Whereas previously you needed to manually install a site extension, the latest extension/agent is now built into the app service image by default. This article will walk you through enabling Application Insights monitoring as well as provide preliminary guidance for automating the process for large-scale deployments.
1717

1818
> [!NOTE]
1919
> Manually adding an Application Insights site extension via **Development Tools** > **Extensions** is deprecated. This method of extension installation was dependent on manual updates for each new version. The latest stable release of the extension is now [preinstalled](https://github.com/projectkudu/kudu/wiki/Azure-Site-Extensions) as part of the App Service image. The files are located in `d:\Program Files (x86)\SiteExtensions\ApplicationInsightsAgent` and are automatically updated with each stable release. If you follow the agent based instructions to enable monitoring below, it will automatically remove the deprecated extension for you.
@@ -372,4 +372,4 @@ For the latest information on the Application Insights agent/extension, check ou
372372
* [Monitor service health metrics](../platform/data-platform.md) to make sure your service is available and responsive.
373373
* [Receive alert notifications](../platform/alerts-overview.md) whenever operational events happen or metrics cross a threshold.
374374
* Use [Application Insights for JavaScript apps and web pages](javascript.md) to get client telemetry from the browsers that visit a web page.
375-
* [Set up Availability web tests](monitor-web-app-availability.md) to be alerted if your site is down.
375+
* [Set up Availability web tests](monitor-web-app-availability.md) to be alerted if your site is down.

0 commit comments

Comments
 (0)