Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
本指南提供有关在 Azure Monitor Application Insights 中筛选 OpenTelemetry (OTel) 数据的说明。 通过实施筛选器,开发人员可以排除不必要的遥测数据,并防止收集敏感信息,确保优化性能和符合性。
你可能想要筛出遥测的原因包括:
- 筛出运行状况检查遥测,以减少噪音。
- 确保不会收集到个人身份信息(PII)和凭据。
- 筛出低价值的遥测以优化性能。
若要详细了解 OpenTelemetry 概念,请参阅 OpenTelemetry 概述或 OpenTelemetry 常见问题解答。
如需 Azure Monitor OpenTelemetry 发行版中包含的所有检测库的列表,请参阅添加和修改适用于 .NET、Java、Node.js 和 Python 应用程序的 Azure Monitor OpenTelemetry。
许多检测库都提供筛选选项。 有关指南,请参阅对应的README文件:
1 在包中提供 SqlClient 检测,尽管它仍处于 beta 版。 当它成为稳定版时,我们会将其作为标准包引用而添加。 在此期间,若要自定义 SQLClient 仪表,请将 OpenTelemetry.Instrumentation.SqlClient
包引用添加到项目中并使用其公共 API。
dotnet add package --prerelease OpenTelemetry.Instrumentation.SqlClient
builder.Services.AddOpenTelemetry().UseAzureMonitor().WithTracing(builder =>
{
builder.AddSqlClientInstrumentation(options =>
{
options.SetDbStatementForStoredProcedure = false;
});
});
使用自定义处理器:
Sugerencia
在添加 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();
使用以下代码将
ActivityFilteringProcessor.cs
添加到你的项目: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; } } }
如果没有使用 AddSource("ActivitySourceName")
显式添加特定源,则不会导出使用该源创建的任何活动。
- 若要进一步配置 OpenTelemetry 发行版,请参阅 Azure Monitor OpenTelemetry 配置。
- 若要查看源代码,请参阅 Azure Monitor AspNetCore GitHub 存储库。
- 若要安装 NuGet 包、检查更新或查看发行说明,请参阅 Azure Monitor AspNetCore NuGet 包页面。
- 若要进一步了解 Azure Monitor 和 OpenTelemetry,请参阅 Azure Monitor 示例应用程序。
- 若要详细了解 OpenTelemetry 及其社区,请参阅 OpenTelemetry .NET GitHub 存储库。
- 若要启用使用体验,请启用 Web 或浏览器用户监视。
- 若要查看常见问题解答、故障排除步骤、支持选项或提供 OpenTelemetry 反馈,请参阅适用于 Azure Monitor Application Insights 的 OpenTelemetry 帮助、支持和反馈。