-
Notifications
You must be signed in to change notification settings - Fork 73
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
Instrumentation inside an IEnumerable #106
Comments
Perhaps something like a using (var scope = FirstPart())
{
for (int i = 0; i < 10; i++)
{
// FirstPart will be leaked out of right here
using (scope.YieldReturn())
{
yield return i;
}
}
} where Note that as a pure extension method this would not be possible due to #95 related issues - it is impossible today for us to (implementation-agnostic) remove an Problems with proposal: A single span would potentially then have multiple parents (which most of the tracing systems today do not handle first-class, at least in their visualization). Possible alternative: A purely extension method that creates a NEW span on each resumption of the enumerable. The implementation of this would almost be an anti-Scope, where at the // This line captures the BuildSpan information to be able to rebuild spans for each enumeration, and immediately starts one (span1)
using (IYieldReadyScope yieldReadyScope = GlobalTracer.Instance.BuildSpan("foo").StartYieldReadyScope())
{
for (int i = 0; i < 10; i ++)
{
// This line closes the previous span (e.g. span1)
using (yieldReadyScope.Yielding())
{
yield return i;
} // This line opens a new span based on the BuildSpan information previously captured, e.g. span2
}
} // This line closes the last span created by the yieldReadyScope Due to how prone this is (in any solution) to misuse, we may want to make a tracing VS Analyzer to detect such cases. |
Interesting scenario. It sounds "like a feature" to me though as that's how C# works in that case - when you While the tracing tree might be unexpected at first sight, I wouldn't say it's inconsistent as everything should get closed properly, doesn't it? You could obviously just avoid using "yield" but I guess there's a reason for why you use it. Does it give you better performance? I've never benchmarked that. |
…match the mental model made by the IEnumerable `yield` syntax in CSharp. Addresses opentracing/opentracing-csharp#106 via an extension
Problem statement:
using
syntax inside ayield return
IEnumerable
results in confusing and inconsistent tracesAction: Clarify the usage via documentation or utility methods that make such authoring more convenient
Expectation:
When tracing inside an IEnumerable's production code and the consumer/processor code...
My Trace should look like
DoStuff
DoStuff > EnumerateItemFirstPart
DoStuff > ProcessItem
DoStuff > EnumerateItemSecondPart
DoStuff > ProcessItem
Reality:
My Trace would look like
DoStuff
DoStuff > EnumerateItemFirstPart
DoStuff > EnumerateItemFirstPart > ProcessItem
DoStuff > EnumerateItemSecondPart
DoStuff > EnumerateItemSecondPart > ProcessItem
Demonstrate the problem:
The text was updated successfully, but these errors were encountered: