@azure/mcp-linux-arm64 2.0.0-beta.27 โ 2.0.0-beta.28
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/README.md +11 -6
- package/dist/Resources/api-reference/dotnet/ActivityProcessors.md +119 -0
- package/dist/Resources/api-reference/dotnet/AddApplicationInsightsTelemetry.md +129 -0
- package/dist/Resources/api-reference/dotnet/AddOpenTelemetry.md +153 -0
- package/dist/Resources/api-reference/dotnet/AzureMonitorExporter.md +137 -0
- package/dist/Resources/api-reference/dotnet/ConfigureOpenTelemetryProvider.md +195 -0
- package/dist/Resources/api-reference/dotnet/ConfigureResource.md +119 -0
- package/dist/Resources/api-reference/dotnet/LogProcessors.md +99 -0
- package/dist/Resources/api-reference/dotnet/OpenTelemetrySdkCreate.md +146 -0
- package/dist/Resources/api-reference/dotnet/Sampling.md +86 -0
- package/dist/Resources/api-reference/dotnet/SdkCreateTracerProviderBuilder.md +127 -0
- package/dist/Resources/api-reference/dotnet/UseAzureMonitor.md +96 -0
- package/dist/Resources/api-reference/dotnet/UseAzureMonitorExporter.md +146 -0
- package/dist/Resources/api-reference/dotnet/WithLogging.md +109 -0
- package/dist/Resources/api-reference/dotnet/WithMetrics.md +105 -0
- package/dist/Resources/api-reference/dotnet/WithTracing.md +91 -0
- package/dist/Resources/concepts/dotnet/azure-monitor-distro.md +102 -0
- package/dist/Resources/concepts/dotnet/opentelemetry-pipeline.md +57 -0
- package/dist/Resources/examples/dotnet/aspnetcore-setup.md +156 -0
- package/dist/Resources/migration/dotnet/appinsights-2x-to-3x-code-migration.md +134 -0
- package/dist/Resources/migration/dotnet/appinsights-2x-to-3x-no-code-change.md +92 -0
- package/dist/azmcp +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,10 +96,6 @@ Check out the remote hosting [azd templates](https://github.com/microsoft/mcp/bl
|
|
|
96
96
|
* List Microsoft Foundry agents
|
|
97
97
|
* Connect and query Microsoft Foundry agents
|
|
98
98
|
* Evaluate Microsoft Foundry agents
|
|
99
|
-
* Get SDK samples for interacting with Microsoft Foundry agent
|
|
100
|
-
* Create Microsoft Foundry agent threads
|
|
101
|
-
* List Microsoft Foundry agent threads
|
|
102
|
-
* Get messages of a Microsoft Foundry thread
|
|
103
99
|
|
|
104
100
|
### ๐ Azure Advisor
|
|
105
101
|
|
|
@@ -276,6 +272,14 @@ Example prompts that generate Azure CLI commands:
|
|
|
276
272
|
|
|
277
273
|
* "Query my Log Analytics workspace"
|
|
278
274
|
|
|
275
|
+
### ๐งญ Azure Monitor Instrumentation
|
|
276
|
+
|
|
277
|
+
* "List available Azure Monitor onboarding learning resources"
|
|
278
|
+
* "Get the learning resource at 'concepts/dotnet/opentelemetry-pipeline.md'"
|
|
279
|
+
* "Start Azure Monitor instrumentation orchestration for my local workspace"
|
|
280
|
+
* "Continue to the next orchestration step after I complete the previous action"
|
|
281
|
+
* "Send brownfield analysis findings to continue migration planning"
|
|
282
|
+
|
|
279
283
|
### ๐ง Azure Resource Management
|
|
280
284
|
|
|
281
285
|
* "List my resource groups"
|
|
@@ -315,9 +319,9 @@ Example prompts that generate Azure CLI commands:
|
|
|
315
319
|
|
|
316
320
|
### ๐๏ธ Azure Well-Architected Framework
|
|
317
321
|
|
|
322
|
+
* "List all services with Well-Architected Framework guidance"
|
|
323
|
+
* "What services have architectural guidance?"
|
|
318
324
|
* "Get Well-Architected Framework guidance for App Service"
|
|
319
|
-
* "What's the WAF guidance for a VM?"
|
|
320
|
-
* "Show me the best practices for virtual machines"
|
|
321
325
|
* "What's the architectural guidance for Azure Cosmos DB?"
|
|
322
326
|
|
|
323
327
|
## Complete List of Supported Azure Services
|
|
@@ -353,6 +357,7 @@ The Azure MCP Server provides tools for interacting with **43+ Azure service are
|
|
|
353
357
|
- ๐ช **Azure Marketplace** - Product discovery
|
|
354
358
|
- ๐ **Azure Migrate** - Platform Landing Zone generation and modification guidance
|
|
355
359
|
- ๐ **Azure Monitor** - Logging, metrics, and health monitoring
|
|
360
|
+
- ๐งญ **Azure Monitor Instrumentation** - Deterministic onboarding and migration workflow for instrumenting local applications
|
|
356
361
|
- โ๏ธ **Azure Policy** - Policies set to enforce organizational standards
|
|
357
362
|
- โ๏ธ **Azure Native ISV Services** - Third-party integrations
|
|
358
363
|
- ๐ก๏ธ **Azure Quick Review CLI** - Compliance scanning
|
|
@@ -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` |
|
|
@@ -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,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,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AzureMonitorExporter
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
source: src/AzureMonitorExporterExtensions.cs, src/AzureMonitorExporterOptions.cs
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# AddAzureMonitor*Exporter
|
|
9
|
+
|
|
10
|
+
**Namespace:** `Azure.Monitor.OpenTelemetry.Exporter`
|
|
11
|
+
|
|
12
|
+
## When to use
|
|
13
|
+
|
|
14
|
+
- You are building a **console app, CLI tool, or background job** without the .NET Generic Host.
|
|
15
|
+
- You need to export **only a subset** of signals (e.g., traces and metrics but not logs).
|
|
16
|
+
- You need **different options per signal** (e.g., different credentials or storage directories).
|
|
17
|
+
|
|
18
|
+
## Signatures
|
|
19
|
+
|
|
20
|
+
```csharp
|
|
21
|
+
public static TracerProviderBuilder AddAzureMonitorTraceExporter(
|
|
22
|
+
this TracerProviderBuilder builder,
|
|
23
|
+
Action<AzureMonitorExporterOptions>? configure = null,
|
|
24
|
+
TokenCredential? credential = null,
|
|
25
|
+
string? name = null);
|
|
26
|
+
|
|
27
|
+
public static MeterProviderBuilder AddAzureMonitorMetricExporter(
|
|
28
|
+
this MeterProviderBuilder builder,
|
|
29
|
+
Action<AzureMonitorExporterOptions>? configure = null,
|
|
30
|
+
TokenCredential? credential = null,
|
|
31
|
+
string? name = null);
|
|
32
|
+
|
|
33
|
+
public static LoggerProviderBuilder AddAzureMonitorLogExporter(
|
|
34
|
+
this LoggerProviderBuilder builder,
|
|
35
|
+
Action<AzureMonitorExporterOptions>? configure = null,
|
|
36
|
+
TokenCredential? credential = null,
|
|
37
|
+
string? name = null);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
A legacy overload extending `OpenTelemetryLoggerOptions` also exists but is superseded by the `LoggerProviderBuilder` version above.
|
|
41
|
+
|
|
42
|
+
## Behavior notes
|
|
43
|
+
|
|
44
|
+
- **Cannot** be combined with `UseAzureMonitorExporter` in the same app โ a runtime exception is thrown.
|
|
45
|
+
- **Live Metrics** is not supported by per-signal methods. Setting `EnableLiveMetrics = true` has no effect โ a warning is logged and the setting is ignored.
|
|
46
|
+
- For hosted apps (ASP.NET Core, Worker Services), prefer `UseAzureMonitorExporter()`(see in UseAzureMonitorExporter.md) โ it registers all three signals in one call with Live Metrics support.
|
|
47
|
+
|
|
48
|
+
## AzureMonitorExporterOptions
|
|
49
|
+
|
|
50
|
+
Inherits `Azure.Core.ClientOptions`.
|
|
51
|
+
|
|
52
|
+
| Property | Type | Default | Description |
|
|
53
|
+
|---|---|---|---|
|
|
54
|
+
| `ConnectionString` | `string` | `null` | Application Insights connection string. Falls back to `APPLICATIONINSIGHTS_CONNECTION_STRING` env var. |
|
|
55
|
+
| `Credential` | `TokenCredential` | `null` | Azure AD token credential for Entra-based auth. |
|
|
56
|
+
| `SamplingRatio` | `float` | `1.0F` | Fixed-percentage sampling ratio (0.0โ1.0). Only used when `TracesPerSecond` is `null`. |
|
|
57
|
+
| `TracesPerSecond` | `double?` | `5.0` | Rate-limited sampling target. Takes precedence over `SamplingRatio`. Set to `null` to use fixed-percentage sampling. |
|
|
58
|
+
| `StorageDirectory` | `string` | `null` | Custom directory for offline/retry storage. Uses OS temp by default. |
|
|
59
|
+
| `DisableOfflineStorage` | `bool` | `false` | Disables persistent storage for failed telemetry. |
|
|
60
|
+
| `EnableLiveMetrics` | `bool` | `true` | **Ignored** by per-signal methods. Only applies with `UseAzureMonitorExporter`. |
|
|
61
|
+
| `EnableTraceBasedLogsSampler` | `bool` | `true` | When `true`, only logs correlated to sampled traces are exported. Logs without trace context are always exported. |
|
|
62
|
+
|
|
63
|
+
## Sampling
|
|
64
|
+
|
|
65
|
+
`AddAzureMonitorTraceExporter` automatically configures a trace sampler โ you do not need to set one yourself.
|
|
66
|
+
|
|
67
|
+
**Two modes**, controlled by `TracesPerSecond` and `SamplingRatio`:
|
|
68
|
+
|
|
69
|
+
| Mode | Activated when | Sampler | Example |
|
|
70
|
+
|---|---|---|---|
|
|
71
|
+
| Rate-limited (default) | `TracesPerSecond` is non-null | `RateLimitedSampler` โ caps throughput to N traces/sec | `TracesPerSecond = 5.0` โ ~5 traces/sec |
|
|
72
|
+
| Fixed-percentage | `TracesPerSecond` is `null` | `ApplicationInsightsSampler` โ samples a fixed ratio | `SamplingRatio = 0.4F` โ 40% of traces |
|
|
73
|
+
|
|
74
|
+
**Environment variable overrides** โ `OTEL_TRACES_SAMPLER` / `OTEL_TRACES_SAMPLER_ARG`:
|
|
75
|
+
|
|
76
|
+
| `OTEL_TRACES_SAMPLER` | `OTEL_TRACES_SAMPLER_ARG` | Effect |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| `microsoft.rate_limited` | `5` | `TracesPerSecond = 5.0` |
|
|
79
|
+
| `microsoft.fixed_percentage` | `0.4` | `SamplingRatio = 0.4F`, `TracesPerSecond = null` |
|
|
80
|
+
|
|
81
|
+
**Log sampling** โ when `EnableTraceBasedLogsSampler` is `true` (default), logs correlated to a sampled-out trace are also dropped.
|
|
82
|
+
|
|
83
|
+
## Minimal example
|
|
84
|
+
|
|
85
|
+
```csharp
|
|
86
|
+
using Azure.Monitor.OpenTelemetry.Exporter;
|
|
87
|
+
using OpenTelemetry;
|
|
88
|
+
using OpenTelemetry.Trace;
|
|
89
|
+
|
|
90
|
+
// Connection string from APPLICATIONINSIGHTS_CONNECTION_STRING env var
|
|
91
|
+
using var sdk = OpenTelemetrySdk.Create(builder => builder
|
|
92
|
+
.WithTracing(tracing => tracing
|
|
93
|
+
.AddSource("MyApp")
|
|
94
|
+
.AddAzureMonitorTraceExporter()));
|
|
95
|
+
|
|
96
|
+
// sdk.Dispose() flushes and shuts down on exit.
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Full example
|
|
100
|
+
|
|
101
|
+
```csharp
|
|
102
|
+
using Azure.Identity;
|
|
103
|
+
using Azure.Monitor.OpenTelemetry.Exporter;
|
|
104
|
+
using OpenTelemetry;
|
|
105
|
+
using OpenTelemetry.Trace;
|
|
106
|
+
using OpenTelemetry.Metrics;
|
|
107
|
+
|
|
108
|
+
var credential = new DefaultAzureCredential();
|
|
109
|
+
var connStr = Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING");
|
|
110
|
+
|
|
111
|
+
using var sdk = OpenTelemetrySdk.Create(builder => builder
|
|
112
|
+
.ConfigureResource(r => r.AddService("my-console-app"))
|
|
113
|
+
.WithTracing(tracing => tracing
|
|
114
|
+
.AddSource("MyApp")
|
|
115
|
+
.AddHttpClientInstrumentation()
|
|
116
|
+
.AddAzureMonitorTraceExporter(
|
|
117
|
+
configure: o =>
|
|
118
|
+
{
|
|
119
|
+
o.ConnectionString = connStr;
|
|
120
|
+
o.TracesPerSecond = null;
|
|
121
|
+
o.SamplingRatio = 0.5F;
|
|
122
|
+
},
|
|
123
|
+
credential: credential))
|
|
124
|
+
.WithMetrics(metrics => metrics
|
|
125
|
+
.AddMeter("MyApp")
|
|
126
|
+
.AddAzureMonitorMetricExporter(
|
|
127
|
+
configure: o => o.ConnectionString = connStr,
|
|
128
|
+
credential: credential)));
|
|
129
|
+
// Logging intentionally omitted โ only traces and metrics exported
|
|
130
|
+
|
|
131
|
+
// sdk.Dispose() flushes all signals on exit.
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## See also
|
|
135
|
+
|
|
136
|
+
- UseAzureMonitorExporter (all signals)(see in UseAzureMonitorExporter.md)
|
|
137
|
+
- WithTracing(see in WithTracing.md) ยท WithMetrics(see in WithMetrics.md) ยท WithLogging(see in WithLogging.md)
|