@azure/mcp-linux-arm64 2.0.0-beta.30 → 2.0.0-beta.32
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/dist/Instrumentation/Resources/api-reference/dotnet/AddApplicationInsightsTelemetryWorkerService.md +115 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/ApplicationInsightsWeb.md +103 -0
- package/dist/Instrumentation/Resources/api-reference/dotnet/ConfigureOpenTelemetryProvider.md +23 -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 +2 -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/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/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 +1 -1
- package/dist/Instrumentation/Resources/concepts/dotnet/opentelemetry-pipeline.md +1 -1
- 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 +34 -30
- 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 +30 -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 +3 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: SqlClientInstrumentation
|
|
3
|
+
category: api-reference
|
|
4
|
+
applies-to: 1.x
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# SQL Client Instrumentation
|
|
8
|
+
|
|
9
|
+
## Package
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
OpenTelemetry.Instrumentation.SqlClient
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
```csharp
|
|
18
|
+
using OpenTelemetry.Trace;
|
|
19
|
+
|
|
20
|
+
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing =>
|
|
21
|
+
tracing.AddSqlClientInstrumentation(options =>
|
|
22
|
+
{
|
|
23
|
+
options.SetDbStatementForText = true; // Include SQL text
|
|
24
|
+
options.RecordException = true; // Record exception details on spans
|
|
25
|
+
}));
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Options
|
|
29
|
+
|
|
30
|
+
| Option | Default | Description |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| `SetDbStatementForText` | `false` | Include SQL command text in `db.statement`. May contain PII. |
|
|
33
|
+
| `SetDbStatementForStoredProcedure` | `true` | Include stored procedure name in `db.statement`. |
|
|
34
|
+
| `RecordException` | `false` | Record exception details as span events when SQL commands fail. |
|
|
35
|
+
| `EnableConnectionLevelAttributes` | `false` | Add `server.address` and `server.port` from the connection string. |
|
|
36
|
+
| `Enrich` | `null` | `Action<Activity, string, object>` to enrich with custom tags. Event names: `OnCustom`. |
|
|
37
|
+
| `Filter` | `null` | `Func<object, bool>` — return `false` to suppress a span. |
|
|
38
|
+
|
|
39
|
+
## Semantic conventions
|
|
40
|
+
|
|
41
|
+
| Attribute | Example |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `db.system` | `microsoft.sql_server` |
|
|
44
|
+
| `db.name` | `MyDatabase` |
|
|
45
|
+
| `db.statement` | `SELECT * FROM Users WHERE Id = @Id` |
|
|
46
|
+
| `server.address` | `myserver.database.windows.net` |
|
|
47
|
+
|
|
48
|
+
## Notes
|
|
49
|
+
|
|
50
|
+
- Works with both `System.Data.SqlClient` and `Microsoft.Data.SqlClient`.
|
|
51
|
+
- If using EF Core with SQL Server, you may not need this package separately — EF Core instrumentation captures the same spans. Use this when you have raw `SqlCommand` / `SqlConnection` calls alongside or instead of EF Core.
|
|
52
|
+
- `SetDbStatementForText = true` captures raw SQL which may contain sensitive data. Use with caution in production.
|
|
53
|
+
- **Non-DI usage:** Use `config.ConfigureOpenTelemetryBuilder(otel => otel.WithTracing(t => t.AddSqlClientInstrumentation()))` on `TelemetryConfiguration`. See TelemetryClient.md.
|
|
@@ -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,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Application Insights for ASP.NET Core
|
|
3
|
+
category: concept
|
|
4
|
+
applies-to: 3.x
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Application Insights for ASP.NET Core
|
|
8
|
+
|
|
9
|
+
**Category:** Concept
|
|
10
|
+
**Applies to:** 3.x
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
The `Microsoft.ApplicationInsights.AspNetCore` package provides built-in telemetry collection for ASP.NET Core applications, sending data to Azure Application Insights.
|
|
15
|
+
|
|
16
|
+
## What It Provides
|
|
17
|
+
|
|
18
|
+
One line of code enables full observability:
|
|
19
|
+
|
|
20
|
+
```csharp
|
|
21
|
+
builder.Services.AddApplicationInsightsTelemetry();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Automatic Collection
|
|
25
|
+
- **Requests** — All incoming HTTP requests with timing, status codes, and URLs
|
|
26
|
+
- **Dependencies** — Outgoing HTTP calls, SQL queries, and Azure SDK calls
|
|
27
|
+
- **Exceptions** — Unhandled exceptions with full stack traces
|
|
28
|
+
- **Performance Counters** — CPU, memory, GC, and thread pool metrics
|
|
29
|
+
- **Logs** — ILogger output (Information level and above by default)
|
|
30
|
+
|
|
31
|
+
### Built-in Features
|
|
32
|
+
- **Live Metrics** — Real-time monitoring via QuickPulse
|
|
33
|
+
- **Adaptive Sampling** — Automatic volume control (configurable via `TracesPerSecond`)
|
|
34
|
+
- **JavaScript Snippet** — Browser-side telemetry injection for Razor pages
|
|
35
|
+
- **AAD Authentication** — Token-based auth via `TokenCredential`
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### 1. Install Package
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
dotnet add package Microsoft.ApplicationInsights.AspNetCore
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Add to Program.cs
|
|
46
|
+
|
|
47
|
+
```csharp
|
|
48
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
49
|
+
builder.Services.AddApplicationInsightsTelemetry();
|
|
50
|
+
var app = builder.Build();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 3. Configure Connection String
|
|
54
|
+
|
|
55
|
+
**Environment variable (recommended):**
|
|
56
|
+
```bash
|
|
57
|
+
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://...
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Or in appsettings.json:**
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"ApplicationInsights": {
|
|
64
|
+
"ConnectionString": "InstrumentationKey=xxx;IngestionEndpoint=https://..."
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Configuration Options
|
|
70
|
+
|
|
71
|
+
Use `ApplicationInsightsServiceOptions` to customize behavior:
|
|
72
|
+
|
|
73
|
+
```csharp
|
|
74
|
+
builder.Services.AddApplicationInsightsTelemetry(options =>
|
|
75
|
+
{
|
|
76
|
+
options.ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...";
|
|
77
|
+
options.EnableQuickPulseMetricStream = true;
|
|
78
|
+
options.SamplingRatio = 0.5f; // Collect 50% of telemetry
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Property | Default | Description |
|
|
83
|
+
|----------|---------|-------------|
|
|
84
|
+
| `ConnectionString` | `null` | Application Insights connection string |
|
|
85
|
+
| `Credential` | `null` | AAD `TokenCredential` for token-based auth |
|
|
86
|
+
| `EnableQuickPulseMetricStream` | `true` | Enables Live Metrics |
|
|
87
|
+
| `EnableDependencyTrackingTelemetryModule` | `true` | Tracks HTTP/SQL dependencies |
|
|
88
|
+
| `EnableRequestTrackingTelemetryModule` | `true` | Tracks incoming requests |
|
|
89
|
+
| `TracesPerSecond` | `5` | Rate-limited sampling target |
|
|
90
|
+
| `SamplingRatio` | `null` | Fixed-rate sampling (0.0–1.0); overrides `TracesPerSecond` |
|
|
91
|
+
|
|
92
|
+
## Connection String Resolution Order
|
|
93
|
+
|
|
94
|
+
1. `ApplicationInsightsServiceOptions.ConnectionString` (code)
|
|
95
|
+
2. Environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING`
|
|
96
|
+
3. Config key `ApplicationInsights:ConnectionString`
|
|
97
|
+
|
|
98
|
+
## Extending with OpenTelemetry
|
|
99
|
+
|
|
100
|
+
Application Insights 3.x is built on OpenTelemetry. You can add additional sources:
|
|
101
|
+
|
|
102
|
+
```csharp
|
|
103
|
+
builder.Services.AddApplicationInsightsTelemetry();
|
|
104
|
+
builder.Services.AddOpenTelemetry()
|
|
105
|
+
.WithTracing(t => t.AddSource("MyApp.CustomSource"))
|
|
106
|
+
.WithMetrics(m => m.AddMeter("MyApp.CustomMeter"));
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## See Also
|
|
110
|
+
|
|
111
|
+
- AddApplicationInsightsTelemetry API (see in AddApplicationInsightsTelemetry.md)
|
|
112
|
+
- ASP.NET Core Setup Example (see in aspnetcore-setup.md)
|
|
113
|
+
- App Insights 2.x to 3.x Migration (see in appinsights-2x-to-3x-code-migration.md)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Application Insights for Classic ASP.NET
|
|
3
|
+
category: concepts
|
|
4
|
+
applies-to: dotnet-framework
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Application Insights for Classic ASP.NET
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Classic ASP.NET applications (.NET Framework 4.6.2+) use `Microsoft.ApplicationInsights.Web` for automatic request, dependency, and exception tracking. In 3.x, the package is built on OpenTelemetry internally.
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
1. **NuGet package install** creates `ApplicationInsights.config` and registers HTTP modules in `Web.config`
|
|
16
|
+
2. **`ApplicationInsightsHttpModule`** runs on every request — reads config, initializes `TelemetryConfiguration`, sets up the OpenTelemetry pipeline
|
|
17
|
+
3. **`TelemetryHttpModule`** (from `OpenTelemetry.Instrumentation.AspNet`) captures request spans via `System.Diagnostics.Activity`
|
|
18
|
+
4. **No code changes needed** — request tracking, dependency tracking, and exception tracking are automatic
|
|
19
|
+
|
|
20
|
+
## Key configuration files
|
|
21
|
+
|
|
22
|
+
| File | Purpose |
|
|
23
|
+
|---|---|
|
|
24
|
+
| `ApplicationInsights.config` | Connection string, sampling, feature flags |
|
|
25
|
+
| `Web.config` | HTTP module registration (auto-configured by NuGet) |
|
|
26
|
+
|
|
27
|
+
## ApplicationInsights.config (3.x format)
|
|
28
|
+
|
|
29
|
+
```xml
|
|
30
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
31
|
+
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
|
|
32
|
+
<ConnectionString>InstrumentationKey=...;IngestionEndpoint=https://...</ConnectionString>
|
|
33
|
+
<TracesPerSecond>5.0</TracesPerSecond>
|
|
34
|
+
<EnableTraceBasedLogsSampler>true</EnableTraceBasedLogsSampler>
|
|
35
|
+
<EnableQuickPulseMetricStream>true</EnableQuickPulseMetricStream>
|
|
36
|
+
<EnablePerformanceCounterCollectionModule>true</EnablePerformanceCounterCollectionModule>
|
|
37
|
+
<EnableDependencyTrackingTelemetryModule>true</EnableDependencyTrackingTelemetryModule>
|
|
38
|
+
<EnableRequestTrackingTelemetryModule>true</EnableRequestTrackingTelemetryModule>
|
|
39
|
+
<AddAutoCollectedMetricExtractor>true</AddAutoCollectedMetricExtractor>
|
|
40
|
+
</ApplicationInsights>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Web.config HTTP modules (auto-configured)
|
|
44
|
+
|
|
45
|
+
```xml
|
|
46
|
+
<system.webServer>
|
|
47
|
+
<modules>
|
|
48
|
+
<add name="ApplicationInsightsWebTracking"
|
|
49
|
+
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
|
|
50
|
+
preCondition="managedHandler" />
|
|
51
|
+
<add name="TelemetryHttpModule"
|
|
52
|
+
type="OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule, OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule"
|
|
53
|
+
preCondition="integratedMode,managedHandler" />
|
|
54
|
+
</modules>
|
|
55
|
+
</system.webServer>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Extensibility — Custom processors
|
|
59
|
+
|
|
60
|
+
Use `TelemetryConfiguration.ConfigureOpenTelemetryBuilder` in `Global.asax.cs`:
|
|
61
|
+
|
|
62
|
+
```csharp
|
|
63
|
+
using Microsoft.ApplicationInsights.Extensibility;
|
|
64
|
+
using OpenTelemetry.Trace;
|
|
65
|
+
using OpenTelemetry.Resources;
|
|
66
|
+
|
|
67
|
+
protected void Application_Start()
|
|
68
|
+
{
|
|
69
|
+
var config = TelemetryConfiguration.CreateDefault();
|
|
70
|
+
config.ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...";
|
|
71
|
+
config.ConfigureOpenTelemetryBuilder(otel =>
|
|
72
|
+
{
|
|
73
|
+
otel.WithTracing(tracing => tracing.AddProcessor<MyCustomProcessor>());
|
|
74
|
+
otel.ConfigureResource(r => r.AddService("MyServiceName"));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
AreaRegistration.RegisterAllAreas();
|
|
78
|
+
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Requirements
|
|
83
|
+
|
|
84
|
+
- .NET Framework **4.6.2** or later (3.x raised minimum from 4.5.2)
|
|
85
|
+
- IIS or IIS Express
|
|
86
|
+
- `Microsoft.ApplicationInsights.Web` 3.x NuGet package
|
|
87
|
+
|
|
88
|
+
## What's automatic (no code needed)
|
|
89
|
+
|
|
90
|
+
- HTTP request tracking (all incoming requests)
|
|
91
|
+
- SQL dependency tracking
|
|
92
|
+
- HTTP dependency tracking (outgoing `HttpClient` / `WebRequest` calls)
|
|
93
|
+
- Exception tracking
|
|
94
|
+
- Performance counter collection
|
|
95
|
+
- Live Metrics (Quick Pulse)
|
|
@@ -99,4 +99,4 @@ builder.Services.AddOpenTelemetry().UseAzureMonitor(options =>
|
|
|
99
99
|
|
|
100
100
|
- OpenTelemetry Pipeline(see in opentelemetry-pipeline.md)
|
|
101
101
|
- UseAzureMonitor API(see in api-reference/dotnet/UseAzureMonitor.md)
|
|
102
|
-
- Basic Setup Example(see in examples/dotnet/aspnetcore-setup.md)
|
|
102
|
+
- Basic Setup Example(see in examples/dotnet/aspnetcore-distro-setup.md)
|
|
@@ -53,5 +53,5 @@ See the AddOpenTelemetry API reference(see in AddOpenTelemetry.md) for full setu
|
|
|
53
53
|
|
|
54
54
|
## See Also
|
|
55
55
|
|
|
56
|
-
-
|
|
56
|
+
- Application Insights for ASP.NET Core(see in appinsights-aspnetcore.md)
|
|
57
57
|
- AddOpenTelemetry API(see in AddOpenTelemetry.md)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Azure Monitor for Node.js
|
|
2
|
+
|
|
3
|
+
Azure Monitor OpenTelemetry for Node.js provides automatic instrumentation and telemetry collection for Node.js applications.
|
|
4
|
+
|
|
5
|
+
## Key Features
|
|
6
|
+
|
|
7
|
+
- **Automatic Instrumentation**: Captures HTTP requests, database calls, and external dependencies
|
|
8
|
+
- **Custom Telemetry**: Track custom events, metrics, and traces
|
|
9
|
+
- **Performance Monitoring**: Monitor response times, throughput, and failures
|
|
10
|
+
- **Dependency Tracking**: Understand outgoing calls to databases, APIs, and services
|
|
11
|
+
- **Distributed Tracing**: Follow requests across microservices
|
|
12
|
+
|
|
13
|
+
## Supported Frameworks
|
|
14
|
+
|
|
15
|
+
- Express.js
|
|
16
|
+
- Next.js (via instrumentation hook — requires webpack externals configuration)
|
|
17
|
+
- Fastify
|
|
18
|
+
- NestJS
|
|
19
|
+
- Koa
|
|
20
|
+
- Hapi
|
|
21
|
+
- And many more through OpenTelemetry auto-instrumentation
|
|
22
|
+
|
|
23
|
+
> **Note**: Next.js requires special setup due to its webpack bundling. See the Next.js Setup Guide(see in basic-setup-nextjs.md) for details on externalizing server-only packages.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @azure/monitor-opentelemetry
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Basic Setup
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const { useAzureMonitor } = require('@azure/monitor-opentelemetry');
|
|
35
|
+
|
|
36
|
+
// Enable Azure Monitor at startup
|
|
37
|
+
useAzureMonitor({
|
|
38
|
+
azureMonitorExporterOptions: {
|
|
39
|
+
connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Your application code follows...
|
|
44
|
+
const express = require('express');
|
|
45
|
+
const app = express();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Configuration Options
|
|
49
|
+
|
|
50
|
+
The `useAzureMonitor()` function accepts configuration for:
|
|
51
|
+
- Connection string
|
|
52
|
+
- Sampling rate
|
|
53
|
+
- Custom resource attributes
|
|
54
|
+
- Instrumentation configuration
|
|
55
|
+
- Logging options
|
|
56
|
+
|
|
57
|
+
## What Gets Instrumented
|
|
58
|
+
|
|
59
|
+
### Automatically Captured
|
|
60
|
+
- HTTP/HTTPS requests and responses
|
|
61
|
+
- Database queries (MongoDB, MySQL, PostgreSQL, etc.)
|
|
62
|
+
- Redis operations
|
|
63
|
+
- External HTTP calls
|
|
64
|
+
- Exceptions and errors
|
|
65
|
+
|
|
66
|
+
### Custom Telemetry
|
|
67
|
+
```javascript
|
|
68
|
+
const { trace } = require('@opentelemetry/api');
|
|
69
|
+
|
|
70
|
+
// Get current span
|
|
71
|
+
const span = trace.getActiveSpan();
|
|
72
|
+
span?.setAttribute('custom.attribute', 'value');
|
|
73
|
+
|
|
74
|
+
// Log custom events
|
|
75
|
+
console.log('Custom event logged'); // Captured as trace
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Best Practices
|
|
79
|
+
|
|
80
|
+
1. **Initialize Early**: Call `useAzureMonitor()` before loading other modules
|
|
81
|
+
2. **Use Environment Variables**: Store connection string in `.env` file
|
|
82
|
+
3. **Enable Sampling**: For high-traffic apps, configure sampling to manage costs
|
|
83
|
+
4. **Add Context**: Use custom attributes to enrich telemetry
|
|
84
|
+
5. **Monitor Performance**: Set up alerts in Azure Monitor for key metrics
|
|
85
|
+
|
|
86
|
+
## Connection String
|
|
87
|
+
|
|
88
|
+
Get your connection string from Azure Portal:
|
|
89
|
+
1. Navigate to your Application Insights resource
|
|
90
|
+
2. Go to "Overview" section
|
|
91
|
+
3. Copy the "Connection String" value
|
|
92
|
+
|
|
93
|
+
Set it as an environment variable:
|
|
94
|
+
```bash
|
|
95
|
+
export APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=..."
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Or in `.env` file:
|
|
99
|
+
```
|
|
100
|
+
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=...
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Links
|
|
104
|
+
|
|
105
|
+
- [Azure Monitor OpenTelemetry for Node.js Documentation](https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-enable?tabs=nodejs)
|
|
106
|
+
- [OpenTelemetry for Node.js](https://opentelemetry.io/docs/instrumentation/js/)
|