Skip to content

Instantly share code, notes, and snippets.

@ThatRendle
Created May 16, 2025 09:20
Show Gist options
  • Save ThatRendle/f2c8a8d4a8e2bf3692c76784d0a214c4 to your computer and use it in GitHub Desktop.
Save ThatRendle/f2c8a8d4a8e2bf3692c76784d0a214c4 to your computer and use it in GitHub Desktop.
Start an Activity without Parent
class A
{
public void Foo()
{
// Hold onto current activity, clear current to prevent automatic parenting
var current = Activity.Current;
Activity.Current = null;
try
{
using var activity = Telemetry.ActivitySource.StartActivity("bar");
}
finally
{
// put the previous activity back
Activity.Current = current;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment