Skip to content

Commit c392963

Browse files
Merge pull request #260020 from AaronMaxwell/aaronmax-otel-dotnetcore-events
Adding code samples for custom events
2 parents a0a3c23 + 7c15351 commit c392963

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

articles/azure-monitor/app/opentelemetry-add-modify.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ The following table represents the currently supported custom telemetry types:
374374
> [!NOTE]
375375
> Custom Metrics are under preview in Azure Monitor Application Insights. Custom metrics without dimensions are available by default. To view and alert on dimensions, you need to [opt-in](pre-aggregated-metrics-log-metrics.md#custom-metrics-dimensions-and-pre-aggregation).
376376
377-
Consider collecting more metrics beyond what's provided by the instrumentation libraries.
378-
379377
The OpenTelemetry API offers six metric "instruments" to cover various metric scenarios and you need to pick the correct "Aggregation Type" when visualizing metrics in Metrics Explorer. This requirement is true when using the OpenTelemetry Metric API to send metrics and when using an instrumentation library.
380378

381379
The following table shows the recommended [aggregation types](../essentials/metrics-aggregation-explained.md#aggregation-types) for each of the OpenTelemetry Metric Instruments.
@@ -1380,15 +1378,51 @@ Currently unavailable.
13801378

13811379
### Send custom telemetry using the Application Insights Classic API
13821380

1383-
We recommend you use the OpenTelemetry APIs whenever possible, but there might be some scenarios when you have to use the Application Insights [Classic API](api-custom-events-metrics.md)s.
1381+
We recommend you use the OpenTelemetry APIs whenever possible, but there might be some scenarios when you have to use the Application Insights [Classic API](api-custom-events-metrics.md).
13841382

13851383
#### [ASP.NET Core](#tab/aspnetcore)
13861384

1387-
Not available in .NET.
1385+
##### Events
1386+
1387+
1. Add `Microsoft.ApplicationInsights` to your application:
1388+
1389+
1. Create a `TelemetryClient` instance.
1390+
1391+
> [!NOTE]
1392+
> It's important to only create once instance of the TelemetryClient per application.
1393+
1394+
```csharp
1395+
var telemetryConfiguration = new TelemetryConfiguration { ConnectionString = "" };
1396+
var telemetryClient = new TelemetryClient(telemetryConfiguration);
1397+
```
1398+
1399+
1. Use the client to send custom telemetry.
1400+
1401+
```csharp
1402+
telemetryClient.TrackEvent("testEvent");
1403+
```
13881404

13891405
#### [.NET](#tab/net)
13901406

1391-
Not available in .NET.
1407+
##### Events
1408+
1409+
1. Add `Microsoft.ApplicationInsights` to your application:
1410+
1411+
1. Create a `TelemetryClient` instance.
1412+
1413+
> [!NOTE]
1414+
> It's important to only create once instance of the TelemetryClient per application.
1415+
1416+
```csharp
1417+
var telemetryConfiguration = new TelemetryConfiguration { ConnectionString = "" };
1418+
var telemetryClient = new TelemetryClient(telemetryConfiguration);
1419+
```
1420+
1421+
1. Use the client to send custom telemetry.
1422+
1423+
```csharp
1424+
telemetryClient.TrackEvent("testEvent");
1425+
```
13921426

13931427
#### [Java](#tab/java)
13941428

@@ -1915,7 +1949,7 @@ Attaching custom dimensions to logs can be accomplished using a [message templat
19151949

19161950
Logback, Log4j, and java.util.logging are [autoinstrumented](#logs). Attaching custom dimensions to your logs can be accomplished in these ways:
19171951

1918-
* [Log4j 2.0 MapMessage](https://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/message/MapMessage.html) (a `MapMessage` key of `"message"` is captured as the log message)
1952+
* [Log4j 2.0 MapMessage](https://logging.apache.org/log4j/2.0/javadoc/log4j-api/org/apache/logging/log4j/message/MapMessage.html) (a `MapMessage` key of `"message"` is captured as the log message)
19191953
* [Log4j 2.0 Thread Context](https://logging.apache.org/log4j/2.x/manual/thread-context.html)
19201954
* [Log4j 1.2 MDC](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/MDC.html)
19211955

0 commit comments

Comments
 (0)