Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This guide provides instructions on filtering OpenTelemetry (OTel) data within Azure Monitor Application Insights. Implementing filters allows developers to exclude unnecessary telemetry and prevent the collection of sensitive information, ensuring optimized performance and compliance.
Reasons why you might want to filter out telemetry include:
- Filtering out health check telemetry to reduce noise.
- Ensuring PII and credentials aren't collected.
- Filtering out low-value telemetry to optimize performance.
To learn more about OpenTelemetry concepts, see the OpenTelemetry overview or OpenTelemetry FAQ.
For a list of all instrumentation libraries included with the Azure Monitor OpenTelemetry Distro, see Add and modify Azure Monitor OpenTelemetry for .NET, Java, Node.js, and Python applications.
Many instrumentation libraries provide a filter option. For guidance, see the corresponding readme files:
1 We include the SqlClient instrumentation in our package while it's still in beta. When it reaches a stable release, we include it as a standard package reference. Until then, to customize the SQLClient instrumentation, add the OpenTelemetry.Instrumentation.SqlClient
package reference to your project and use its public API.
dotnet add package --prerelease OpenTelemetry.Instrumentation.SqlClient
builder.Services.AddOpenTelemetry().UseAzureMonitor().WithTracing(builder =>
{
builder.AddSqlClientInstrumentation(options =>
{
options.SetDbStatementForStoredProcedure = false;
});
});
Use a custom processor:
Tip
Add the processor shown here before adding Azure Monitor.
// Create an ASP.NET Core application builder. var builder = WebApplication.CreateBuilder(args); // Configure the OpenTelemetry tracer provider to add a new processor named ActivityFilteringProcessor. builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => builder.AddProcessor(new ActivityFilteringProcessor())); // Configure the OpenTelemetry tracer provider to add a new source named "ActivitySourceName". builder.Services.ConfigureOpenTelemetryTracerProvider((sp, builder) => builder.AddSource("ActivitySourceName")); // Add the Azure Monitor telemetry service to the application. This service will collect and send telemetry data to Azure Monitor. builder.Services.AddOpenTelemetry().UseAzureMonitor(); // Build the ASP.NET Core application. var app = builder.Build(); // Start the ASP.NET Core application. app.Run();
Add
ActivityFilteringProcessor.cs
to your project with the following code:public class ActivityFilteringProcessor : BaseProcessor<Activity> { // The OnStart method is called when an activity is started. This is the ideal place to filter activities. public override void OnStart(Activity activity) { // prevents all exporters from exporting internal activities if (activity.Kind == ActivityKind.Internal) { activity.IsAllDataRequested = false; } } }
If a particular source isn't explicitly added by using AddSource("ActivitySourceName")
, then none of the activities created by using that source are exported.
- To further configure the OpenTelemetry distro, see Azure Monitor OpenTelemetry configuration.
- To review the source code, see the Azure Monitor AspNetCore GitHub repository.
- To install the NuGet package, check for updates, or view release notes, see the Azure Monitor AspNetCore NuGet Package page.
- To become more familiar with Azure Monitor and OpenTelemetry, see the Azure Monitor Example Application.
- To learn more about OpenTelemetry and its community, see the OpenTelemetry .NET GitHub repository.
- To enable usage experiences, enable web or browser user monitoring.
- To review frequently asked questions, troubleshooting steps, support options, or to provide OpenTelemetry feedback, see OpenTelemetry help, support, and feedback for Azure Monitor Application Insights.