From 870eb92e5c5d29aa25bdf1f6e4ad87acd7be0f63 Mon Sep 17 00:00:00 2001 From: Mikel Blanchard Date: Thu, 16 Jun 2022 15:32:29 -0700 Subject: [PATCH] Examples: Fix ParentProvider not being set on MyFilteringProcessor (#3370) * Fix ParentProvider not being set on MyFilteringProcessor example. * Added XML comments. * Tweak. * Typo. --- .../extending-the-sdk/MyFilteringProcessor.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/trace/extending-the-sdk/MyFilteringProcessor.cs b/docs/trace/extending-the-sdk/MyFilteringProcessor.cs index 22cf898f3b5..ed74678decf 100644 --- a/docs/trace/extending-the-sdk/MyFilteringProcessor.cs +++ b/docs/trace/extending-the-sdk/MyFilteringProcessor.cs @@ -17,16 +17,28 @@ using System; using System.Diagnostics; using OpenTelemetry; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; -internal class MyFilteringProcessor : BaseProcessor +/// +/// A custom processor for filtering instances. +/// +/// +/// Note: is used as the base class because +/// the SDK needs to understand that MyFilteringProcessor wraps an inner +/// processor. Without that understanding some features such as would be unavailable because the SDK needs to push state +/// about the parent to all processors in the +/// chain. +/// +internal sealed class MyFilteringProcessor : CompositeProcessor { private readonly Func filter; - private readonly BaseProcessor processor; public MyFilteringProcessor(BaseProcessor processor, Func 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) @@ -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); } } }