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

[BUG] unable to filter log records exported to Azure Monitor #32276

Closed
cataggar opened this issue Nov 3, 2022 · 19 comments
Closed

[BUG] unable to filter log records exported to Azure Monitor #32276

cataggar opened this issue Nov 3, 2022 · 19 comments
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Exporter Monitor OpenTelemetry Exporter needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@cataggar
Copy link
Member

cataggar commented Nov 3, 2022

Library name and version

Azure.Monitor.OpenTelemetry.Exporter 1.0.0-beta.4

Describe the bug

I want to prevent logs from being sent to Azure.Monitor. Based on the filtering processor example, I created:

open System.Diagnostics
open OpenTelemetry
open OpenTelemetry.Logs

/// Remove Heartbeat from Host.Results
type HeartbeatLogFilter() =
    inherit BaseProcessor<LogRecord>()
    override _.OnEnd log =
        if log.CategoryName = "Host.Results" then
            let fullName =
                log.StateValues |> Seq.tryPick(fun kv ->
                    if kv.Key = "FullName" then
                        Some kv.Value
                    else
                        None
                )
            if fullName = Some "Heartbeat" then
                log.TraceFlags <- log.TraceFlags &&& ~~~ ActivityTraceFlags.Recorded

It removes ActivityTraceFlags.Recorded from the LogRecord.TraceFlags.

Expected behavior

I was expecting the log records with ActivityTraceFlags.Recorded removed to not be exported to Azure Monitor.

Actual behavior

The log records still end up in Azure Monitor.

Reproduction Steps

Please see the Microsoft internal pull request.

Environment

No response

@ghost ghost added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Nov 3, 2022
@azure-sdk
Copy link
Collaborator

Label prediction was below confidence level 0.6 for Model:ServiceLabels: 'Storage:0.116750255,Service Bus:0.11560577,Azure.Identity:0.08867687'

@cataggar cataggar changed the title [BUG] filter [BUG] unable to filter log records exported to Azure Monitor Nov 3, 2022
@cataggar cataggar added the Monitor - Exporter Monitor OpenTelemetry Exporter label Nov 3, 2022
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Nov 3, 2022
@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team CXP Attention labels Nov 3, 2022
@ghost
Copy link

ghost commented Nov 3, 2022

Thank you for your feedback. This has been routed to the support team for assistance.

@navba-MSFT navba-MSFT added Service Attention Workflow: This issue is responsible by Azure service team. and removed CXP Attention labels Nov 4, 2022
@ghost
Copy link

ghost commented Nov 4, 2022

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas, @reyang, @rajkumar-rangaraj, @TimothyMothra, @vishweshbankwar.

Issue Details

Library name and version

Azure.Monitor.OpenTelemetry.Exporter 1.0.0-beta.4

Describe the bug

I want to prevent logs from being sent to Azure.Monitor. Based on the filtering processor example, I created:

open System.Diagnostics
open OpenTelemetry
open OpenTelemetry.Logs

/// Remove Heartbeat from Host.Results
type HeartbeatLogFilter() =
    inherit BaseProcessor<LogRecord>()
    override _.OnEnd log =
        if log.CategoryName = "Host.Results" then
            let fullName =
                log.StateValues |> Seq.tryPick(fun kv ->
                    if kv.Key = "FullName" then
                        Some kv.Value
                    else
                        None
                )
            if fullName = Some "Heartbeat" then
                log.TraceFlags <- log.TraceFlags &&& ~~~ ActivityTraceFlags.Recorded

It removes ActivityTraceFlags.Recorded from the LogRecord.TraceFlags.

Expected behavior

I was expecting the log records with ActivityTraceFlags.Recorded removed to not be exported to Azure Monitor.

Actual behavior

The log records still end up in Azure Monitor.

Reproduction Steps

Please see the Microsoft internal pull request.

Environment

No response

Author: cataggar
Assignees: -
Labels:

Service Attention, Client, customer-reported, question, needs-team-attention, Monitor - Exporter

Milestone: -

@navba-MSFT
Copy link
Contributor

Adding Service team to look into this.

@cijothomas
Copy link
Contributor

https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/docs/trace/extending-the-sdk/README.md#filtering-processor is only applicable for Traces, not logs.

OpenTelemetry Logging is based on ILogger, and the filtering capabilities provided by ILogger itself can be used to filter logs.
https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/logs/customizing-the-sdk#log-filtering

@cijothomas
Copy link
Contributor

We can close this. This is not an issue/questions specific to AzureMonitor.

@cataggar cataggar closed this as completed Nov 4, 2022
@cataggar
Copy link
Member Author

cataggar commented Nov 4, 2022

Thank you @cijothomas 🥇

@cataggar
Copy link
Member Author

cataggar commented Nov 4, 2022

Unfortunately, the ILoggerBuilder filters are limited to filtering by log.CategoryName and log.LogLevel only. I need to filter based on log.StateValues. Can the filtering processor be made applicable for logs too please?

image

@cataggar cataggar reopened this Nov 4, 2022
@vishweshbankwar
Copy link
Contributor

@cataggar There is no recommended way to filter out logs based on ActivityTraceFlags. Since this is not Azure Monitor specific question, Could you please open an issue here https://github.com/open-telemetry/opentelemetry-dotnet.

@vishweshbankwar
Copy link
Contributor

Closing this as the issue is related to OTel Sdk.

@navba-MSFT navba-MSFT removed the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Nov 8, 2022
@navba-MSFT navba-MSFT self-assigned this Nov 8, 2022
@cataggar
Copy link
Member Author

@cataggar
Copy link
Member Author

You can write own FilteringProcessor wrapping the exporting processor, but that'll only work if the Exporter being target has public ctor.
open-telemetry/opentelemetry-dotnet#3918 (comment)

Can class AzureMonitorLogExporter please be made public so that it can be wrapped in a FilteringProcessor? It is currently internal:

internal class AzureMonitorLogExporter : BaseExporter<LogRecord>
{
private readonly ITransmitter _transmitter;
private readonly string _instrumentationKey;
private readonly ResourceParser _resourceParser;
private readonly AzureMonitorPersistentStorage _persistentStorage;
public AzureMonitorLogExporter(AzureMonitorExporterOptions options, TokenCredential credential = null) : this(new AzureMonitorTransmitter(options, credential))
{
}

@navba-MSFT navba-MSFT removed their assignment Dec 19, 2022
@navba-MSFT navba-MSFT removed the Service Attention Workflow: This issue is responsible by Azure service team. label Dec 19, 2022
@ghost ghost added the needs-team-triage Workflow: This issue needs the team to triage. label Dec 19, 2022
@navba-MSFT navba-MSFT added Service Attention Workflow: This issue is responsible by Azure service team. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-team-triage Workflow: This issue needs the team to triage. labels Dec 19, 2022
@ghost
Copy link

ghost commented Dec 19, 2022

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas, @reyang, @rajkumar-rangaraj, @TimothyMothra, @vishweshbankwar.

Issue Details

Library name and version

Azure.Monitor.OpenTelemetry.Exporter 1.0.0-beta.4

Describe the bug

I want to prevent logs from being sent to Azure.Monitor. Based on the filtering processor example, I created:

open System.Diagnostics
open OpenTelemetry
open OpenTelemetry.Logs

/// Remove Heartbeat from Host.Results
type HeartbeatLogFilter() =
    inherit BaseProcessor<LogRecord>()
    override _.OnEnd log =
        if log.CategoryName = "Host.Results" then
            let fullName =
                log.StateValues |> Seq.tryPick(fun kv ->
                    if kv.Key = "FullName" then
                        Some kv.Value
                    else
                        None
                )
            if fullName = Some "Heartbeat" then
                log.TraceFlags <- log.TraceFlags &&& ~~~ ActivityTraceFlags.Recorded

It removes ActivityTraceFlags.Recorded from the LogRecord.TraceFlags.

Expected behavior

I was expecting the log records with ActivityTraceFlags.Recorded removed to not be exported to Azure Monitor.

Actual behavior

The log records still end up in Azure Monitor.

Reproduction Steps

Please see the Microsoft internal pull request.

Environment

No response

Author: cataggar
Assignees: -
Labels:

Service Attention, Client, customer-reported, question, needs-team-attention, Monitor - Exporter

Milestone: -

@navba-MSFT
Copy link
Contributor

Adding Service team to answer the above question:

#32276 (comment)

@cijothomas
Copy link
Contributor

You can write own FilteringProcessor wrapping the exporting processor, but that'll only work if the Exporter being target has public ctor.
open-telemetry/opentelemetry-dotnet#3918 (comment)

Can class AzureMonitorLogExporter please be made public so that it can be wrapped in a FilteringProcessor? It is currently internal:

internal class AzureMonitorLogExporter : BaseExporter<LogRecord>
{
private readonly ITransmitter _transmitter;
private readonly string _instrumentationKey;
private readonly ResourceParser _resourceParser;
private readonly AzureMonitorPersistentStorage _persistentStorage;
public AzureMonitorLogExporter(AzureMonitorExporterOptions options, TokenCredential credential = null) : this(new AzureMonitorTransmitter(options, credential))
{
}

@rajkumar-rangaraj Did we discuss/decide about making the Exporter public?

@zyofeng
Copy link

zyofeng commented Mar 5, 2023

At least in beta 3 release this was still public, alternatively it would be good to provide some kind of filtering logic in AzureMonitorExporterOptions,

something like
public Func<Activity, bool> Filter { get; set; }

@cataggar
Copy link
Member Author

It looks like AzureMonitorLogExporter is still internal. Can it be made public?

@cataggar
Copy link
Member Author

#35568 will make it public.

@cataggar
Copy link
Member Author

cataggar commented Apr 27, 2023

I am hesitant to close those this. I was able to find a workaround for the logs created in this case. Hopefully, better ILogger filtering support will be possible generically for .NET. dotnet/runtime#82465

@github-actions github-actions bot locked and limited conversation to collaborators Jul 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Exporter Monitor OpenTelemetry Exporter needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

8 participants
@jsquire @cijothomas @vishweshbankwar @zyofeng @azure-sdk @navba-MSFT @cataggar and others