Skip to content

Commit 9f0ec72

Browse files
committed
Touching up FAQ
1 parent 3821035 commit 9f0ec72

File tree

1 file changed

+78
-26
lines changed

1 file changed

+78
-26
lines changed

articles/azure-monitor/app/opentelemetry-dotnet-migrate.md

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,63 @@ The following libraries are included in the Distro.
488488
- [ASP.NET Core](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AspNetCore)
489489
- [SQL](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.sqlclient)
490490

491+
#### Customizing Instrumentation Libraries
492+
493+
The Azure Monitor Distro includes .NET OpenTelemetry instrumentation for [ASP.NET Core](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AspNetCore/), [HttpClient](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.Http/), and [SQLClient](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.SqlClient).
494+
You can customize these included instrumentations or manually add additional instrumentation on your own using the OpenTelemetry API.
495+
496+
Here are some examples of how to customize the instrumentation:
497+
498+
##### Customizing AspNetCoreTraceInstrumentationOptions
499+
500+
```C#
501+
builder.Services.AddOpenTelemetry().UseAzureMonitor();
502+
builder.Services.Configure<AspNetCoreTraceInstrumentationOptions>(options =>
503+
{
504+
options.RecordException = true;
505+
options.Filter = (httpContext) =>
506+
{
507+
// only collect telemetry about HTTP GET requests
508+
return HttpMethods.IsGet(httpContext.Request.Method);
509+
};
510+
});
511+
```
512+
513+
##### Customizing HttpClientTraceInstrumentationOptions
514+
515+
```C#
516+
builder.Services.AddOpenTelemetry().UseAzureMonitor();
517+
builder.Services.Configure<HttpClientTraceInstrumentationOptions>(options =>
518+
{
519+
options.RecordException = true;
520+
options.FilterHttpRequestMessage = (httpRequestMessage) =>
521+
{
522+
// only collect telemetry about HTTP GET requests
523+
return HttpMethods.IsGet(httpRequestMessage.Method.Method);
524+
};
525+
});
526+
```
527+
528+
##### Customizing SqlClientInstrumentationOptions
529+
530+
While the [SQLClient](https://www.nuget.org/packages/OpenTelemetry.Instrumentation.SqlClient) instrumentation is still in beta, we have vendored it within our package.
531+
Once it reaches a stable release, it will be included as a standard package reference.
532+
Until then, for customization of the SQLClient instrumentation, manually add the OpenTelemetry.Instrumentation.SqlClient package reference to your project and utilize its public API.
533+
534+
```
535+
dotnet add package --prerelease OpenTelemetry.Instrumentation.SqlClient
536+
```
537+
538+
```C#
539+
builder.Services.AddOpenTelemetry().UseAzureMonitor().WithTracing(builder =>
540+
{
541+
builder.AddSqlClientInstrumentation(options =>
542+
{
543+
options.SetDbStatementForStoredProcedure = false;
544+
});
545+
});
546+
```
547+
491548
### [ASP.NET](#tab/net)
492549

493550
[Instrumentation libraries](https://opentelemetry.io/docs/specs/otel/overview/#instrumentation-libraries) can be added to your project to auto collect telemetry about specific components or dependencies. We recommend the following libraries:
@@ -971,10 +1028,6 @@ This section is for customers who use telemetry initializers or processors, or w
9711028

9721029
### How do the SDK API's map to OpenTelemetry concepts?
9731030

974-
#### How do Application Insights telemetry types map to OpenTelemetry?
975-
976-
#### How do Application Insights sampling concepts map to OpenTelemetry?
977-
9781031
[OpenTelemetry](https://opentelemetry.io/) is a vendor neutral observability framework. There are no Application Insights APIs in the OpenTelemetry SDK or libraries. Before migrating, it's important to understand some of OpenTelemetry's concepts.
9791032
9801033
* In Application Insights, all telemetry was managed through a single `TelemetryClient` and `TelemetryConfiguration`. In OpenTelemetry, each of the three telemetry signals (Traces, Metrics, and Logs) has its own configuration. You can manually create telemetry via the .NET runtime without external libraries. For more information, see the .NET guides on [distributed tracing](/dotnet/core/diagnostics/distributed-tracing-instrumentation-walkthroughs), [metrics](/dotnet/core/diagnostics/metrics), and [logging](/dotnet/core/extensions/logging).
@@ -987,11 +1040,7 @@ With OpenTelemetry, you can write a [Processor](https://opentelemetry.io/docs/co
9871040
9881041
* Application Insights used `TelemetryProcessors` to filter telemetry. An OpenTelemetry [Processor](https://opentelemetry.io/docs/collector/configuration/#processors) can also be used to apply filtering rules on a specific signal.
9891042
990-
* Application Insights offered multiple options to configure sampling.
991-
Azure Monitor Exporter or Azure Monitor Distro only offers fixed rate sampling.
992-
Currently only Traces (Requests and Dependencies) can be sampled.
993-
994-
##### Understanding Telemetry DataTypes
1043+
### How do Application Insights telemetry types map to OpenTelemetry?
9951044

9961045
This table maps Application Insights data types to OpenTelemetry concepts and their .NET implementations.
9971046

@@ -1010,11 +1059,17 @@ The following documents provide more information.
10101059
- [Application Insights telemetry data model](./data-model-complete.md)
10111060
- [OpenTelemetry Concepts](https://opentelemetry.io/docs/concepts/)
10121061
1013-
##### Telemetry Processors and Initializers
1062+
### How do Application Insights sampling concepts map to OpenTelemetry?
1063+
1064+
While Application Insights offered multiple options to configure sampling, Azure Monitor Exporter or Azure Monitor Distro only offers fixed rate sampling. Only *Requests* and *Dependencies* (*OpenTelemetry Traces*) can be sampled.
1065+
1066+
For code samples detailing how to configure sampling, see our guide [Enable Sampling](./opentelemetry-configuration.md#enable-sampling)
1067+
1068+
### How do Telemetry Processors and Initializers map to OpenTelemetry?
10141069

10151070
In the Application Insights .NET SDK, use telemetry processors to filter and modify or discard telemetry. Use telemetry initializers to add or modify custom properties. For more information, see the [Azure Monitor documentation](./api-filtering-sampling.md). OpenTelemetry replaces these concepts with activity or log processors, which enrich and filter telemetry.
10161071

1017-
###### Filtering Traces
1072+
#### Filtering Traces
10181073

10191074
To filter telemetry data in OpenTelemetry, you can implement an activity processor. This example is equivalent to the Application Insights example for filtering telemetry data as described in [Azure Monitor documentation](./api-filtering-sampling.md?tabs=javascriptwebsdkloaderscript#c). The example illustrates where unsuccessful dependency calls are filtered.
10201075

@@ -1053,7 +1108,7 @@ public static void Main()
10531108
}
10541109
```
10551110

1056-
###### Filtering Logs
1111+
#### Filtering Logs
10571112

10581113
[`ILogger`](/dotnet/core/extensions/logging)
10591114
implementations have a built-in mechanism to apply [log
@@ -1074,7 +1129,7 @@ builder.AddFilter<OpenTelemetryLoggerProvider>("MyProduct.MyLibrary.MyClass", Lo
10741129

10751130
For more information, please read the [OpenTelemetry .NET documentation on logs](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/logs/README.md).
10761131
1077-
###### Adding Custom Properties to Traces
1132+
#### Adding Custom Properties to Traces
10781133

10791134
In OpenTelemetry, you can use activity processors to enrich telemetry data with more properties. It's similar to using telemetry initializers in Application Insights, where you can modify telemetry properties.
10801135

@@ -1140,12 +1195,9 @@ public static void Main()
11401195
}
11411196
```
11421197

1143-
While Application Insights offered multiple options to configure sampling, Azure Monitor Exporter or Azure Monitor Distro only offers fixed rate sampling.
1144-
Currently only Traces (Requests and Dependencies) can be sampled.
1145-
1146-
For code samples detailing how to configure sampling, see our guide [Enable Sampling](./opentelemetry-configuration.md#enable-sampling)
1198+
### How do I manually track telemetry using OpenTelemetry?
11471199

1148-
### Sending Traces - Manual
1200+
#### Sending Traces - Manual
11491201

11501202
Traces in Application Insights are stored as `RequestTelemetry` and `DependencyTelemetry`. In OpenTelemetry, traces are modeled as `Span` using the `Activity` class.
11511203

@@ -1292,11 +1344,11 @@ using (var activity = activitySource.StartActivity("CustomOperation", ActivityKi
12921344
}
12931345
```
12941346

1295-
### Sending Logs
1347+
#### Sending Logs
12961348

12971349
Logs in Application Insights are stored as `TraceTelemetry` and `ExceptionTelemetry`.
12981350

1299-
#### TraceTelemetry
1351+
##### TraceTelemetry
13001352

13011353
In OpenTelemetry, logging is integrated via the `ILogger` interface. Here's how to migrate `TraceTelemetry`:
13021354

@@ -1345,7 +1397,7 @@ internal static partial class LoggerExtensions
13451397
}
13461398
```
13471399

1348-
#### ExceptionTelemetry
1400+
##### ExceptionTelemetry
13491401

13501402
Application Insights uses `ExceptionTelemetry` to log exceptions. Here's how to migrate to OpenTelemetry:
13511403

@@ -1395,7 +1447,7 @@ catch (Exception ex)
13951447
}
13961448
```
13971449

1398-
### Sending Metrics
1450+
#### Sending Metrics
13991451

14001452
Metrics in Application Insights are stored as `MetricTelemetry`. In OpenTelemetry, metrics are modeled as `Meter` from the `System.Diagnostics.DiagnosticSource` package.
14011453

@@ -1412,9 +1464,9 @@ Migrating from Application Insights to OpenTelemetry involves replacing all Appl
14121464
> **Tip:**
14131465
> The histogram is the most versatile and the closest equivalent to the Application Insights `GetMetric().TrackValue()` API. You can replace Application Insights Metric APIs with Histogram to achieve the same purpose.
14141466

1415-
### Other Telemetry Types
1467+
#### Other Telemetry Types
14161468

1417-
#### CustomEvents
1469+
##### CustomEvents
14181470

14191471
Not supported in OpenTelemetry.
14201472

@@ -1424,7 +1476,7 @@ Not supported in OpenTelemetry.
14241476
TelemetryClient.TrackEvent()
14251477
```
14261478

1427-
#### AvailabilityTelemetry
1479+
##### AvailabilityTelemetry
14281480

14291481
Not supported in OpenTelemetry.
14301482

@@ -1434,7 +1486,7 @@ Not supported in OpenTelemetry.
14341486
TelemetryClient.TrackAvailability()
14351487
```
14361488

1437-
#### PageViewTelemetry
1489+
##### PageViewTelemetry
14381490

14391491
Not supported in OpenTelemetry.
14401492

0 commit comments

Comments
 (0)