Skip to content

Commit ef85bb9

Browse files
Documentation fixes and restructuring (#3079)
* fixng inaccuracies & restructuring documentation * minor * toc fix * remove changes from examples * copilot comments * comments --------- Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
1 parent 81f97ca commit ef85bb9

File tree

12 files changed

+490
-1758
lines changed

12 files changed

+490
-1758
lines changed

BASE/README.md

Lines changed: 104 additions & 815 deletions
Large diffs are not rendered by default.

BreakingChanges.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ This applies to all dimension combinations (1D, 2D, 3D, 4D).
106106
-`TelemetryConfiguration(string instrumentationKey)`
107107
-`TelemetryConfiguration(string instrumentationKey, ITelemetryChannel channel)`
108108

109+
#### Methods
110+
-**`CreateFromConfiguration(string config)`** - Static method that created a TelemetryConfiguration from XML configuration string. Use `CreateDefault()` or the parameterless constructor and set properties directly.
111+
109112
### Properties with Changed Behavior
110113
-**`ConnectionString`** - Still exists but behavior differs
111114
- **2.x**: String property
112115
- **3.x**: Setting this calls OpenTelemetry configuration internally
113-
-**`DisableTelemetry`** - Still exists but does not disable flow of telemetry (will be fixed later)
114116

115117
### Methods with changed Behavior
116118
- CreateDefault() returns an internal static configuration instead of a new TelemetryConfiguration()
@@ -139,11 +141,8 @@ Most TelemetryContext modules have now been marked internal or removed. The prop
139141
### Properties Retained
140142

141143
The following remain **public**:
142-
-`Cloud` (RoleName, RoleInstance)
143-
- Note: These are settable via resource attributes (service.name & service.instance.id) in OpenTelemetry; we are working on fixing functionality for setting the same via CloudContext.
144144
-`User` (Id, AuthenticatedUserId, UserAgent)
145-
-`Operation` (Name, SyntheticSource)
146-
- Note: A future work item is to make sure SyntheticSource can be read from properly and emitted in the telemetry item.
145+
-`Operation` (Name)
147146
-`Location` (Ip)
148147
-`GlobalProperties`
149148

@@ -197,6 +196,11 @@ The following extension methods remain with identical signatures:
197196
-**`ExceptionTrackingMiddleware`** - Middleware class removed
198197
-**`HostingDiagnosticListener`** - Diagnostic listener removed
199198
-**`HostingStartupOptions`** - Configuration class removed
199+
-**`Resources`** - Internal resource class removed from public API
200+
- `Resources.Culture` (get/set)
201+
- `Resources.JavaScriptAuthSnippet` (get)
202+
- `Resources.JavaScriptSnippet` (get)
203+
- `Resources.ResourceManager` (get)
200204

201205
### TelemetryInitializers Removed (All 7)
202206
-`AspNetCoreEnvironmentTelemetryInitializer`
@@ -218,13 +222,13 @@ The following extension methods remain with identical signatures:
218222
-**`RequestCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
219223
-**`DependencyCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
220224
-`EnableAdaptiveSampling`** - Removed, rate limited sampling is now the default.
225+
-**`EnableDebugLogger`** - Removed
221226

222227
### Properties Retained
223228
-**`ConnectionString`** - Primary configuration method
224229
-**`ApplicationVersion`**
225230
-**`AddAutoCollectedMetricExtractor`**
226231
-**`EnableQuickPulseMetricStream`**
227-
-**`EnableDebugLogger`** - Retained but has no effect
228232
-**`EnableAuthenticationTrackingJavaScript`** - JavaScript auth tracking config
229233
-**`EnableDependencyTrackingTelemetryModule`** - Dependency tracking toggle
230234
-**`EnablePerformanceCounterCollectionModule`** - Performance counter toggle
@@ -234,6 +238,7 @@ The following extension methods remain with identical signatures:
234238
-**`Credential`** (Azure.Core.TokenCredential) - Enables Azure Active Directory (AAD) authentication
235239
-**`TracesPerSecond`** (double?) - Gets or sets the number of traces per second for rate-limited sampling (default sampling mode). Replaces `EnableAdaptiveSampling`.
236240
-**`SamplingRatio`** (float?) - Gets or sets the sampling ratio for traces (0.0 to 1.0). A value of 1.0 means all telemetry is sent. Replaces `EnableAdaptiveSampling`.
241+
-**`EnableTraceBasedLogsSampler`** (bool?) - Gets or sets whether trace-based log sampling is enabled (default: true). When enabled, logs are sampled based on the sampling decision of the associated trace.
237242

238243
### JavaScriptSnippet Constructor Change
239244
**2.x:**
@@ -286,20 +291,21 @@ The following extension methods remain with identical signatures:
286291
-**`EndpointAddress`** - No longer configurable (`ConnectionString` contains endpoints)
287292
-**`DependencyCollectionOptions`** - Removed (non-functional, use OpenTelemetry instrumentation options)
288293
-**`EnableAdaptiveSampling`** - Removed, rate limited sampling is now the default.
294+
-**`EnableDebugLogger`** - Removed
289295

290296
### Properties Retained
291297
-**`ConnectionString`** - Primary configuration method (maps to `AzureMonitorExporterOptions.ConnectionString`)
292298
-**`ApplicationVersion`** - Still configurable
293299
-**`EnableDependencyTrackingTelemetryModule`** - Still configurable
294300
-**`EnablePerformanceCounterCollectionModule`** - Still configurable
295301
-**`EnableQuickPulseMetricStream`** - Maps to `AzureMonitorExporterOptions.EnableLiveMetrics`
296-
-**`EnableDebugLogger`** - Still configurable though has no effect
297302
-**`AddAutoCollectedMetricExtractor`** - Still configurable
298303

299304
### New Properties Added in 3.x
300305
-**`Credential`** (Azure.Core.TokenCredential) - Enables Azure Active Directory (AAD) authentication
301306
-**`TracesPerSecond`** (double?) - Gets or sets the number of traces per second for rate-limited sampling (default sampling mode). Replaces `EnableAdaptiveSampling`.
302307
-**`SamplingRatio`** (float?) - Gets or sets the sampling ratio for traces (0.0 to 1.0). A value of 1.0 means all telemetry is sent. Replaces `EnableAdaptiveSampling`.
308+
-**`EnableTraceBasedLogsSampler`** (bool?) - Gets or sets whether trace-based log sampling is enabled (default: true). When enabled, logs are sampled based on the sampling decision of the associated trace.
303309

304310
## Migration Impact
305311
- Any code depending on `InstrumentationKey` must migrate to `ConnectionString`

LOGGING/README.md

Lines changed: 3 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
![Build](https://mseng.visualstudio.com/DefaultCollection/_apis/public/build/definitions/96a62c4a-58c2-4dbb-94b6-5979ebc7f2af/2637/badge)
22

33
## Nuget packages
4-
5-
- For ILogger:
6-
[Microsoft.Extensions.Logging.ApplicationInsights](https://www.nuget.org/packages/Microsoft.Extensions.Logging.ApplicationInsights/)
7-
[![Nuget](https://img.shields.io/nuget/vpre/Microsoft.Extensions.Logging.ApplicationInsights.svg)](https://www.nuget.org/packages/Microsoft.Extensions.Logging.ApplicationInsights/)
84
- For NLog:
95
[Microsoft.ApplicationInsights.NLogTarget](http://www.nuget.org/packages/Microsoft.ApplicationInsights.NLogTarget/)
106
[![Nuget](https://img.shields.io/nuget/vpre/Microsoft.ApplicationInsights.NLogTarget.svg)](https://www.nuget.org/packages/Microsoft.ApplicationInsights.NLogTarget/)
11-
- For Log4Net: [Microsoft.ApplicationInsights.Log4NetAppender](http://www.nuget.org/packages/Microsoft.ApplicationInsights.Log4NetAppender/)
12-
[![Nuget](https://img.shields.io/nuget/vpre/Microsoft.ApplicationInsights.Log4NetAppender.svg)](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Log4NetAppender/)
13-
- For System.Diagnostics: [Microsoft.ApplicationInsights.TraceListener](http://www.nuget.org/packages/Microsoft.ApplicationInsights.TraceListener/)
14-
[![Nuget](https://img.shields.io/nuget/vpre/Microsoft.ApplicationInsights.TraceListener.svg)](https://www.nuget.org/packages/Microsoft.ApplicationInsights.TraceListener/)
15-
- [Microsoft.ApplicationInsights.DiagnosticSourceListener](http://www.nuget.org/packages/Microsoft.ApplicationInsights.DiagnosticSourceListener/)
16-
[![Nuget](https://img.shields.io/nuget/vpre/Microsoft.ApplicationInsights.DiagnosticSourceListener.svg)](https://www.nuget.org/packages/Microsoft.ApplicationInsights.DiagnosticSourceListener/)
17-
- [Microsoft.ApplicationInsights.EtwCollector](http://www.nuget.org/packages/Microsoft.ApplicationInsights.EtwCollector/)
18-
[![Nuget](https://img.shields.io/nuget/vpre/Microsoft.ApplicationInsights.EtwCollector.svg)](https://www.nuget.org/packages/Microsoft.ApplicationInsights.EtwCollector/)
19-
- [Microsoft.ApplicationInsights.EventSourceListener](http://www.nuget.org/packages/Microsoft.ApplicationInsights.EventSourceListener/)
20-
[![Nuget](https://img.shields.io/nuget/vpre/Microsoft.ApplicationInsights.EventSourceListener.svg)](https://www.nuget.org/packages/Microsoft.ApplicationInsights.EventSourceListener/)
21-
22-
Application Insights logging adapters.
23-
==============================
24-
25-
If you use NLog, log4Net or System.Diagnostics.Trace for diagnostic tracing in your application, you can have your logs sent to Application Insights, where you can explore and search them. Your logs will be merged with the other telemetry coming from your application, so that you can identify the traces associated with servicing each user request, and correlate them with other events and exception reports.
267

27-
Read more:
28-
- [Microsoft Docs: "Explore .NET trace logs in Application Insights"](https://docs.microsoft.com/azure/application-insights/app-insights-asp-net-trace-logs)
29-
- [Microsoft Docs: "Diagnose sudden changes in your app telemetry"](https://docs.microsoft.com/azure/application-insights/app-insights-analytics-diagnostics#trace)
30-
31-
## ILogger
32-
See [this](src/ILogger/Readme.md).
338

349
## NLog
3510

@@ -78,7 +53,7 @@ For more information, see the [Azure.Identity documentation](https://learn.micro
7853
</extensions>
7954
<targets>
8055
<target xsi:type="ApplicationInsightsTarget" name="aiTarget">
81-
<instrumentationKey>Your_Resource_Key</instrumentationKey> <!-- Only required if not using ApplicationInsights.config -->
56+
<connectionString>InstrumentationKey=YOUR_IKEY;IngestionEndpoint=https://YOUR_REGION.in.applicationinsights.azure.com/</connectionString>
8257
<contextproperty name="threadid" layout="${threadid}" /> <!-- Can be repeated with more context -->
8358
</target>
8459
</targets>
@@ -91,34 +66,22 @@ For more information, see the [Azure.Identity documentation](https://learn.micro
9166
NLog allows you to configure conditional configs:
9267

9368
```xml
94-
<instrumentationKey>${configsetting:APPINSIGHTS.INSTRUMENTATIONKEY:whenEmpty=${environment:APPINSIGHTS_INSTRUMENTATIONKEY}}</instrumentationKey>
69+
<connectionString>${configsetting:APPLICATIONINSIGHTS_CONNECTION_STRING:whenEmpty=${environment:APPLICATIONINSIGHTS_CONNECTION_STRING}}</connectionString>
9570
```
9671

9772
For more information see:
9873
- https://github.com/NLog/NLog/wiki/ConfigSetting-Layout-Renderer
9974
- https://github.com/nlog/nlog/wiki/Environment-Layout-Renderer
10075
- https://github.com/nlog/nlog/wiki/WhenEmpty-Layout-Renderer
10176

102-
103-
104-
```csharp
105-
// You need this only if you did not define InstrumentationKey in ApplicationInsights.config (Or in the NLog.config)
106-
TelemetryConfiguration.Active.InstrumentationKey = "Your_Resource_Key";
107-
108-
Logger logger = LogManager.GetLogger("Example");
109-
110-
logger.Trace("trace log message");
111-
```
112-
11377
* **Configure ApplicationInsightsTarget using NLog Config API** :
11478
If you configure NLog programmatically with the [NLog Config API](https://github.com/nlog/NLog/wiki/Configuration-API), then create Application Insights target in code and add it to your other targets:
11579

11680
```csharp
11781
var config = new LoggingConfiguration();
11882

11983
ApplicationInsightsTarget target = new ApplicationInsightsTarget();
120-
// You need this only if you did not define InstrumentationKey in ApplicationInsights.config or want to use different instrumentation key
121-
target.InstrumentationKey = "Your_Resource_Key";
84+
target.ConnectionString = "InstrumentationKey=....;IngestionEndpoint=...";
12285

12386
LoggingRule rule = new LoggingRule("*", LogLevel.Trace, target);
12487
config.LoggingRules.Add(rule);
@@ -130,79 +93,3 @@ Logger logger = LogManager.GetLogger("Example");
13093
logger.Trace("trace log message");
13194
```
13295

133-
## Log4Net
134-
135-
Application Insights Log4Net adapter nuget modifies web.config and adds Application Insights Appender.
136-
137-
For more information, see [Log4Net Configuration](https://logging.apache.org/log4net/release/manual/configuration.html)
138-
139-
```csharp
140-
// You do not need this if you have instrumentation key in the ApplicationInsights.config
141-
TelemetryConfiguration.Active.InstrumentationKey = "Your_Resource_Key";
142-
143-
log4net.Config.XmlConfigurator.Configure();
144-
var logger = LogManager.GetLogger(this.GetType());
145-
146-
logger.Info("Message");
147-
logger.Warn("A warning message");
148-
logger.Error("An error message");
149-
```
150-
151-
## System.Diagnostics
152-
153-
Microsoft.ApplicationInsights.TraceListener nuget package modifies web.config and adds application insights listener.
154-
155-
For more information, see ["Microsoft Docs: "Tracing and Instrumenting Applications"](https://docs.microsoft.com/dotnet/framework/debug-trace-profile/tracing-and-instrumenting-applications)
156-
157-
```xml
158-
<configuration>
159-
<system.diagnostics>
160-
<trace>
161-
<listeners>
162-
<add name="myAppInsightsListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" />
163-
</listeners>
164-
</trace>
165-
</system.diagnostics>
166-
</configuration>
167-
```
168-
169-
If your application type does not have web.config, add listener programmatically or in the configuration file appropriate to your application type
170-
171-
```csharp
172-
// You do not need this if you have instrumentation key in the ApplicationInsights.config
173-
TelemetryConfiguration.Active.InstrumentationKey = "Your_Resource_Key";
174-
System.Diagnostics.Trace.TraceWarning("Slow response - database01");
175-
176-
```
177-
178-
179-
## EventSource
180-
181-
`EventSourceTelemetryModule` allows you to configure EventSource events to be sent to Application Insights as traces.
182-
183-
For more information, see [Microsoft Docs: "Using EventSource Events"](https://docs.microsoft.com/azure/application-insights/app-insights-asp-net-trace-logs#using-eventsource-events).
184-
185-
186-
## ETW
187-
188-
`EtwCollectorTelemetryModule` allows you to configure events from ETW providers to be sent to Application Insights as traces.
189-
190-
For more information, see [Microsoft Docs: "Using ETW Events"](https://docs.microsoft.com/azure/application-insights/app-insights-asp-net-trace-logs#using-etw-events).
191-
192-
193-
## DiagnosticSource
194-
195-
You can configure `System.Diagnostics.DiagnosticSource` events to be sent to Application Insights as traces.
196-
197-
For more information, see [CoreFX: "Diagnostic Source Users Guide"](https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md).
198-
199-
To enable, edit the `TelemetryModules` section of the ApplicationInsights.config file:
200-
201-
```xml
202-
<Add Type="Microsoft.ApplicationInsights.DiagnsoticSourceListener.DiagnosticSourceTelemetryModule, Microsoft.ApplicationInsights.DiagnosticSourceListener">
203-
<Sources>
204-
<Add Name="MyDiagnosticSourceName" />
205-
</Sources>
206-
</Add>
207-
```
208-

0 commit comments

Comments
 (0)