Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions docs/trace/extending-the-sdk/MyFilteringProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,28 @@
using System;
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

internal class MyFilteringProcessor : BaseProcessor<Activity>
/// <summary>
/// A custom processor for filtering <see cref="Activity"/> instances.
/// </summary>
/// <remarks>
/// Note: <see cref="CompositeProcessor{T}"/> is used as the base class because
/// the SDK needs to understand that <c>MyFilteringProcessor</c> wraps an inner
/// processor. Without that understanding some features such as <see
/// cref="Resource"/> would unavailable because the SDK needs to push state
/// about the parent <see cref="TracerProvider"/> to all processors in the
/// chain.
/// </remarks>
internal sealed class MyFilteringProcessor : CompositeProcessor<Activity>
{
private readonly Func<Activity, bool> filter;
private readonly BaseProcessor<Activity> processor;

public MyFilteringProcessor(BaseProcessor<Activity> processor, Func<Activity, bool> filter)
: base(new[] { processor })
{
this.filter = filter ?? throw new ArgumentNullException(nameof(filter));
this.processor = processor ?? throw new ArgumentNullException(nameof(processor));
}

public override void OnEnd(Activity activity)
Expand All @@ -35,7 +47,7 @@ public override void OnEnd(Activity activity)
// only if the Filter returns true.
if (this.filter(activity))
{
this.processor.OnEnd(activity);
base.OnEnd(activity);
}
}
}