Skip to content

Commit 5930907

Browse files
author
Timothy Mothra
authored
[AzureMonitor] add readme instructions for CustomEvent (Azure#49101)
* add readme instructions for CustomEvent * distro readme * pr feedback * testing fix for compile error * remove extra file
1 parent 55ac2e3 commit 5930907

File tree

2 files changed

+87
-0
lines changed
  • sdk/monitor
    • Azure.Monitor.OpenTelemetry.AspNetCore
    • Azure.Monitor.OpenTelemetry.Exporter

2 files changed

+87
-0
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,48 @@ In scenarios involving multiple scopes or a single scope with multiple key-value
334334
only the first occurrence of the key-value pair from the outermost scope will be recorded.
335335
However, when the same key is utilized both within a logging scope and directly in the log statement, the value specified in the log message template will take precedence.
336336

337+
### CustomEvents
338+
339+
Azure Monitor relies on OpenTelemetry's Log Signal to create CustomEvents.
340+
For .NET, users will use ILogger and place an attribute named `"microsoft.custom_event.name"` in the message template.
341+
Severity and CategoryName are not recorded in the CustomEvent.
342+
343+
#### via ILogger.Log methods
344+
345+
To send a CustomEvent via ILogger, include the `"microsoft.custom_event.name"` attribute in the message template.
346+
347+
Note: This example shows `LogInformation`, but any Log method can be used.
348+
Severity is not recorded, but depending on your configuration it may be filtered out.
349+
Users should take care to select a severity for CustomEvents that is not filtered out by their configuration.
350+
351+
```csharp
352+
var builder = WebApplication.CreateBuilder(args);
353+
354+
builder.Services.AddOpenTelemetry().UseAzureMonitor();
355+
356+
var app = builder.Build();
357+
358+
app.Logger.LogInformation("{microsoft.custom_event.name} {key1} {key2}", "MyCustomEventName", "value1", "value2");
359+
```
360+
361+
This example generates a CustomEvent structured like this:
362+
363+
```json
364+
{
365+
"name": "Event",
366+
"data": {
367+
"baseType": "EventData",
368+
"baseData": {
369+
"name": "MyCustomEventName",
370+
"properties": {
371+
"key1": "value1",
372+
"key2": "value2"
373+
}
374+
}
375+
}
376+
}
377+
``
378+
337379
## Troubleshooting
338380

339381
The Azure Monitor Distro uses EventSource for its own internal logging. The logs are available to any EventListener by opting into the source named "OpenTelemetry-AzureMonitor-Exporter".

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,51 @@ In scenarios involving multiple scopes or a single scope with multiple key-value
180180
only the first occurrence of the key-value pair from the outermost scope will be recorded.
181181
However, when the same key is utilized both within a logging scope and directly in the log statement, the value specified in the log message template will take precedence.
182182

183+
### CustomEvents
184+
185+
Azure Monitor relies on OpenTelemetry's Log Signal to create CustomEvents.
186+
For .NET, users will use ILogger and place an attribute named `"microsoft.custom_event.name"` in the message template.
187+
Severity and CategoryName are not recorded in the CustomEvent.
188+
189+
#### via ILogger.Log methods
190+
191+
To send a CustomEvent via ILogger, include the `"microsoft.custom_event.name"` attribute in the message template.
192+
193+
Note: This example shows `LogInformation`, but any Log method can be used.
194+
Severity is not recorded, but depending on your configuration it may be filtered out.
195+
Users should take care to select a severity for CustomEvents that is not filtered out by their configuration.
196+
197+
```csharp
198+
var loggerFactory = LoggerFactory.Create(builder =>
199+
{
200+
builder.AddOpenTelemetry(logging =>
201+
{
202+
logging.AddAzureMonitorLogExporter();
203+
});
204+
});
205+
206+
var logger = loggerFactory.CreateLogger(logCategoryName);
207+
logger.LogInformation("{microsoft.custom_event.name} {key1} {key2}", "MyCustomEventName", "value1", "value2");
208+
```
209+
210+
This example generates a CustomEvent structured like this:
211+
212+
```json
213+
{
214+
"name": "Event",
215+
"data": {
216+
"baseType": "EventData",
217+
"baseData": {
218+
"name": "MyCustomEventName",
219+
"properties": {
220+
"key1": "value1",
221+
"key2": "value2"
222+
}
223+
}
224+
}
225+
}
226+
``
227+
183228
## Troubleshooting
184229

185230
The Azure Monitor exporter uses EventSource for its own internal logging. The exporter logs are available to any EventListener by opting into the source named "OpenTelemetry-AzureMonitor-Exporter".

0 commit comments

Comments
 (0)