Skip to content

Child Activity outliving its parent corrupts Activity.Current #101775

Open

Description

According to https://github.com/open-telemetry/opentelemetry-specification/blob/v1.31.0/specification/trace/api.md#end, child spans are allowed to outlive their parents:

End MUST NOT have any effects on child spans. Those may still be running and can be ended later.

However in .NET such activities may lead to weird behavior resulting in Activity.Current becoming an activity that has been already stopped, leaving devs without an option to leave the corrupted state:

Activity a = new Activity("a").Start();
Activity b = new Activity("b").Start();
Activity c = new Activity("c").Start();

b.Stop();
Console.WriteLine(Activity.Current!.OperationName); // Prints "a"
c.Stop();
Console.WriteLine(Activity.Current!.OperationName); // Prints "b" -- already stopped!
b.Stop(); // Does nothing
Console.WriteLine(Activity.Current!.OperationName); // Still prints "b"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions