open-telemetry/opentelemetry-dotnet
View on GitHub[feature request] Being able to filter logs like activities with a processor
Open
#5,924 opened on Oct 25, 2024
contribfestdocumentationenhancementgood first issuekeep-openpkg:OpenTelemetry
Repository metrics
- Stars
- (3,725 stars)
- PR merge metrics
- (PR metrics pending)
Description
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"]);
});