-
Notifications
You must be signed in to change notification settings - Fork 775
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
Examples: Fix ParentProvider not being set on MyFilteringProcessor #3370
Examples: Fix ParentProvider not being set on MyFilteringProcessor #3370
Conversation
Codecov Report
@@ Coverage Diff @@
## main #3370 +/- ##
==========================================
+ Coverage 85.87% 86.04% +0.16%
==========================================
Files 268 268
Lines 9460 9460
==========================================
+ Hits 8124 8140 +16
+ Misses 1336 1320 -16
|
@@ -18,15 +18,14 @@ | |||
using System.Diagnostics; | |||
using OpenTelemetry; | |||
|
|||
internal class MyFilteringProcessor : BaseProcessor<Activity> | |||
internal class MyFilteringProcessor : CompositeProcessor<Activity> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Purely from the reader's perspective - I guess folks would question "why would I need to derive from CompositeProcessor?".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 this is a good question, and I can't think of simple explanation to give users. The alternative to making SetParentProvider
public is problematic for similar reasons. I'd struggle to come up with a concise way to explain to users under what circumstances they need to be sure to call SetParentProvider
.
In either case the explanation is basically: if you're newing up a processor and you're not directly passing it to providerBuilder.AddProcessor()
(i.e., it's nested in another processor or something) then you gotta make sure that the parent provider gets set - which in turn ensures the processor has access to the configured resource... which may or may not be important depending on the processor
which then raises questions of why the parent provider needs to be set, why does it need access to a resource, and when is all of this important
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a good solution for this! Agree with @alanwest exposing SetParentProvider
feels wrong. I just added some XML comments explaining (or hinting at) what is going on in the example. That might help?
We could introduce a class to make it more self-explanatory like...
public class DelegatingProcessor<T> : CompositeProcessor<T>
{
public DelegatingProcessor(BaseProcessor<T> innerProcessor)
: base(new[] { innerProcessor ?? throw new ArgumentNullException(nameof(innerProcessor) })
{
}
}
...or...
public class DelegatingProcessor<T> : BaseProcessor<T>
{
public DelegatingProcessor(BaseProcessor<T> innerProcessor)
{
Guard.ThrowIfNull(innerProcessor);
this.InnerProcessor = innerProcessor;
}
protected BaseProcessor<T> InnerProcessor { get; }
public override void OnStart(T data)
{
this.InnerProcessor.OnStart(data);
}
public override void OnEnd(T data)
{
this.InnerProcessor.OnEnd(data);
}
internal override void SetParentProvider(BaseProvider parentProvider)
{
this.InnerProcessor.SetParentProvider(parentProvider);
}
protected override bool OnForceFlush(int timeoutMilliseconds)
{
return this.InnerProcessor.ForceFlush(timeoutMilliseconds);
}
protected override bool OnShutdown(int timeoutMilliseconds)
{
return this.InnerProcessor.Shutdown(timeoutMilliseconds);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.InnerProcessor.Dispose();
}
base.Dispose(disposing);
}
}
I doubt anyone will like that either, but it's an option 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving this is an example, I guess I can just close my eyes on it and click the approve button. 🤣
I guess there might be a solution to retrieve the "parent" processor's ParentProvider - based on callstack or context (should be reasonably performant since we only have to fetch it once when the ParentProvider is not yet set), but maybe it's just an overkill 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt anyone will like that either, but it's an option 🤣
Yea not yet excited about this idea. I do agree the naming offers a slight improvement, but I think it's worth sitting on a bit. Definitely think it's worth continuing this discussion in hopes of finding a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something about this problem kinda feels similar to middleware branching. Like the filter processor effectively introduces a branch in the pipeline. Something like
if (filterFunc(span)) {
// invoke the next process in the chain
} else {
// terminate the pipeline - maybe call a noop processor or something
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 looks good. At least the example works as intended now! Can't argue with progress.
* Added Jaeger Propagator to Opentelemetry.Extensions.Propagators (#3309) * Remove unnecessary bullet in CHANGELOG.md (#3352) Co-authored-by: Cijo Thomas <cithomas@microsoft.com> * Fix OTLP test (#3357) * Show that test is not doing what you might think it does * More asserts the merrier * Show this little test that it has potential * improve test coverage: InMemoryExporter & IDeferredMeterProviderBuilder (#3345) * [SDK] Circular buffer tweaks + cpu pressure test (#3349) * CircularBuffer tweaks and cpu pressure test. * Switch to Volatile.Read. * Perf tweaks. * Remove race check in debug after doing more testing. Co-authored-by: Cijo Thomas <cithomas@microsoft.com> * Fix event name logic + support null categoryname. (#3359) * In-memory Exporter: Buffer log scopes (#3360) * Buffer log scopes when using in-memory exporter. * CHANGELOG update. * Code review. * Tests. * CHANGELOG tweak. * SDK: Forward SetParentProvider to children of CompositeProcessor (#3368) * Examples: Fix ParentProvider not being set on MyFilteringProcessor (#3370) * Fix ParentProvider not being set on MyFilteringProcessor example. * Added XML comments. * Tweak. * Typo. * Logs: Add helper ctors & forceflush on OpenTelemetryLoggerProvider (#3364) * Add helper ctors & forceflush on OpenTelemetryLoggerProvider. * CHANGELOG update. * Unit tests. * Code review. * Code review. * Tweak. * SDK: Nullable annotations for base classes & batch + shims to enable compiler features (#3374) * Nullable annotations and shims for SDK base classes & batch. * Target updates. * Remove System.Collections.Immutable ref. * ApiCompat attribute exclusions. * ASPNETCore instrumentation to populate httpflavor tag (#3372) * improve test coverage: InMemoryExporter SnapshotMetric (#3344) * Fix AspNetCore metrics to use correct value for http.flavor (#3379) * Fix AspNetCore metrics to use correct value for http.flavor * word better * Logs: Add LogRecordData (#3378) * Add LogRecordData and hook up to LogRecord. * CHANGELOG update. * Code review. * Remove SetHttpFlavor from Http instrumentations (#3381) * Asp.Net Core trace instrumentation to populate http schema tag (#3392) * Try asp.net core tests with inproc server (#3394) * Dedupe IsPackable (#3398) * Remove AspNet and AspNet.TelemetryHttpModule instrumentation projects (#3397) * Handle possible exception when initializing the default service name (#3405) * HttpClient: Invoke Enrich when SocketException = HostNotFound (#3407) * Add & use ConfigureResource API. (#3307) Co-authored-by: tyler jago <ty_bone11@hotmail.com> Co-authored-by: Robert Pająk <rpajak@splunk.com> Co-authored-by: Cijo Thomas <cithomas@microsoft.com> Co-authored-by: Timothy Mothra <tilee@microsoft.com> Co-authored-by: Mikel Blanchard <mblanchard@macrosssoftware.com> Co-authored-by: Reiley Yang <reyang@microsoft.com> Co-authored-by: Utkarsh Umesan Pillai <utpilla@microsoft.com> Co-authored-by: Christian Neumüller <christian.neumueller@dynatrace.com>
Fixes #3241
Changes
Uses
CompositeProcessor<Activity>
so thatParentProvider
is correctly set on the inner processor for the filtering example.Requires #3368 (comment) to fully work.