Created
May 16, 2025 09:20
-
-
Save ThatRendle/f2c8a8d4a8e2bf3692c76784d0a214c4 to your computer and use it in GitHub Desktop.
Start an Activity without Parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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