Skip to content

filter out logs based on ActivityTraceFlags #3918

@cataggar

Description

@cataggar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestlogsLogging signal related

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions