Skip to content

Commit b9776ed

Browse files
authored
Merge pull request #3067 from microsoft/harskaur/webExporterOptions
Documentation for setting exporter options (BASE and WEB)
2 parents 39a2db8 + dbcce63 commit b9776ed

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

BASE/README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Select the option that best describes your situation:
5959
- [Tracking Page Views](#tracking-page-views)
6060
- [Configuration](#configuration)
6161
- [TelemetryConfiguration](#telemetryconfiguration)
62-
- [Setting Context Properties](#setting-context-properties)
62+
- [Setting Context Properties](#setting-context-properties)
6363
- [Dependency Injection](#dependency-injection)
6464
- [Advanced Scenarios](#advanced-scenarios)
6565
- [Enriching Telemetry with Activity Processors](#enriching-telemetry-with-activity-processors)
@@ -627,6 +627,44 @@ var configuration = new TelemetryConfiguration
627627
};
628628
```
629629

630+
#### Telemetry Configuration Properties
631+
632+
`TelemetryConfiguration` exposes properties that configure settings related to sampling, offline storage, and live metrics emission.
633+
634+
| Property | Type | Default (when null) | Description |
635+
|----------|------|---------------------|-------------|
636+
| `SamplingRatio` | `float?` | `1.0` (100%) | Percentage of opentelemetry traces to sample (0.0 to 1.0) |
637+
| `TracesPerSecond` | `double?` | None | Traces per second (rate-limited sampling) |
638+
| `StorageDirectory` | `string` | Platform-specific* | Directory for offline telemetry storage |
639+
| `DisableOfflineStorage` | `bool?` | `false` | When `true`, disables offline storage for failed transmissions |
640+
| `EnableLiveMetrics` | `bool?` | `true` | Enables Live Metrics stream in Azure Portal |
641+
| `EnableTraceBasedLogsSampler` | `bool?` | `true` | Applies trace sampling decisions to related logs |
642+
643+
*Storage directory defaults: Windows: `%LOCALAPPDATA%\Microsoft\AzureMonitor`, Linux/macOS: `$TMPDIR/Microsoft/AzureMonitor`
644+
645+
> **⚠️ Sampling Configuration:** Configure **either** `SamplingRatio` **or** `TracesPerSecond`, not both. Use `SamplingRatio` for percentage-based sampling (e.g., keep 50% of telemetry). Use `TracesPerSecond` for rate-limited sampling (e.g., keep at most 5 traces per second regardless of load).
646+
647+
**Example:**
648+
649+
```csharp
650+
var configuration = new TelemetryConfiguration
651+
{
652+
ConnectionString = "InstrumentationKey=...;IngestionEndpoint=...",
653+
654+
// Sampling: Choose ONE of these approaches
655+
SamplingRatio = 0.5f, // Keep 50% of telemetry
656+
// TracesPerSecond = 5.0, // OR: Keep max 5 traces/second
657+
658+
// Offline storage
659+
StorageDirectory = @"C:\AppData\MyApp\Telemetry",
660+
DisableOfflineStorage = false,
661+
662+
// Features
663+
EnableLiveMetrics = true,
664+
EnableTraceBasedLogsSampler = true
665+
};
666+
```
667+
630668
#### Configuring OpenTelemetry Integration
631669

632670
In version 3.x, you can extend the SDK using OpenTelemetry's extensibility model. Use `ConfigureOpenTelemetryBuilder()` to access the underlying OpenTelemetry configuration:

WEB/Src/Web/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ public class Global : HttpApplication
3838
**Note:** You need to install the `Azure.Identity` NuGet package to use AAD authentication.
3939

4040
For more information, see the [Azure.Identity documentation](https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme).
41+
42+
### Sampling, Offline Storage, and other configuration
43+
Other options can also be set via the TelemetryConfiguration in the `Global.asax.cs` file. See [documentation for Microsoft.ApplicationInsights](../../../BASE/README.smd#azure-monitor-exporter-options).

examples/ClassicAspNetWebApp/Global.asax.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,40 @@ void Application_Start(object sender, EventArgs e)
1717
// Code that runs on application startup
1818
RouteConfig.RegisterRoutes(RouteTable.Routes);
1919
// BundleConfig.RegisterBundles(BundleTable.Bundles);
20-
21-
// Example: Configure Azure Active Directory (AAD) authentication for Application Insights
22-
// Requires: Install-Package Azure.Identity
20+
21+
// ============================================================================
22+
// EXAMPLE: Configure Application Insights with Azure Monitor Exporter Options
23+
// ============================================================================
24+
//
2325
// var telemetryConfig = TelemetryConfiguration.CreateDefault();
24-
// telemetryConfig.ConnectionString = "InstrumentationKey=YOUR_IKEY;IngestionEndpoint=https://ingestion-endpoint.applicationinsights.azure.com/";
25-
// telemetryConfig.SetAzureTokenCredential(new Azure.Identity.DefaultAzureCredential());
26+
// telemetryConfig.ConnectionString = "";
27+
//
28+
// // SAMPLING: Choose ONE approach (not both)
29+
// // SamplingRatio: Percentage of telemetry to keep (0.0 to 1.0). Default: 1.0 (100%)
30+
// telemetryConfig.SamplingRatio = 0.5f; // Keep 50% of telemetry
31+
// // TracesPerSecond: Rate-limited sampling. Default: null (disabled)
32+
// // telemetryConfig.TracesPerSecond = 5.0; // OR: Keep max 5 traces/second
33+
//
34+
// // OFFLINE STORAGE: Persists telemetry when network is unavailable
35+
// // StorageDirectory: Custom path for offline storage.
36+
// // Default: %LOCALAPPDATA%\Microsoft\AzureMonitor (Windows)
37+
// // $TMPDIR/Microsoft/AzureMonitor (Linux/macOS)
38+
// // telemetryConfig.StorageDirectory = @"C:\AppInsightsStorage";
39+
// // DisableOfflineStorage: Set to true to disable offline storage. Default: false
40+
// telemetryConfig.DisableOfflineStorage = false;
41+
//
42+
// // FEATURES
43+
// // EnableLiveMetrics: Enable real-time metrics streaming. Default: true
44+
// telemetryConfig.EnableLiveMetrics = true;
45+
// // EnableTraceBasedLogsSampler: Apply trace-based sampling to logs. Default: true
46+
// telemetryConfig.EnableTraceBasedLogsSampler = true;
47+
//
48+
// // AUTHENTICATION: Azure AD (Entra ID) token-based auth
49+
// // Requires: Install-Package Azure.Identity
50+
// // telemetryConfig.SetAzureTokenCredential(new Azure.Identity.DefaultAzureCredential());
51+
//
52+
// var telemetryClient = new TelemetryClient(telemetryConfig);
53+
// telemetryClient.Context.Cloud.RoleName = "MyWebApp";
2654
}
2755
}
2856
}

0 commit comments

Comments
 (0)