@azure/mcp-linux-arm64 2.0.0-beta.9 → 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 +148 -27
- 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/azmcp +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TelemetryClient
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# TelemetryClient — Breaking Changes in 3.x
|
|
8
|
+
|
|
9
|
+
`TelemetryClient` still works in 3.x but several constructors, properties, and method overloads were **removed or changed**. Code that uses removed overloads will not compile after upgrading.
|
|
10
|
+
|
|
11
|
+
## Removed APIs
|
|
12
|
+
|
|
13
|
+
| API | Status | Migration |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| `new TelemetryClient()` (parameterless) | **Removed** | Use `TelemetryClient(TelemetryConfiguration)` via DI (constructor injection). |
|
|
16
|
+
| `client.InstrumentationKey` | **Removed** | Use `TelemetryConfiguration.ConnectionString`. |
|
|
17
|
+
| `TrackPageView(string)` | **Removed** | Use `TrackEvent(name, properties)` or `TrackRequest`. |
|
|
18
|
+
| `TrackPageView(PageViewTelemetry)` | **Removed** | Use `TrackEvent(name, properties)` or `TrackRequest`. |
|
|
19
|
+
|
|
20
|
+
## Changed method signatures
|
|
21
|
+
|
|
22
|
+
The `IDictionary<string, double> metrics` parameter was **removed** from several Track methods. Code passing a metrics dictionary will not compile.
|
|
23
|
+
|
|
24
|
+
| Method | 2.x signature | 3.x signature | Fix |
|
|
25
|
+
| --- | --- | --- | --- |
|
|
26
|
+
| `TrackEvent` | `(string, IDictionary<string,string>, IDictionary<string,double>)` | `(string, IDictionary<string,string>)` | Remove metrics dict. Track metrics separately via `TrackMetric()`. |
|
|
27
|
+
| `TrackException` | `(Exception, IDictionary<string,string>, IDictionary<string,double>)` | `(Exception, IDictionary<string,string>)` | Remove metrics dict. Track metrics separately via `TrackMetric()`. |
|
|
28
|
+
| `TrackAvailability` | 8-param with trailing `IDictionary<string,double>` | 7-param — metrics removed | Remove metrics dict. Track metrics separately via `TrackMetric()`. |
|
|
29
|
+
|
|
30
|
+
### Example fix — TrackEvent
|
|
31
|
+
|
|
32
|
+
**2.x (breaks in 3.x):**
|
|
33
|
+
```csharp
|
|
34
|
+
_telemetryClient.TrackEvent("OrderCreated",
|
|
35
|
+
new Dictionary<string, string> { ["OrderId"] = orderId },
|
|
36
|
+
new Dictionary<string, double> { ["ProcessingTimeMs"] = elapsed });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**3.x:**
|
|
40
|
+
```csharp
|
|
41
|
+
_telemetryClient.TrackEvent("OrderCreated",
|
|
42
|
+
new Dictionary<string, string> { ["OrderId"] = orderId });
|
|
43
|
+
_telemetryClient.TrackMetric("OrderProcessingTimeMs", elapsed);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Other changed APIs
|
|
47
|
+
|
|
48
|
+
| API | Change | Migration |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `TrackDependency` (obsolete 5-param overload) | **Removed** | Use the full overload with `dependencyTypeName`, `target`, `data`, `startTime`, `duration`, `success`. |
|
|
51
|
+
| `GetMetric` (all overloads) | `MetricConfiguration` and `MetricAggregationScope` parameters **removed** | Call the simplified overload: `GetMetric(metricId)` or `GetMetric(metricId, dim1, ...)`. |
|
|
52
|
+
| `Track(ITelemetry)` | Internal routing changed — now delegates to specific Track methods | Review any direct `Track(ITelemetry)` calls; prefer specific Track methods. |
|
|
53
|
+
| `StartOperation<T>` / `StopOperation<T>` | Now uses OpenTelemetry Activities internally | No code change needed — API is the same. |
|
|
54
|
+
|
|
55
|
+
## Unchanged Track methods — no action needed
|
|
56
|
+
|
|
57
|
+
These methods and their signatures are **identical** in 3.x:
|
|
58
|
+
|
|
59
|
+
- `TrackEvent(string eventName)` — single-param overload
|
|
60
|
+
- `TrackEvent(string eventName, IDictionary<string, string> properties)` — 2-param overload (no metrics)
|
|
61
|
+
- `TrackException(Exception exception)` — single-param overload
|
|
62
|
+
- `TrackException(Exception exception, IDictionary<string, string> properties)` — 2-param overload (no metrics)
|
|
63
|
+
- `TrackTrace(string message)` and `TrackTrace(string, SeverityLevel)` and `TrackTrace(string, SeverityLevel, IDictionary<string,string>)`
|
|
64
|
+
- `TrackMetric(string name, double value)` and other `TrackMetric` overloads
|
|
65
|
+
- `TrackRequest(...)` — all overloads
|
|
66
|
+
- `TrackDependency(...)` — full overload (not the obsolete 5-param)
|
|
67
|
+
- `TrackAvailability(...)` — 7-param overload (without metrics dict)
|
|
68
|
+
- `Flush()` and `FlushAsync(CancellationToken)`
|
|
69
|
+
|
|
70
|
+
## TelemetryContext changes
|
|
71
|
+
|
|
72
|
+
Several sub-context classes are now **internal** in 3.x:
|
|
73
|
+
|
|
74
|
+
| Sub-context | Status | Previously accessible properties |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `Context.Cloud` | **Internal** | `RoleName`, `RoleInstance` — use `ConfigureResource(r => r.AddService("name"))` instead |
|
|
77
|
+
| `Context.Component` | **Internal** | `Version` — use `ApplicationVersion` in service options |
|
|
78
|
+
| `Context.Device` | **Internal** | `Type`, `Id`, `OperatingSystem`, etc. |
|
|
79
|
+
| `Context.Session` | **Internal** | `Id`, `IsFirst` |
|
|
80
|
+
|
|
81
|
+
These remain **public**: `Context.User` (`Id`, `AuthenticatedUserId`, `UserAgent`), `Context.Operation` (`Name`), `Context.Location` (`Ip`), `Context.GlobalProperties`.
|
|
82
|
+
|
|
83
|
+
Properties made internal on remaining public sub-contexts:
|
|
84
|
+
- `User.AccountId` — internal; set via properties dict on Track calls or custom processor
|
|
85
|
+
- `Operation.Id`, `Operation.ParentId` — internal; managed by OpenTelemetry correlation
|
|
86
|
+
- `Operation.CorrelationVector` — removed; no longer needed
|
|
87
|
+
|
|
88
|
+
## Extensibility — ConfigureOpenTelemetryBuilder
|
|
89
|
+
|
|
90
|
+
To register custom OpenTelemetry processors or instrumentations alongside TelemetryClient in 3.x:
|
|
91
|
+
|
|
92
|
+
```csharp
|
|
93
|
+
var config = TelemetryConfiguration.CreateDefault();
|
|
94
|
+
config.ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...";
|
|
95
|
+
config.ConfigureOpenTelemetryBuilder(otel =>
|
|
96
|
+
{
|
|
97
|
+
otel.WithTracing(t => t.AddProcessor<MyActivityProcessor>());
|
|
98
|
+
otel.WithLogging(l => l.AddProcessor<MyLogProcessor>());
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
When using ASP.NET Core DI, use the service options + `ConfigureOpenTelemetryProvider` pattern instead — see ConfigureOpenTelemetryProvider.md.
|
|
103
|
+
|
|
104
|
+
## Quick decision guide
|
|
105
|
+
|
|
106
|
+
| Code pattern found | Action required? |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| `TrackEvent(name, props, metrics)` — 3 args | **Yes** — remove metrics dict, use `TrackMetric()` separately |
|
|
109
|
+
| `TrackException(ex, props, metrics)` — 3 args | **Yes** — remove metrics dict, use `TrackMetric()` separately |
|
|
110
|
+
| `TrackAvailability(..., metrics)` — 8 args | **Yes** — remove metrics dict, use `TrackMetric()` separately |
|
|
111
|
+
| `TrackPageView(...)` | **Yes** — replace with `TrackEvent()` or `TrackRequest()` |
|
|
112
|
+
| `GetMetric(..., MetricConfiguration, ...)` | **Yes** — remove config/scope params |
|
|
113
|
+
| `new TelemetryClient()` (no args) | **Yes** — use DI or `TelemetryClient(TelemetryConfiguration)` |
|
|
114
|
+
| `client.InstrumentationKey = ...` | **Yes** — use `TelemetryConfiguration.ConnectionString` |
|
|
115
|
+
| `Context.Cloud.RoleName = ...` | **Yes** — use `ConfigureResource` |
|
|
116
|
+
| `TrackEvent(name)` or `TrackEvent(name, props)` | No |
|
|
117
|
+
| `TrackTrace(...)` | No |
|
|
118
|
+
| `TrackMetric(...)` | No |
|
|
119
|
+
| `TrackRequest(...)` | No |
|
|
120
|
+
| `TrackDependency(...)` (full overload) | No |
|
|
121
|
+
| `TrackException(ex)` or `TrackException(ex, props)` | No |
|
|
122
|
+
| `Flush()` | No |
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TelemetryConfigurationBuilder
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# TelemetryConfiguration.ConfigureOpenTelemetryBuilder
|
|
8
|
+
|
|
9
|
+
The non-DI extensibility API for Application Insights 3.x. Use this when you don't have an `IServiceCollection` — classic ASP.NET (`Global.asax`), console apps, or test scenarios.
|
|
10
|
+
|
|
11
|
+
For DI-based apps (ASP.NET Core, Worker Service), use ConfigureOpenTelemetryTracerProvider(see in ConfigureOpenTelemetryProvider.md) instead.
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
```csharp
|
|
16
|
+
TelemetryConfiguration.ConfigureOpenTelemetryBuilder(
|
|
17
|
+
Action<IOpenTelemetryBuilder> configure)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Setup pattern
|
|
21
|
+
|
|
22
|
+
```csharp
|
|
23
|
+
using Microsoft.ApplicationInsights.Extensibility;
|
|
24
|
+
using OpenTelemetry;
|
|
25
|
+
using OpenTelemetry.Trace;
|
|
26
|
+
using OpenTelemetry.Logs;
|
|
27
|
+
using OpenTelemetry.Resources;
|
|
28
|
+
|
|
29
|
+
var config = TelemetryConfiguration.CreateDefault();
|
|
30
|
+
config.ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...";
|
|
31
|
+
|
|
32
|
+
config.ConfigureOpenTelemetryBuilder(otel =>
|
|
33
|
+
{
|
|
34
|
+
// Add custom trace processors
|
|
35
|
+
otel.WithTracing(tracing =>
|
|
36
|
+
{
|
|
37
|
+
tracing.AddProcessor<MyEnrichmentProcessor>();
|
|
38
|
+
tracing.AddProcessor<MyFilterProcessor>();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Add custom log processors
|
|
42
|
+
otel.WithLogging(logging =>
|
|
43
|
+
{
|
|
44
|
+
logging.AddProcessor<MyLogProcessor>();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Set resource attributes (Cloud.RoleName, etc.)
|
|
48
|
+
otel.ConfigureResource(r => r.AddService(
|
|
49
|
+
serviceName: "MyWebApp",
|
|
50
|
+
serviceInstanceId: Environment.MachineName,
|
|
51
|
+
serviceVersion: "1.0.0"));
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Add instrumentations
|
|
56
|
+
|
|
57
|
+
```csharp
|
|
58
|
+
using OpenTelemetry;
|
|
59
|
+
using OpenTelemetry.Trace;
|
|
60
|
+
|
|
61
|
+
config.ConfigureOpenTelemetryBuilder(otel =>
|
|
62
|
+
{
|
|
63
|
+
otel.WithTracing(tracing =>
|
|
64
|
+
{
|
|
65
|
+
tracing.AddRedisInstrumentation();
|
|
66
|
+
tracing.AddSqlClientInstrumentation(options =>
|
|
67
|
+
{
|
|
68
|
+
options.SetDbStatementForText = true;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Add exporters (dual export)
|
|
75
|
+
|
|
76
|
+
```csharp
|
|
77
|
+
using OpenTelemetry;
|
|
78
|
+
using OpenTelemetry.Trace;
|
|
79
|
+
using OpenTelemetry.Metrics;
|
|
80
|
+
using OpenTelemetry.Logs;
|
|
81
|
+
|
|
82
|
+
config.ConfigureOpenTelemetryBuilder(otel =>
|
|
83
|
+
{
|
|
84
|
+
// Console exporter for debugging
|
|
85
|
+
otel.WithTracing(tracing => tracing.AddConsoleExporter());
|
|
86
|
+
otel.WithLogging(logging => logging.AddConsoleExporter());
|
|
87
|
+
|
|
88
|
+
// OTLP exporter for secondary destination
|
|
89
|
+
otel.WithTracing(tracing => tracing.AddOtlpExporter());
|
|
90
|
+
otel.WithMetrics(metrics => metrics.AddOtlpExporter());
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## TelemetryClient usage
|
|
95
|
+
|
|
96
|
+
In classic ASP.NET, create a **single static** `TelemetryClient` instance. `TelemetryConfiguration.CreateDefault()` returns a singleton shared with `ApplicationInsightsHttpModule` — do not create per-request instances.
|
|
97
|
+
|
|
98
|
+
```csharp
|
|
99
|
+
using Microsoft.ApplicationInsights;
|
|
100
|
+
using Microsoft.ApplicationInsights.Extensibility;
|
|
101
|
+
using OpenTelemetry;
|
|
102
|
+
using OpenTelemetry.Trace;
|
|
103
|
+
using OpenTelemetry.Logs;
|
|
104
|
+
using OpenTelemetry.Resources;
|
|
105
|
+
|
|
106
|
+
public class MvcApplication : HttpApplication
|
|
107
|
+
{
|
|
108
|
+
public static TelemetryClient TelemetryClient { get; private set; }
|
|
109
|
+
|
|
110
|
+
protected void Application_Start()
|
|
111
|
+
{
|
|
112
|
+
var config = TelemetryConfiguration.CreateDefault();
|
|
113
|
+
config.ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...";
|
|
114
|
+
config.ConfigureOpenTelemetryBuilder(otel =>
|
|
115
|
+
{
|
|
116
|
+
otel.WithTracing(tracing => tracing.AddProcessor<MyProcessor>());
|
|
117
|
+
otel.ConfigureResource(r => r.AddService("MyWebApp"));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
TelemetryClient = new TelemetryClient(config);
|
|
121
|
+
|
|
122
|
+
AreaRegistration.RegisterAllAreas();
|
|
123
|
+
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
protected void Application_End()
|
|
127
|
+
{
|
|
128
|
+
TelemetryClient?.Flush();
|
|
129
|
+
System.Threading.Tasks.Task.Delay(1000).Wait();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Then in controllers:
|
|
135
|
+
|
|
136
|
+
```csharp
|
|
137
|
+
public class HomeController : Controller
|
|
138
|
+
{
|
|
139
|
+
public ActionResult Index()
|
|
140
|
+
{
|
|
141
|
+
MvcApplication.TelemetryClient.TrackEvent("HomeVisited");
|
|
142
|
+
return View();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Relationship to ConfigureOpenTelemetryTracerProvider
|
|
148
|
+
|
|
149
|
+
| Scenario | API to use |
|
|
150
|
+
|---|---|
|
|
151
|
+
| ASP.NET Core / Worker Service (DI) | `services.ConfigureOpenTelemetryTracerProvider(...)` |
|
|
152
|
+
| Classic ASP.NET (Global.asax) | `config.ConfigureOpenTelemetryBuilder(...)` |
|
|
153
|
+
| Console apps without DI | `config.ConfigureOpenTelemetryBuilder(...)` |
|
|
154
|
+
| Tests | `config.ConfigureOpenTelemetryBuilder(...)` |
|
|
155
|
+
|
|
156
|
+
Both APIs provide access to the same OTel builders (`TracerProviderBuilder`, `MeterProviderBuilder`, `LoggerProviderBuilder`). The difference is the entry point — `IServiceCollection` extension vs `TelemetryConfiguration` method.
|
|
157
|
+
|
|
158
|
+
## Key differences from 2.x
|
|
159
|
+
|
|
160
|
+
| 2.x Pattern | 3.x via `ConfigureOpenTelemetryBuilder` |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `config.TelemetryInitializers.Add(new MyInit())` | `otel.WithTracing(t => t.AddProcessor<MyProcessor>())` in `OnStart` |
|
|
163
|
+
| `config.TelemetryProcessorChainBuilder.Use(...)` | `otel.WithTracing(t => t.AddProcessor<MyProcessor>())` in `OnEnd` |
|
|
164
|
+
| `config.TelemetryChannel = new InMemoryChannel()` | Not needed — export managed by OTel |
|
|
165
|
+
| `config.TelemetrySinks.Add(...)` | `otel.WithTracing(t => t.AddOtlpExporter())` |
|
|
166
|
+
|
|
167
|
+
## Notes
|
|
168
|
+
|
|
169
|
+
- **`using OpenTelemetry;` is required** — the `WithTracing()`, `WithLogging()`, `WithMetrics()`, and `ConfigureResource()` extension methods on `IOpenTelemetryBuilder` are defined in the root `OpenTelemetry` namespace. Without this using directive, these methods will not resolve. This is separate from `using OpenTelemetry.Trace;` / `using OpenTelemetry.Logs;` which are also needed.
|
|
170
|
+
- `CreateDefault()` returns a **static singleton** in 3.x (not a new instance). Call `ConfigureOpenTelemetryBuilder` only once, in `Application_Start`.
|
|
171
|
+
- Connection string is **required** — 3.x throws if not set. For tests, use a dummy: `InstrumentationKey=00000000-0000-0000-0000-000000000000`.
|
|
172
|
+
- Call `TelemetryClient.Flush()` in `Application_End` followed by a short delay to avoid data loss on shutdown.
|
|
173
|
+
- `GlobalProperties` on `TelemetryClient.Context` works for custom properties. Other `Context` properties (User.Id, Operation.Name) have known propagation limitations in 3.x.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: UseAzureMonitor
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
source: Azure.Monitor.OpenTelemetry.AspNetCore/OpenTelemetryBuilderExtensions.cs
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# UseAzureMonitor
|
|
9
|
+
|
|
10
|
+
**Namespace:** `Azure.Monitor.OpenTelemetry.AspNetCore`
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
Extension method on `IOpenTelemetryBuilder` that configures OpenTelemetry with Azure Monitor exporters and automatic instrumentation.
|
|
15
|
+
|
|
16
|
+
## Signature
|
|
17
|
+
|
|
18
|
+
```csharp
|
|
19
|
+
public static IOpenTelemetryBuilder UseAzureMonitor(
|
|
20
|
+
this IOpenTelemetryBuilder builder);
|
|
21
|
+
|
|
22
|
+
public static IOpenTelemetryBuilder UseAzureMonitor(
|
|
23
|
+
this IOpenTelemetryBuilder builder,
|
|
24
|
+
Action<AzureMonitorOptions> configureAzureMonitor);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic (environment variable connection string)
|
|
30
|
+
|
|
31
|
+
```csharp
|
|
32
|
+
using Azure.Monitor.OpenTelemetry.AspNetCore;
|
|
33
|
+
|
|
34
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
35
|
+
builder.Services.AddOpenTelemetry().UseAzureMonitor();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### With options
|
|
39
|
+
|
|
40
|
+
```csharp
|
|
41
|
+
using Azure.Monitor.OpenTelemetry.AspNetCore;
|
|
42
|
+
|
|
43
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
44
|
+
builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
|
|
45
|
+
{
|
|
46
|
+
options.ConnectionString = "InstrumentationKey=...";
|
|
47
|
+
options.SamplingRatio = 0.5f;
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## AzureMonitorOptions Properties
|
|
52
|
+
|
|
53
|
+
| Property | Type | Description |
|
|
54
|
+
|----------|------|-------------|
|
|
55
|
+
| `ConnectionString` | `string?` | Azure Monitor connection string. If not set, reads from `APPLICATIONINSIGHTS_CONNECTION_STRING` env var |
|
|
56
|
+
| `SamplingRatio` | `float` | Sampling ratio (0.0 to 1.0). Default: 1.0 (100%) |
|
|
57
|
+
| `EnableLiveMetrics` | `bool` | Enable Live Metrics stream. Default: true |
|
|
58
|
+
| `Credential` | `TokenCredential?` | Azure credential for AAD authentication |
|
|
59
|
+
| `Resource` | `Resource?` | Custom OpenTelemetry resource |
|
|
60
|
+
|
|
61
|
+
## What It Configures
|
|
62
|
+
|
|
63
|
+
Calling `UseAzureMonitor()` automatically adds:
|
|
64
|
+
|
|
65
|
+
**Tracing:**
|
|
66
|
+
- ASP.NET Core instrumentation
|
|
67
|
+
- HttpClient instrumentation
|
|
68
|
+
- SQL Client instrumentation
|
|
69
|
+
- Azure SDK instrumentation
|
|
70
|
+
- Azure Monitor trace exporter
|
|
71
|
+
|
|
72
|
+
**Metrics:**
|
|
73
|
+
- ASP.NET Core instrumentation
|
|
74
|
+
- HttpClient instrumentation
|
|
75
|
+
- Runtime instrumentation
|
|
76
|
+
- Azure Monitor metric exporter
|
|
77
|
+
|
|
78
|
+
**Logging:**
|
|
79
|
+
- Azure Monitor log exporter
|
|
80
|
+
|
|
81
|
+
## Chaining with Additional Configuration
|
|
82
|
+
|
|
83
|
+
```csharp
|
|
84
|
+
builder.Services.AddOpenTelemetry()
|
|
85
|
+
.UseAzureMonitor()
|
|
86
|
+
.WithTracing(tracing => tracing
|
|
87
|
+
.AddSource("MyCustomSource")
|
|
88
|
+
.AddProcessor<MyCustomProcessor>())
|
|
89
|
+
.WithMetrics(metrics => metrics
|
|
90
|
+
.AddMeter("MyCustomMeter"));
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## See Also
|
|
94
|
+
|
|
95
|
+
- AddOpenTelemetry(see in AddOpenTelemetry.md)
|
|
96
|
+
- Azure Monitor Distro concept(see in azure-monitor-distro.md)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: UseAzureMonitorExporter
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
source: src/OpenTelemetryBuilderExtensions.cs
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# UseAzureMonitorExporter
|
|
9
|
+
|
|
10
|
+
**Namespace:** `Azure.Monitor.OpenTelemetry.Exporter`
|
|
11
|
+
|
|
12
|
+
## When to use
|
|
13
|
+
|
|
14
|
+
- You want Azure Monitor export **without** the automatic instrumentation that `UseAzureMonitor` (distro) adds.
|
|
15
|
+
- You want a single call that registers exporters for **all three signals** (traces, metrics, logs).
|
|
16
|
+
- You want **Live Metrics** support (per-signal methods do not support it).
|
|
17
|
+
- You are adding Azure Monitor to a pipeline that already calls `AddOpenTelemetry()` with custom providers.
|
|
18
|
+
|
|
19
|
+
## Signatures
|
|
20
|
+
|
|
21
|
+
```csharp
|
|
22
|
+
public static IOpenTelemetryBuilder UseAzureMonitorExporter(
|
|
23
|
+
this IOpenTelemetryBuilder builder);
|
|
24
|
+
|
|
25
|
+
public static IOpenTelemetryBuilder UseAzureMonitorExporter(
|
|
26
|
+
this IOpenTelemetryBuilder builder,
|
|
27
|
+
Action<AzureMonitorExporterOptions> configureAzureMonitor);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Automatically calls `WithTracing()`, `WithMetrics()`, and `WithLogging()`.
|
|
31
|
+
Sets the sampler, configures `IncludeFormattedMessage = true` on the logger,
|
|
32
|
+
and enables Live Metrics.
|
|
33
|
+
|
|
34
|
+
## Behavior notes
|
|
35
|
+
|
|
36
|
+
- **Cannot** be combined with per-signal methods (`AddAzureMonitorTraceExporter`, etc.) in the same app — a runtime exception is thrown.
|
|
37
|
+
- Chaining additional `WithTracing()` / `WithMetrics()` / `WithLogging()` calls adds configuration to the existing provider — it does not create a second one.
|
|
38
|
+
- See AzureMonitorExporter(see in AzureMonitorExporter.md) for the per-signal approach.
|
|
39
|
+
|
|
40
|
+
## AzureMonitorExporterOptions
|
|
41
|
+
|
|
42
|
+
Inherits `Azure.Core.ClientOptions`.
|
|
43
|
+
|
|
44
|
+
| Property | Type | Default | Description |
|
|
45
|
+
|---|---|---|---|
|
|
46
|
+
| `ConnectionString` | `string` | `null` | Application Insights connection string. Falls back to `APPLICATIONINSIGHTS_CONNECTION_STRING` env var. |
|
|
47
|
+
| `Credential` | `TokenCredential` | `null` | Azure AD token credential for Entra-based auth. |
|
|
48
|
+
| `SamplingRatio` | `float` | `1.0F` | Fixed-percentage sampling ratio (0.0–1.0). Only used when `TracesPerSecond` is `null`. |
|
|
49
|
+
| `TracesPerSecond` | `double?` | `5.0` | Rate-limited sampling target. Takes precedence over `SamplingRatio`. Set to `null` to use fixed-percentage sampling. |
|
|
50
|
+
| `StorageDirectory` | `string` | `null` | Custom directory for offline/retry storage. Uses OS temp by default. |
|
|
51
|
+
| `DisableOfflineStorage` | `bool` | `false` | Disables persistent storage for failed telemetry. |
|
|
52
|
+
| `EnableLiveMetrics` | `bool` | `true` | Enables Live Metrics stream. |
|
|
53
|
+
| `EnableTraceBasedLogsSampler` | `bool` | `true` | When `true`, only logs correlated to sampled traces are exported. Logs without trace context are always exported. |
|
|
54
|
+
|
|
55
|
+
## Sampling
|
|
56
|
+
|
|
57
|
+
The exporter automatically configures a trace sampler — you do not need to set one yourself.
|
|
58
|
+
|
|
59
|
+
**Two modes**, controlled by `TracesPerSecond` and `SamplingRatio`:
|
|
60
|
+
|
|
61
|
+
| Mode | Activated when | Sampler | Example |
|
|
62
|
+
|---|---|---|---|
|
|
63
|
+
| Rate-limited (default) | `TracesPerSecond` is non-null | `RateLimitedSampler` — caps throughput to N traces/sec | `TracesPerSecond = 5.0` → ~5 traces/sec |
|
|
64
|
+
| Fixed-percentage | `TracesPerSecond` is `null` | `ApplicationInsightsSampler` — samples a fixed ratio | `SamplingRatio = 0.4F` → 40% of traces |
|
|
65
|
+
|
|
66
|
+
Because `TracesPerSecond` defaults to `5.0`, rate-limited sampling is active out of the box. To switch to fixed-percentage sampling:
|
|
67
|
+
|
|
68
|
+
```csharp
|
|
69
|
+
builder.Services.AddOpenTelemetry()
|
|
70
|
+
.UseAzureMonitorExporter(o =>
|
|
71
|
+
{
|
|
72
|
+
o.TracesPerSecond = null; // disable rate-limited sampling
|
|
73
|
+
o.SamplingRatio = 0.25F; // keep 25% of traces
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Environment variable overrides** — `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`:
|
|
78
|
+
|
|
79
|
+
| `OTEL_TRACES_SAMPLER` | `OTEL_TRACES_SAMPLER_ARG` | Effect |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `microsoft.rate_limited` | `5` | `TracesPerSecond = 5.0` |
|
|
82
|
+
| `microsoft.fixed_percentage` | `0.4` | `SamplingRatio = 0.4F`, `TracesPerSecond = null` |
|
|
83
|
+
|
|
84
|
+
Environment variables override `IConfiguration` values, which override code defaults.
|
|
85
|
+
|
|
86
|
+
**Log sampling** — when `EnableTraceBasedLogsSampler` is `true` (default), logs correlated to a sampled-out trace are also dropped. Logs without trace context are always exported.
|
|
87
|
+
|
|
88
|
+
## Minimal example
|
|
89
|
+
|
|
90
|
+
```csharp
|
|
91
|
+
using Azure.Monitor.OpenTelemetry.Exporter;
|
|
92
|
+
|
|
93
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
94
|
+
|
|
95
|
+
// Connection string from APPLICATIONINSIGHTS_CONNECTION_STRING env var
|
|
96
|
+
builder.Services.AddOpenTelemetry().UseAzureMonitorExporter();
|
|
97
|
+
|
|
98
|
+
var app = builder.Build();
|
|
99
|
+
app.Run();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Full example
|
|
103
|
+
|
|
104
|
+
```csharp
|
|
105
|
+
using Azure.Identity;
|
|
106
|
+
using Azure.Monitor.OpenTelemetry.Exporter;
|
|
107
|
+
using OpenTelemetry.Trace;
|
|
108
|
+
|
|
109
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
110
|
+
|
|
111
|
+
builder.Services.AddOpenTelemetry()
|
|
112
|
+
.UseAzureMonitorExporter(o =>
|
|
113
|
+
{
|
|
114
|
+
o.ConnectionString = builder.Configuration["AzureMonitor:ConnectionString"];
|
|
115
|
+
o.Credential = new DefaultAzureCredential();
|
|
116
|
+
o.TracesPerSecond = null; // switch to fixed-percentage sampling
|
|
117
|
+
o.SamplingRatio = 0.5F; // keep 50% of traces
|
|
118
|
+
o.EnableTraceBasedLogsSampler = false; // export all logs
|
|
119
|
+
})
|
|
120
|
+
.WithTracing(tracing => tracing
|
|
121
|
+
.AddAspNetCoreInstrumentation()
|
|
122
|
+
.AddHttpClientInstrumentation()
|
|
123
|
+
.AddSource("MyApp"));
|
|
124
|
+
|
|
125
|
+
var app = builder.Build();
|
|
126
|
+
app.Run();
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Non-hosted (console / CLI)
|
|
130
|
+
|
|
131
|
+
```csharp
|
|
132
|
+
using Azure.Monitor.OpenTelemetry.Exporter;
|
|
133
|
+
using OpenTelemetry;
|
|
134
|
+
|
|
135
|
+
using var sdk = OpenTelemetrySdk.Create(builder => builder
|
|
136
|
+
.UseAzureMonitorExporter()
|
|
137
|
+
.WithTracing(tracing => tracing.AddSource("MyApp")));
|
|
138
|
+
|
|
139
|
+
// sdk.Dispose() flushes all signals on exit.
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## See also
|
|
143
|
+
|
|
144
|
+
- UseAzureMonitor (distro)(see in UseAzureMonitor.md)
|
|
145
|
+
- Per-signal exporters (AzureMonitorExporter)(see in AzureMonitorExporter.md)
|
|
146
|
+
- AddOpenTelemetry(see in AddOpenTelemetry.md)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WithLogging
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 1.x
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# .WithLogging()
|
|
8
|
+
|
|
9
|
+
## API surface
|
|
10
|
+
|
|
11
|
+
| Method | Purpose |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `.WithLogging()` | Enable logging with defaults |
|
|
14
|
+
| `.WithLogging(Action<LoggerProviderBuilder>)` | Enable logging and configure the provider builder |
|
|
15
|
+
| `.WithLogging(Action<LoggerProviderBuilder>?, Action<OpenTelemetryLoggerOptions>?)` | Configure both provider and logger options |
|
|
16
|
+
| `ILoggingBuilder.AddOpenTelemetry()` | Register OpenTelemetry logger without the host builder |
|
|
17
|
+
| `ILoggingBuilder.AddOpenTelemetry(Action<OpenTelemetryLoggerOptions>?)` | Register with options configuration |
|
|
18
|
+
| `builder.AddProcessor(BaseProcessor<LogRecord>)` | Add a log processor instance |
|
|
19
|
+
| `builder.AddProcessor<T>()` | Add a processor resolved from DI (singleton) |
|
|
20
|
+
| `builder.AddProcessor(Func<IServiceProvider, BaseProcessor<LogRecord>>)` | Add a processor via factory |
|
|
21
|
+
|
|
22
|
+
See also: ConfigureResource.md for resource configuration
|
|
23
|
+
|
|
24
|
+
## When to use
|
|
25
|
+
|
|
26
|
+
- Route `ILogger` log records through the OpenTelemetry pipeline in an ASP.NET Core or Worker Service app.
|
|
27
|
+
- Configure `OpenTelemetryLoggerOptions` (formatted messages, scopes, state parsing) alongside the provider.
|
|
28
|
+
- Use `AddOpenTelemetry()` on `ILoggingBuilder` when you need logging without the full `AddOpenTelemetry()` builder (e.g., non-host `ServiceCollection`).
|
|
29
|
+
- Call multiple times safely — only one `LoggerProvider` is created per `IServiceCollection`.
|
|
30
|
+
|
|
31
|
+
## Minimal example
|
|
32
|
+
|
|
33
|
+
```csharp
|
|
34
|
+
using OpenTelemetry;
|
|
35
|
+
using OpenTelemetry.Logs;
|
|
36
|
+
|
|
37
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
38
|
+
|
|
39
|
+
builder.Services.AddOpenTelemetry()
|
|
40
|
+
.WithLogging(logging => logging
|
|
41
|
+
.AddOtlpExporter());
|
|
42
|
+
|
|
43
|
+
var app = builder.Build();
|
|
44
|
+
app.Run();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Full example
|
|
48
|
+
|
|
49
|
+
```csharp
|
|
50
|
+
using OpenTelemetry;
|
|
51
|
+
using OpenTelemetry.Logs;
|
|
52
|
+
using OpenTelemetry.Resources;
|
|
53
|
+
|
|
54
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
55
|
+
|
|
56
|
+
builder.Services.AddOpenTelemetry()
|
|
57
|
+
.ConfigureResource(r => r.AddService("order-api"))
|
|
58
|
+
.WithLogging(
|
|
59
|
+
configureBuilder: logging => logging
|
|
60
|
+
.AddProcessor<MyLogEnrichmentProcessor>()
|
|
61
|
+
.AddOtlpExporter(),
|
|
62
|
+
configureOptions: options =>
|
|
63
|
+
{
|
|
64
|
+
options.IncludeFormattedMessage = true;
|
|
65
|
+
options.IncludeScopes = true;
|
|
66
|
+
options.ParseStateValues = true;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
var app = builder.Build();
|
|
70
|
+
app.Run();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Alternative: ILoggingBuilder.AddOpenTelemetry()
|
|
74
|
+
|
|
75
|
+
Use this when you don't have an `IOpenTelemetryBuilder` — for example, a bare `ServiceCollection`:
|
|
76
|
+
|
|
77
|
+
```csharp
|
|
78
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
79
|
+
using Microsoft.Extensions.Logging;
|
|
80
|
+
using OpenTelemetry.Logs;
|
|
81
|
+
|
|
82
|
+
var services = new ServiceCollection();
|
|
83
|
+
|
|
84
|
+
services.AddLogging(logging => logging
|
|
85
|
+
.AddOpenTelemetry(options =>
|
|
86
|
+
{
|
|
87
|
+
options.IncludeFormattedMessage = true;
|
|
88
|
+
}));
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Key parameters
|
|
92
|
+
|
|
93
|
+
`OpenTelemetryLoggerOptions` properties:
|
|
94
|
+
|
|
95
|
+
| Parameter | Type | Default | Description |
|
|
96
|
+
| --- | --- | --- | --- |
|
|
97
|
+
| `IncludeFormattedMessage` | `bool` | `false` | Include the formatted log message on `LogRecord` |
|
|
98
|
+
| `IncludeScopes` | `bool` | `false` | Include log scopes on `LogRecord` |
|
|
99
|
+
| `ParseStateValues` | `bool` | `false` | Parse state into `LogRecord.Attributes` (sets `State` to `null`) |
|
|
100
|
+
|
|
101
|
+
## Behavior notes
|
|
102
|
+
|
|
103
|
+
- `WithLogging()` automatically registers an `ILoggerProvider` named `"OpenTelemetry"`.
|
|
104
|
+
- `AddOpenTelemetry()` on `ILoggingBuilder` does **not** support all `IServiceCollection` features available to tracing/metrics (e.g., `ConfigureServices` extensions).
|
|
105
|
+
- When `IncludeFormattedMessage` is `false`, the formatted message is still included if no message template is found.
|
|
106
|
+
- When `ParseStateValues` is `true`, `LogRecord.State` is always `null` — use `LogRecord.Attributes` instead.
|
|
107
|
+
- State parsing happens automatically (regardless of `ParseStateValues`) if the logged state implements `IReadOnlyList<KeyValuePair<string, object>>`.
|
|
108
|
+
- Processors run in registration order. Export processors should be added last.
|
|
109
|
+
- `OpenTelemetryLoggerOptions` reloading is disabled internally to prevent unwanted re-creation of processors/exporters during `IConfiguration` reloads.
|