open-telemetry/opentelemetry-dotnet
在 GitHub 查看[feature request] Being able to filter logs like activities with a processor
Open
#5,924 创建于 2024年10月25日
contribfestdocumentationenhancementgood first issuekeep-openpkg:OpenTelemetry
仓库指标
- Star
- (3,725 star)
- PR 合并指标
- (PR 指标待抓取)
描述
Package
OpenTelemetry
Is your feature request related to a problem?
Is it possible to give the possibility to custom processors to be able to filter "logs" as it is already possible with custom processors on "activities"?
What is the expected behavior?
Example:
/// <summary>
/// Represents the processor for filtering logs on <see cref="LogRecord"/> if is necessary.
/// </summary>
public class FilterLogsProcessor : BaseProcessor<LogRecord>
{
/// <inheritdoc/>
public override void OnEnd(LogRecord data)
{
var pathAttributeValue = data.Attributes?.FirstOrDefault(attribute => attribute.Key == "Path").Value?.ToString();
if (!string.IsNullOrEmpty(pathAttributeValue)
&& (pathAttributeValue.Contains("liveness") || pathAttributeValue.Contains("health") || pathAttributeValue.Contains("metrics")))
{
// TODO: Configure the log record here, so that it is not exported
}
var endpointNameAttributeValue = data.Attributes?.FirstOrDefault(attribute => attribute.Key == "EndpointName").Value?.ToString();
if (!string.IsNullOrEmpty(endpointNameAttributeValue)
&& (endpointNameAttributeValue.Contains("Health")))
{
// TODO: Configure the log record here, so that it is not exported
}
base.OnEnd(data);
}
}
Which alternative solutions or features have you considered?
At the moment, we have not found any workaround to avoid polluting our Azure Application Insights with the logs of our healthchecks
Additional context
We use the Azure Monitor exporter as follows:
builder.Logging.AddOpenTelemetry(builder =>
{
builder.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(TelemetryHelper.ServiceName, serviceInstanceId: TelemetryHelper.ServiceInstanceId));
builder.IncludeFormattedMessage = true;
builder.IncludeScopes = true;
builder.ParseStateValues = true;
builder.AddProcessor(new RemoveExceptionProcessor());
builder.AddProcessor(new FilterLogsProcessor());
builder.AddAzureMonitorLogExporter(options => options.ConnectionString = configuration["AzureMonitor:ApplicationInsights:ConnectionString"]);
});