// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 using System.Diagnostics; using OpenTelemetry; /// /// A custom processor for filtering instances. /// internal sealed class MyFilteringProcessor : BaseProcessor { private readonly Func filter; /// /// Initializes a new instance of the /// class. /// /// Function used to test if an /// should be recorded or dropped. Return to record /// or to drop. public MyFilteringProcessor(Func filter) { this.filter = filter ?? throw new ArgumentNullException(nameof(filter)); } public override void OnEnd(Activity activity) { // Bypass export if the Filter returns false. if (!this.filter(activity)) { activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded; } } }