@azure/mcp-linux-arm64 2.0.0-beta.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.txt +5683 -4849
- package/README.md +149 -26
- package/dist/Azure.Mcp.Tools.AzureMigrate.xml +1060 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/ActivityProcessors.md +119 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/AddApplicationInsightsTelemetry.md +129 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/AddApplicationInsightsTelemetryWorkerService.md +115 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/AddOpenTelemetry.md +153 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/ApplicationInsightsWeb.md +103 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/AzureMonitorExporter.md +137 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/ConfigureOpenTelemetryProvider.md +218 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/ConfigureResource.md +119 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/ConsoleExporter.md +47 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/EntityFrameworkInstrumentation.md +56 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/HttpInstrumentation.md +109 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/LogProcessors.md +101 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/OpenTelemetrySdkCreate.md +146 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/OtlpExporter.md +88 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/RedisInstrumentation.md +63 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/Sampling.md +86 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/SdkCreateTracerProviderBuilder.md +127 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/SqlClientInstrumentation.md +53 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/TelemetryClient.md +122 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/TelemetryConfigurationBuilder.md +173 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/UseAzureMonitor.md +96 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/UseAzureMonitorExporter.md +146 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/WithLogging.md +109 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/WithMetrics.md +105 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/WithTracing.md +91 -0
- package/dist/Instrumentation/Resources/concepts/dotnet/appinsights-aspnetcore.md +113 -0
- package/dist/Instrumentation/Resources/concepts/dotnet/aspnet-classic-appinsights.md +95 -0
- package/dist/Instrumentation/Resources/concepts/dotnet/azure-monitor-distro.md +102 -0
- package/dist/Instrumentation/Resources/concepts/dotnet/opentelemetry-pipeline.md +57 -0
- package/dist/Instrumentation/Resources/concepts/nodejs/azure-monitor-overview.md +106 -0
- package/dist/Instrumentation/Resources/concepts/nodejs/opentelemetry-pipeline.md +201 -0
- package/dist/Instrumentation/Resources/concepts/python/azure-monitor-overview.md +122 -0
- package/dist/Instrumentation/Resources/concepts/python/opentelemetry-pipeline.md +154 -0
- package/dist/Instrumentation/Resources/examples/dotnet/aspnet-classic-setup.md +80 -0
- package/dist/Instrumentation/Resources/examples/dotnet/aspnetcore-distro-setup.md +156 -0
- package/dist/Instrumentation/Resources/examples/dotnet/aspnetcore-setup.md +160 -0
- package/dist/Instrumentation/Resources/examples/dotnet/workerservice-setup.md +154 -0
- package/dist/Instrumentation/Resources/examples/nodejs/bunyan-setup.md +301 -0
- package/dist/Instrumentation/Resources/examples/nodejs/console-setup.md +284 -0
- package/dist/Instrumentation/Resources/examples/nodejs/express-setup.md +169 -0
- package/dist/Instrumentation/Resources/examples/nodejs/fastify-setup.md +237 -0
- package/dist/Instrumentation/Resources/examples/nodejs/langchain-js-setup.md +310 -0
- package/dist/Instrumentation/Resources/examples/nodejs/mongodb-setup.md +185 -0
- package/dist/Instrumentation/Resources/examples/nodejs/mysql-setup.md +231 -0
- package/dist/Instrumentation/Resources/examples/nodejs/nestjs-setup.md +184 -0
- package/dist/Instrumentation/Resources/examples/nodejs/nextjs-setup.md +320 -0
- package/dist/Instrumentation/Resources/examples/nodejs/postgres-setup.md +147 -0
- package/dist/Instrumentation/Resources/examples/nodejs/redis-setup.md +198 -0
- package/dist/Instrumentation/Resources/examples/nodejs/winston-setup.md +260 -0
- package/dist/Instrumentation/Resources/examples/python/console-setup.md +392 -0
- package/dist/Instrumentation/Resources/examples/python/django-setup.md +269 -0
- package/dist/Instrumentation/Resources/examples/python/fastapi-setup.md +256 -0
- package/dist/Instrumentation/Resources/examples/python/flask-setup.md +218 -0
- package/dist/Instrumentation/Resources/examples/python/genai-setup.md +214 -0
- package/dist/Instrumentation/Resources/examples/python/generic-setup.md +164 -0
- package/dist/Instrumentation/Resources/migration/dotnet/aad-authentication-migration.md +150 -0
- package/dist/Instrumentation/Resources/migration/dotnet/appinsights-2x-to-3x-code-migration.md +164 -0
- package/dist/Instrumentation/Resources/migration/dotnet/appinsights-2x-to-3x-no-code-change.md +92 -0
- package/dist/Instrumentation/Resources/migration/dotnet/aspnet-classic-2x-to-3x-code-migration.md +190 -0
- package/dist/Instrumentation/Resources/migration/dotnet/console-2x-to-3x-code-migration.md +106 -0
- package/dist/Instrumentation/Resources/migration/dotnet/ilogger-migration.md +54 -0
- package/dist/Instrumentation/Resources/migration/dotnet/workerservice-2x-to-3x-code-migration.md +126 -0
- package/dist/Instrumentation/Resources/migration/dotnet/workerservice-2x-to-3x-no-code-change.md +102 -0
- package/dist/appsettings.json +5 -0
- package/dist/azmcp +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ActivityProcessors
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 1.x
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Activity Processors — Filtering & Enrichment
|
|
8
|
+
|
|
9
|
+
## Key concepts
|
|
10
|
+
|
|
11
|
+
- Subclass `BaseProcessor<Activity>` to create a custom processor.
|
|
12
|
+
- **`OnStart`** = enrichment (add tags early). **`OnEnd`** = filtering (all data finalized).
|
|
13
|
+
- Register via `.AddProcessor<T>()` — see WithTracing.md.
|
|
14
|
+
|
|
15
|
+
## Filtering — drop spans
|
|
16
|
+
|
|
17
|
+
Clear the `Recorded` flag to prevent export. Export processors (`BatchActivityExportProcessor`, `SimpleActivityExportProcessor`) check `Activity.Recorded` and skip when `false`.
|
|
18
|
+
|
|
19
|
+
```csharp
|
|
20
|
+
using System.Diagnostics;
|
|
21
|
+
using OpenTelemetry;
|
|
22
|
+
|
|
23
|
+
public class HealthCheckFilterProcessor : BaseProcessor<Activity>
|
|
24
|
+
{
|
|
25
|
+
private static readonly HashSet<string> SuppressedPaths = new(StringComparer.OrdinalIgnoreCase)
|
|
26
|
+
{
|
|
27
|
+
"/health", "/ready", "/healthz", "/liveness"
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
public override void OnEnd(Activity data)
|
|
31
|
+
{
|
|
32
|
+
var path = data.GetTagItem("url.path")?.ToString()
|
|
33
|
+
?? data.GetTagItem("http.route")?.ToString();
|
|
34
|
+
|
|
35
|
+
if (path != null && SuppressedPaths.Contains(path))
|
|
36
|
+
{
|
|
37
|
+
data.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
> **Important:** Do not rely on skipping `base.OnEnd()` — `CompositeProcessor` iterates all processors regardless. The `Recorded` flag is the correct filtering mechanism.
|
|
44
|
+
|
|
45
|
+
## Enrichment — add tags
|
|
46
|
+
|
|
47
|
+
Use `OnStart` to attach tags before the span completes:
|
|
48
|
+
|
|
49
|
+
```csharp
|
|
50
|
+
using System.Diagnostics;
|
|
51
|
+
using OpenTelemetry;
|
|
52
|
+
|
|
53
|
+
public class EnrichmentProcessor : BaseProcessor<Activity>
|
|
54
|
+
{
|
|
55
|
+
public override void OnStart(Activity data)
|
|
56
|
+
{
|
|
57
|
+
data.SetTag("deployment.environment", "production");
|
|
58
|
+
data.SetTag("cloud.region", "eastus");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Inspectable `Activity` properties
|
|
64
|
+
|
|
65
|
+
`DisplayName`, `Source.Name`, `Kind`, `Status`, `Duration`, `Tags` (via `GetTagItem()`), `Events`, `Links`, `ParentId`.
|
|
66
|
+
|
|
67
|
+
## Migration from Application Insights 2.x
|
|
68
|
+
|
|
69
|
+
> **Key difference:** A single `ITelemetryInitializer` or `ITelemetryProcessor` handled all signal types (requests, dependencies, traces, events). In OpenTelemetry, traces, logs, and metrics are separate pipelines — each processor only sees its own signal. If the old initializer/processor touched both signals (e.g., checked for `RequestTelemetry` and `TraceTelemetry`), you need two OpenTelemetry processors: `BaseProcessor<Activity>` for traces + `BaseProcessor<LogRecord>` for logs. If it only touched trace types (`RequestTelemetry`, `DependencyTelemetry`), a single `BaseProcessor<Activity>` is sufficient. Any `if (telemetry is MetricTelemetry) return;` guards can be removed — metrics have their own pipeline and never reach activity or log processors.
|
|
70
|
+
|
|
71
|
+
| 2.x Pattern | 3.x Equivalent |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `ITelemetryInitializer.Initialize(ITelemetry)` | `BaseProcessor<Activity>.OnStart(Activity)` — enrich traces |
|
|
74
|
+
| `ITelemetryInitializer` touching `TraceTelemetry`/`EventTelemetry` | `BaseProcessor<LogRecord>.OnEnd(LogRecord)` — enrich logs (see LogProcessors.md) |
|
|
75
|
+
| `ITelemetryProcessor.Process(ITelemetry)` | `BaseProcessor<Activity>.OnEnd(Activity)` — filter traces |
|
|
76
|
+
| `ITelemetryProcessor` filtering `TraceTelemetry` by severity | `ILoggingBuilder.AddFilter<OpenTelemetryLoggerProvider>()` — filter logs (see LogProcessors.md) |
|
|
77
|
+
| `services.AddApplicationInsightsTelemetryProcessor<T>()` | `.AddProcessor<T>()` on `TracerProviderBuilder` |
|
|
78
|
+
| Not calling `next.Process(item)` to drop | `data.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;` |
|
|
79
|
+
|
|
80
|
+
### Property mapping
|
|
81
|
+
|
|
82
|
+
| 2.x Property | Activity equivalent | LogRecord equivalent |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| `telemetry.Context.GlobalProperties["key"]` | `data.SetTag("key", value)` | Add to `data.Attributes` |
|
|
85
|
+
| `telemetry.Properties["key"]` | `data.SetTag("key", value)` | Add to `data.Attributes` |
|
|
86
|
+
| `request.Url.AbsolutePath` | `data.GetTagItem("url.path")` | N/A |
|
|
87
|
+
| `request.ResponseCode` / `dependency.ResultCode` | `data.GetTagItem("http.response.status_code")` | N/A |
|
|
88
|
+
| `request.Success = false` | `data.SetStatus(ActivityStatusCode.Error)` | N/A |
|
|
89
|
+
| `request.Name` / `dependency.Name` | `data.DisplayName` (get/set) | N/A |
|
|
90
|
+
| `dependency.Type` | `data.GetTagItem("db.system")` or `data.GetTagItem("rpc.system")` | N/A |
|
|
91
|
+
| `dependency.Target` | `data.GetTagItem("server.address")` | N/A |
|
|
92
|
+
| `dependency.Duration` | `data.Duration` | N/A |
|
|
93
|
+
| `trace.SeverityLevel` | N/A | `data.LogLevel` |
|
|
94
|
+
| `trace.Message` | N/A | `data.FormattedMessage` or `data.Attributes` |
|
|
95
|
+
| `telemetry.Context.User.AuthenticatedUserId` | `data.SetTag("enduser.id", value)` | N/A |
|
|
96
|
+
| `telemetry.Context.Operation.Id` | `data.TraceId` (read-only, set by framework) | `data.TraceId` |
|
|
97
|
+
| `telemetry.Context.Cloud.RoleName` | Not a processor concern — use `ConfigureResource(r => r.AddService("name"))` | Same |
|
|
98
|
+
|
|
99
|
+
### Telemetry type mapping
|
|
100
|
+
|
|
101
|
+
Old processors often check `if (telemetry is RequestTelemetry)` or `if (telemetry is DependencyTelemetry)`. In 3.x, check `Activity.Kind`:
|
|
102
|
+
|
|
103
|
+
| `ActivityKind` | Application Insights telemetry type |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| `Server` | `RequestTelemetry` |
|
|
106
|
+
| `Consumer` | `RequestTelemetry` (message-driven) or `DependencyTelemetry` (when acting as downstream call) |
|
|
107
|
+
| `Client` | `DependencyTelemetry` |
|
|
108
|
+
| `Producer` | `DependencyTelemetry` |
|
|
109
|
+
| `Internal` | `DependencyTelemetry` (if parent is `Server`/`Consumer`) |
|
|
110
|
+
|
|
111
|
+
Other signal types:
|
|
112
|
+
|
|
113
|
+
| Source | Application Insights telemetry type |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| `ILogger` logs | `TraceTelemetry` |
|
|
116
|
+
| `ILogger` logs with `microsoft.custom_event.name` attribute | `EventTelemetry` |
|
|
117
|
+
| Exceptions logged via `ILogger.LogError` / `LogCritical` | `ExceptionTelemetry` — now a `LogRecord` with exception attributes |
|
|
118
|
+
| Exceptions on spans | `ExceptionTelemetry` — now an `Activity.Event` named `exception` (check `data.Events`) |
|
|
119
|
+
| `Meter` measurements | `MetricTelemetry` |
|
package/dist/Instrumentation/Resources/api-reference/dotnet/AddApplicationInsightsTelemetry.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AddApplicationInsightsTelemetry
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
source: NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# AddApplicationInsightsTelemetry
|
|
9
|
+
|
|
10
|
+
**Package:** `Microsoft.ApplicationInsights.AspNetCore` (3.x)
|
|
11
|
+
|
|
12
|
+
## Signatures
|
|
13
|
+
|
|
14
|
+
```csharp
|
|
15
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
16
|
+
|
|
17
|
+
// 1. Parameterless — reads config from appsettings.json / env vars
|
|
18
|
+
public static IServiceCollection AddApplicationInsightsTelemetry(
|
|
19
|
+
this IServiceCollection services);
|
|
20
|
+
|
|
21
|
+
// 2. IConfiguration — binds "ApplicationInsights" section
|
|
22
|
+
public static IServiceCollection AddApplicationInsightsTelemetry(
|
|
23
|
+
this IServiceCollection services,
|
|
24
|
+
IConfiguration configuration);
|
|
25
|
+
|
|
26
|
+
// 3. Action delegate — configure options inline
|
|
27
|
+
public static IServiceCollection AddApplicationInsightsTelemetry(
|
|
28
|
+
this IServiceCollection services,
|
|
29
|
+
Action<ApplicationInsightsServiceOptions> options);
|
|
30
|
+
|
|
31
|
+
// 4. Options instance — pass a pre-built options object
|
|
32
|
+
public static IServiceCollection AddApplicationInsightsTelemetry(
|
|
33
|
+
this IServiceCollection services,
|
|
34
|
+
ApplicationInsightsServiceOptions options);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
All overloads return `IServiceCollection`. Overloads 2–4 call overload 1 internally, then apply configuration.
|
|
38
|
+
|
|
39
|
+
## ApplicationInsightsServiceOptions
|
|
40
|
+
|
|
41
|
+
Namespace: `Microsoft.ApplicationInsights.AspNetCore.Extensions`
|
|
42
|
+
|
|
43
|
+
| Property | Type | Default | Description |
|
|
44
|
+
|---|---|---|---|
|
|
45
|
+
| `ConnectionString` | `string` | `null` | Connection string for Application Insights. Can also be set via env var or config (see below). |
|
|
46
|
+
| `Credential` | `TokenCredential` | `null` | AAD credential for token-based authentication. When null, the instrumentation key from the connection string is used. |
|
|
47
|
+
| `ApplicationVersion` | `string` | Entry assembly version | Application version reported with telemetry. |
|
|
48
|
+
| `EnableQuickPulseMetricStream` | `bool` | `true` | Enables Live Metrics. |
|
|
49
|
+
| `EnablePerformanceCounterCollectionModule` | `bool` | `true` | Enables performance counter collection. |
|
|
50
|
+
| `EnableDependencyTrackingTelemetryModule` | `bool` | `true` | Enables HTTP and SQL dependency tracking. |
|
|
51
|
+
| `EnableRequestTrackingTelemetryModule` | `bool` | `true` | Enables ASP.NET Core request tracking. |
|
|
52
|
+
| `AddAutoCollectedMetricExtractor` | `bool` | `true` | Enables standard metric extraction. |
|
|
53
|
+
| `TracesPerSecond` | `double?` | `null` (effective: `5`) | Rate-limited sampling — targets this many traces per second. Must be ≥ 0. |
|
|
54
|
+
| `SamplingRatio` | `float?` | `null` | Fixed-rate sampling (0.0–1.0, where 1.0 = no sampling). When set, overrides `TracesPerSecond`. |
|
|
55
|
+
| `EnableTraceBasedLogsSampler` | `bool?` | `null` (effective: `true`) | When true, logs are sampled with their parent trace. Set `false` to collect all logs. |
|
|
56
|
+
| `EnableAuthenticationTrackingJavaScript` | `bool` | `false` | Injects authenticated user tracking in the JavaScript snippet. ASP.NET Core only. |
|
|
57
|
+
|
|
58
|
+
## JavaScriptSnippet
|
|
59
|
+
|
|
60
|
+
Automatically registered as a singleton (`IJavaScriptSnippet` and `JavaScriptSnippet`) when `AddApplicationInsightsTelemetry()` is called.
|
|
61
|
+
|
|
62
|
+
### Razor usage
|
|
63
|
+
|
|
64
|
+
```cshtml
|
|
65
|
+
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
|
|
66
|
+
|
|
67
|
+
<!-- FullScript includes <script> tags -->
|
|
68
|
+
@Html.Raw(JavaScriptSnippet.FullScript)
|
|
69
|
+
|
|
70
|
+
<!-- ScriptBody returns JS only (no <script> tags) — use inside your own script block -->
|
|
71
|
+
<script>
|
|
72
|
+
@Html.Raw(JavaScriptSnippet.ScriptBody)
|
|
73
|
+
</script>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- `FullScript` — complete `<script>` block ready to drop into a layout page. Return `string.Empty` when telemetry is disabled or connection string is not set.
|
|
77
|
+
- `ScriptBody` — JavaScript only, for use inside an existing `<script>` tag.
|
|
78
|
+
|
|
79
|
+
## Minimal example
|
|
80
|
+
|
|
81
|
+
```csharp
|
|
82
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
83
|
+
|
|
84
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
85
|
+
builder.Services.AddApplicationInsightsTelemetry();
|
|
86
|
+
var app = builder.Build();
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Set the connection string via environment variable:
|
|
90
|
+
```
|
|
91
|
+
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...;IngestionEndpoint=...
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Or in `appsettings.json`:
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"ApplicationInsights": {
|
|
98
|
+
"ConnectionString": "InstrumentationKey=...;IngestionEndpoint=..."
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Full example
|
|
104
|
+
|
|
105
|
+
```csharp
|
|
106
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
107
|
+
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
|
|
108
|
+
|
|
109
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
110
|
+
builder.Services.AddApplicationInsightsTelemetry(options =>
|
|
111
|
+
{
|
|
112
|
+
options.ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...";
|
|
113
|
+
options.EnableQuickPulseMetricStream = true;
|
|
114
|
+
options.SamplingRatio = 0.5f; // Collect 50% of telemetry
|
|
115
|
+
options.EnableAuthenticationTrackingJavaScript = true;
|
|
116
|
+
});
|
|
117
|
+
var app = builder.Build();
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Behavior notes
|
|
121
|
+
|
|
122
|
+
- Connection string resolution order: `ApplicationInsightsServiceOptions.ConnectionString` → env var `APPLICATIONINSIGHTS_CONNECTION_STRING` → config key `ApplicationInsights:ConnectionString`.
|
|
123
|
+
- `TracesPerSecond` is the default sampling mode (effective default `5`). Set `SamplingRatio` for fixed-rate sampling instead.
|
|
124
|
+
- Additional OTel sources/meters can be added: `builder.Services.AddOpenTelemetry().WithTracing(t => t.AddSource("MySource"))`.
|
|
125
|
+
## See also
|
|
126
|
+
|
|
127
|
+
- UseAzureMonitor (distro)(see in UseAzureMonitor.md)
|
|
128
|
+
- UseAzureMonitorExporter(see in UseAzureMonitorExporter.md)
|
|
129
|
+
- App Insights 2.x → 3.x Migration(see in appinsights-2x-to-3x-code-migration.md)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AddApplicationInsightsTelemetryWorkerService
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
source: NETCORE/src/Microsoft.ApplicationInsights.WorkerService/ApplicationInsightsExtensions.cs
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# AddApplicationInsightsTelemetryWorkerService
|
|
9
|
+
|
|
10
|
+
**Package:** `Microsoft.ApplicationInsights.WorkerService` (3.x)
|
|
11
|
+
|
|
12
|
+
## Signatures
|
|
13
|
+
|
|
14
|
+
```csharp
|
|
15
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
16
|
+
|
|
17
|
+
// 1. Parameterless — reads config from appsettings.json / env vars
|
|
18
|
+
public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(
|
|
19
|
+
this IServiceCollection services);
|
|
20
|
+
|
|
21
|
+
// 2. IConfiguration — binds "ApplicationInsights" section
|
|
22
|
+
public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(
|
|
23
|
+
this IServiceCollection services,
|
|
24
|
+
IConfiguration configuration);
|
|
25
|
+
|
|
26
|
+
// 3. Action delegate — configure options inline
|
|
27
|
+
public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(
|
|
28
|
+
this IServiceCollection services,
|
|
29
|
+
Action<ApplicationInsightsServiceOptions> options);
|
|
30
|
+
|
|
31
|
+
// 4. Options instance — pass a pre-built options object
|
|
32
|
+
public static IServiceCollection AddApplicationInsightsTelemetryWorkerService(
|
|
33
|
+
this IServiceCollection services,
|
|
34
|
+
ApplicationInsightsServiceOptions options);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
All overloads return `IServiceCollection`. Overloads 2–4 call overload 1 internally, then apply configuration.
|
|
38
|
+
|
|
39
|
+
## ApplicationInsightsServiceOptions
|
|
40
|
+
|
|
41
|
+
Namespace: `Microsoft.ApplicationInsights.WorkerService`
|
|
42
|
+
|
|
43
|
+
| Property | Type | Default | Description |
|
|
44
|
+
|---|---|---|---|
|
|
45
|
+
| `ConnectionString` | `string` | `null` | Connection string for Application Insights. Can also be set via env var or config (see below). |
|
|
46
|
+
| `Credential` | `TokenCredential` | `null` | AAD credential for token-based authentication. When null, the instrumentation key from the connection string is used. |
|
|
47
|
+
| `ApplicationVersion` | `string` | Entry assembly version | Application version reported with telemetry. |
|
|
48
|
+
| `EnableQuickPulseMetricStream` | `bool` | `true` | Enables Live Metrics. |
|
|
49
|
+
| `EnablePerformanceCounterCollectionModule` | `bool` | `true` | Enables performance counter collection. |
|
|
50
|
+
| `EnableDependencyTrackingTelemetryModule` | `bool` | `true` | Enables HTTP and SQL dependency tracking. |
|
|
51
|
+
| `AddAutoCollectedMetricExtractor` | `bool` | `true` | Enables standard metric extraction. |
|
|
52
|
+
| `TracesPerSecond` | `double?` | `null` (effective: `5`) | Rate-limited sampling — targets this many traces per second. Must be ≥ 0. |
|
|
53
|
+
| `SamplingRatio` | `float?` | `null` | Fixed-rate sampling (0.0–1.0, where 1.0 = no sampling). When set, overrides `TracesPerSecond`. |
|
|
54
|
+
| `EnableTraceBasedLogsSampler` | `bool?` | `null` (effective: `true`) | When true, logs are sampled with their parent trace. Set `false` to collect all logs. |
|
|
55
|
+
|
|
56
|
+
**Note:** Unlike the ASP.NET Core package, WorkerService does not include `EnableRequestTrackingTelemetryModule` or `EnableAuthenticationTrackingJavaScript`.
|
|
57
|
+
|
|
58
|
+
## Minimal example
|
|
59
|
+
|
|
60
|
+
```csharp
|
|
61
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
62
|
+
|
|
63
|
+
var builder = Host.CreateDefaultBuilder(args);
|
|
64
|
+
builder.ConfigureServices(services =>
|
|
65
|
+
{
|
|
66
|
+
services.AddApplicationInsightsTelemetryWorkerService();
|
|
67
|
+
});
|
|
68
|
+
var host = builder.Build();
|
|
69
|
+
await host.RunAsync();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Set the connection string via environment variable:
|
|
73
|
+
```
|
|
74
|
+
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...;IngestionEndpoint=...
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Or in `appsettings.json`:
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"ApplicationInsights": {
|
|
81
|
+
"ConnectionString": "InstrumentationKey=...;IngestionEndpoint=..."
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Full example
|
|
87
|
+
|
|
88
|
+
```csharp
|
|
89
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
90
|
+
using Microsoft.ApplicationInsights.WorkerService;
|
|
91
|
+
|
|
92
|
+
var builder = Host.CreateDefaultBuilder(args);
|
|
93
|
+
builder.ConfigureServices(services =>
|
|
94
|
+
{
|
|
95
|
+
services.AddApplicationInsightsTelemetryWorkerService(options =>
|
|
96
|
+
{
|
|
97
|
+
options.ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...";
|
|
98
|
+
options.EnableQuickPulseMetricStream = true;
|
|
99
|
+
options.SamplingRatio = 0.5f; // Collect 50% of telemetry
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
var host = builder.Build();
|
|
103
|
+
await host.RunAsync();
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Behavior notes
|
|
107
|
+
|
|
108
|
+
- Connection string resolution order: `ApplicationInsightsServiceOptions.ConnectionString` → env var `APPLICATIONINSIGHTS_CONNECTION_STRING` → config key `ApplicationInsights:ConnectionString`.
|
|
109
|
+
- `TracesPerSecond` is the default sampling mode (effective default `5`). Set `SamplingRatio` for fixed-rate sampling instead.
|
|
110
|
+
- Additional OTel sources/meters can be added: `services.AddOpenTelemetry().WithTracing(t => t.AddSource("MySource"))`.
|
|
111
|
+
## See also
|
|
112
|
+
|
|
113
|
+
- UseAzureMonitor (distro)(see in UseAzureMonitor.md)
|
|
114
|
+
- UseAzureMonitorExporter(see in UseAzureMonitorExporter.md)
|
|
115
|
+
- Worker Service 2.x → 3.x Migration(see in workerservice-2x-to-3x-code-migration.md)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AddOpenTelemetry
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# services.AddOpenTelemetry()
|
|
8
|
+
|
|
9
|
+
> [!NOTE]
|
|
10
|
+
> This is the recommended approach for any application using the .NET Generic
|
|
11
|
+
> Host (ASP.NET Core, Worker Services, MAUI, etc.).
|
|
12
|
+
|
|
13
|
+
## When to use
|
|
14
|
+
|
|
15
|
+
- **ASP.NET Core** web apps and APIs.
|
|
16
|
+
- **Worker services** (`BackgroundService` / `IHostedService`).
|
|
17
|
+
- Any application that already calls `Host.CreateDefaultBuilder()` or
|
|
18
|
+
`WebApplication.CreateBuilder()`.
|
|
19
|
+
- Production services where you want **automatic lifecycle management** - no
|
|
20
|
+
manual `Dispose()` calls.
|
|
21
|
+
|
|
22
|
+
## Minimal example
|
|
23
|
+
|
|
24
|
+
```csharp
|
|
25
|
+
using OpenTelemetry.Trace;
|
|
26
|
+
|
|
27
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
28
|
+
|
|
29
|
+
builder.Services.AddOpenTelemetry()
|
|
30
|
+
.ConfigureResource(r => r.AddService("my-web-api"))
|
|
31
|
+
.WithTracing(tracing => tracing
|
|
32
|
+
.AddAspNetCoreInstrumentation()
|
|
33
|
+
.AddConsoleExporter());
|
|
34
|
+
|
|
35
|
+
var app = builder.Build();
|
|
36
|
+
app.MapGet("/", () => "Hello World");
|
|
37
|
+
app.Run();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Full multi-signal example
|
|
41
|
+
|
|
42
|
+
```csharp
|
|
43
|
+
using OpenTelemetry.Logs;
|
|
44
|
+
using OpenTelemetry.Metrics;
|
|
45
|
+
using OpenTelemetry.Trace;
|
|
46
|
+
|
|
47
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
48
|
+
|
|
49
|
+
// Clear default log providers if you want OTel to be the sole log sink
|
|
50
|
+
builder.Logging.ClearProviders();
|
|
51
|
+
|
|
52
|
+
builder.Services.AddOpenTelemetry()
|
|
53
|
+
.ConfigureResource(r => r
|
|
54
|
+
.AddService(
|
|
55
|
+
serviceName: "my-web-api",
|
|
56
|
+
serviceVersion: "1.0.0"))
|
|
57
|
+
.WithTracing(tracing => tracing
|
|
58
|
+
.AddAspNetCoreInstrumentation()
|
|
59
|
+
.AddHttpClientInstrumentation()
|
|
60
|
+
.AddSource("MyApp")
|
|
61
|
+
.AddOtlpExporter())
|
|
62
|
+
.WithMetrics(metrics => metrics
|
|
63
|
+
.AddAspNetCoreInstrumentation()
|
|
64
|
+
.AddHttpClientInstrumentation()
|
|
65
|
+
.AddMeter("MyApp")
|
|
66
|
+
.AddOtlpExporter())
|
|
67
|
+
.WithLogging(logging => logging
|
|
68
|
+
.AddOtlpExporter());
|
|
69
|
+
|
|
70
|
+
var app = builder.Build();
|
|
71
|
+
app.MapGet("/", () => "Hello World");
|
|
72
|
+
app.Run();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Worker service example
|
|
76
|
+
|
|
77
|
+
```csharp
|
|
78
|
+
using OpenTelemetry.Trace;
|
|
79
|
+
|
|
80
|
+
var builder = Host.CreateApplicationBuilder(args);
|
|
81
|
+
|
|
82
|
+
builder.Services.AddOpenTelemetry()
|
|
83
|
+
.ConfigureResource(r => r.AddService("my-worker"))
|
|
84
|
+
.WithTracing(tracing => tracing
|
|
85
|
+
.AddSource("MyWorker")
|
|
86
|
+
.AddOtlpExporter());
|
|
87
|
+
|
|
88
|
+
builder.Services.AddHostedService<MyWorker>();
|
|
89
|
+
|
|
90
|
+
var host = builder.Build();
|
|
91
|
+
host.Run();
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## API surface
|
|
95
|
+
|
|
96
|
+
`AddOpenTelemetry()` returns an `OpenTelemetryBuilder` that implements
|
|
97
|
+
`IOpenTelemetryBuilder`:
|
|
98
|
+
|
|
99
|
+
| Method | Purpose |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `.WithTracing(Action<TracerProviderBuilder>)` | Configure tracing |
|
|
102
|
+
| `.WithMetrics(Action<MeterProviderBuilder>)` | Configure metrics |
|
|
103
|
+
| `.WithLogging(Action<LoggerProviderBuilder>)` | Configure logging |
|
|
104
|
+
| `.ConfigureResource(Action<ResourceBuilder>)` | Set resource attributes (shared across all signals) |
|
|
105
|
+
|
|
106
|
+
## Lifecycle
|
|
107
|
+
|
|
108
|
+
- **Host-managed.** The host starts the SDK via an `IHostedService` and
|
|
109
|
+
disposes it on graceful shutdown. You do **not** call `Dispose()` yourself.
|
|
110
|
+
- **Safe to call multiple times.** Calling `AddOpenTelemetry()` from multiple
|
|
111
|
+
libraries or configuration modules is safe - only one `TracerProvider` and
|
|
112
|
+
one `MeterProvider` are created per `IServiceCollection`.
|
|
113
|
+
- **DI-integrated.** Processors, exporters, and any custom services registered
|
|
114
|
+
in the DI container are available to the SDK. You can inject
|
|
115
|
+
`TracerProvider`, `MeterProvider`, or `ILoggerFactory` anywhere via
|
|
116
|
+
constructor injection.
|
|
117
|
+
|
|
118
|
+
## Dependency injection tips
|
|
119
|
+
|
|
120
|
+
### Accessing the TracerProvider
|
|
121
|
+
|
|
122
|
+
```csharp
|
|
123
|
+
app.MapGet("/trace-id", (TracerProvider tp) =>
|
|
124
|
+
{
|
|
125
|
+
// TracerProvider is available via DI
|
|
126
|
+
return Activity.Current?.TraceId.ToString() ?? "none";
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Registering a custom processor
|
|
131
|
+
|
|
132
|
+
```csharp
|
|
133
|
+
builder.Services.AddOpenTelemetry()
|
|
134
|
+
.WithTracing(tracing => tracing
|
|
135
|
+
.AddProcessor<MyFilteringProcessor>()); // resolved from DI
|
|
136
|
+
|
|
137
|
+
builder.Services.AddSingleton<MyFilteringProcessor>();
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Comparison with the non-hosted builders
|
|
141
|
+
|
|
142
|
+
| Concern | `AddOpenTelemetry()` | `OpenTelemetrySdk.Create()` |
|
|
143
|
+
| --- | --- | --- |
|
|
144
|
+
| Requires Generic Host | Yes | No |
|
|
145
|
+
| Lifecycle | Automatic (host) | Manual (`Dispose()`) |
|
|
146
|
+
| DI container | App's container | SDK-internal container |
|
|
147
|
+
| Safe to call multiple times | Yes | N/A (single call) |
|
|
148
|
+
| Builder API | Same `IOpenTelemetryBuilder` | Same `IOpenTelemetryBuilder` |
|
|
149
|
+
|
|
150
|
+
> [!TIP]
|
|
151
|
+
> **No host?** Use
|
|
152
|
+
> `OpenTelemetrySdk.Create()`(see in OpenTelemetrySdkCreate.md) for the same
|
|
153
|
+
> builder API with manual lifecycle control.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: ApplicationInsightsWeb
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Microsoft.ApplicationInsights.Web — API Reference
|
|
8
|
+
|
|
9
|
+
## Package
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Microsoft.ApplicationInsights.Web
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Target: .NET Framework 4.6.2+
|
|
16
|
+
|
|
17
|
+
## ApplicationInsights.config elements
|
|
18
|
+
|
|
19
|
+
| Element | Default | Description |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `ConnectionString` | — | **Required.** Azure Monitor connection string. |
|
|
22
|
+
| `DisableTelemetry` | `false` | Disable all telemetry collection. |
|
|
23
|
+
| `ApplicationVersion` | — | Sets `service.version` resource attribute. |
|
|
24
|
+
| `TracesPerSecond` | `5.0` | Rate-limited sampling (traces per second). |
|
|
25
|
+
| `SamplingRatio` | — | Fixed-rate sampling (0.0–1.0). Overrides `TracesPerSecond` if set. |
|
|
26
|
+
| `EnableTraceBasedLogsSampler` | `true` | Logs follow parent trace sampling decision. |
|
|
27
|
+
| `StorageDirectory` | — | Directory for offline telemetry storage. |
|
|
28
|
+
| `DisableOfflineStorage` | `false` | Disable offline storage. |
|
|
29
|
+
| `EnableQuickPulseMetricStream` | `true` | Enable Live Metrics. |
|
|
30
|
+
| `EnablePerformanceCounterCollectionModule` | `true` | Collect performance counters. |
|
|
31
|
+
| `EnableDependencyTrackingTelemetryModule` | `true` | Track SQL/HTTP dependencies. |
|
|
32
|
+
| `EnableRequestTrackingTelemetryModule` | `true` | Track incoming HTTP requests. |
|
|
33
|
+
| `AddAutoCollectedMetricExtractor` | `true` | Extract standard metrics. |
|
|
34
|
+
|
|
35
|
+
## Removed in 3.x (from 2.x)
|
|
36
|
+
|
|
37
|
+
| Element/Section | Status |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `<InstrumentationKey>` | **Removed** — use `<ConnectionString>` |
|
|
40
|
+
| `<TelemetryInitializers>` | **Removed** — initializers are now internal Activity Processors |
|
|
41
|
+
| `<TelemetryModules>` | **Removed** — modules are auto-configured internally |
|
|
42
|
+
| `<TelemetryProcessors>` | **Removed** — use `ConfigureOpenTelemetryBuilder` for custom processors |
|
|
43
|
+
| `<TelemetryChannel>` | **Removed** — export pipeline managed by OpenTelemetry |
|
|
44
|
+
|
|
45
|
+
## HTTP modules required in Web.config
|
|
46
|
+
|
|
47
|
+
### IIS Integrated mode (`system.webServer/modules`)
|
|
48
|
+
|
|
49
|
+
```xml
|
|
50
|
+
<add name="ApplicationInsightsWebTracking"
|
|
51
|
+
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
|
|
52
|
+
preCondition="managedHandler" />
|
|
53
|
+
<add name="TelemetryHttpModule"
|
|
54
|
+
type="OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule, OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule"
|
|
55
|
+
preCondition="integratedMode,managedHandler" />
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### IIS Classic mode (`system.web/httpModules`)
|
|
59
|
+
|
|
60
|
+
```xml
|
|
61
|
+
<add name="ApplicationInsightsWebTracking"
|
|
62
|
+
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
> These are auto-configured by the NuGet package install.
|
|
66
|
+
|
|
67
|
+
## TelemetryClient usage
|
|
68
|
+
|
|
69
|
+
`TelemetryClient` works the same as in ASP.NET Core 3.x. See TelemetryClient.md for breaking changes.
|
|
70
|
+
|
|
71
|
+
Key difference: in classic ASP.NET, create via `new TelemetryClient(TelemetryConfiguration.CreateDefault())` or let `ApplicationInsightsHttpModule` initialize the configuration first.
|
|
72
|
+
|
|
73
|
+
```csharp
|
|
74
|
+
var client = new TelemetryClient(TelemetryConfiguration.CreateDefault());
|
|
75
|
+
client.TrackEvent("OrderCreated", new Dictionary<string, string> { ["OrderId"] = orderId });
|
|
76
|
+
client.TrackMetric("ProcessingTime", elapsed);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## ConfigureOpenTelemetryBuilder
|
|
80
|
+
|
|
81
|
+
The primary extensibility point in 3.x for classic ASP.NET. Add custom processors, exporters, or resource attributes:
|
|
82
|
+
|
|
83
|
+
```csharp
|
|
84
|
+
// In Global.asax.cs Application_Start()
|
|
85
|
+
var config = TelemetryConfiguration.CreateDefault();
|
|
86
|
+
config.ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...";
|
|
87
|
+
config.ConfigureOpenTelemetryBuilder(otel =>
|
|
88
|
+
{
|
|
89
|
+
otel.WithTracing(tracing =>
|
|
90
|
+
{
|
|
91
|
+
tracing.AddProcessor<MyFilterProcessor>();
|
|
92
|
+
tracing.AddConsoleExporter(); // For debugging
|
|
93
|
+
});
|
|
94
|
+
otel.ConfigureResource(r => r.AddService("MyWebApp"));
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Notes
|
|
99
|
+
|
|
100
|
+
- The NuGet package install handles all configuration — no code changes needed for basic setup.
|
|
101
|
+
- `TelemetryCorrelationHttpModule` is **not needed** in 3.x — OpenTelemetry handles correlation natively.
|
|
102
|
+
- Connection string can be set in `ApplicationInsights.config`, in code, or via `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable.
|
|
103
|
+
- **Non-DI:** Classic ASP.NET does not use `IServiceCollection`. Use `TelemetryConfiguration.ConfigureOpenTelemetryBuilder` for extensibility.
|