Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Instrumentation inside an IEnumerable #106

@ndrwrbgs

Description

@ndrwrbgs

Problem statement: using syntax inside a yield return IEnumerable results in confusing and inconsistent traces

Action: 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:

class DemonstrateTheProblem
{
    public static IEnumerable<int> ShowIt()
    {
        using (StartFirstPartTrace())
        {
            for (int i = 0; i < 10; i++)
            {
                // StartFirstPartTrace will be leaked out of right here - e.g. the code consuming the IEnumerable will say that it is inside StartFirstPartTrace()
                yield return i;
            }
        }

        // Including a SecondPart to negate the obvious solution of wrapping the IEnumerator
        using (StartSecondPartTrace())
        {
            for (int i = 0; i < 10; i++)
            {
                // StartSecondPartTrace will be leaked out of right here - e.g. the code consuming (a foreach for instance) will now 
                yield return i;
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions