Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Being able to filter logs like activities with a processor #5924

Open
tovich37 opened this issue Oct 25, 2024 · 1 comment
Labels
documentation Documentation related enhancement New feature or request good first issue Good for newcomers pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Comments

@tovich37
Copy link

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"]);
});
@tovich37 tovich37 added enhancement New feature or request needs-triage New issues which have not been classified or triaged by a community member labels Oct 25, 2024
@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Oct 25, 2024
@rajkumar-rangaraj
Copy link
Contributor

@tovich37 This is a PR from the Azure SDK repo. It contains a sample for the LogFilteringProcessor and its registration. Check if that could help you. We plan to document this in the repo (https://github.com/Azure/azure-sdk-for-net/pull/44745/files#r1655622219) when we have the cycles to update the documentation.

@cijothomas cijothomas added good first issue Good for newcomers documentation Documentation related and removed needs-triage New issues which have not been classified or triaged by a community member labels Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation related enhancement New feature or request good first issue Good for newcomers pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

No branches or pull requests

3 participants