how does the first Activity instance from Activity.Current get created in asp.net web api?

28 views Asked by At

if I try to get the activity instance by calling Activity.Current in a console project, I get a null

class Program
{
    static void Main(string[] args)
    {
        var activity = Activity.Current;  // activity is null
        // ...
    }
}

and if I call it from a web api project then it is not null

[ApiController]
public class PingController : ControllerBase
{

    [HttpGet("ping")]
    public async Task<IActionResult> PingAsync()
    {
        var activity = Activity.Current;  // activity is NOT null
        // ...
    }  
}

so asp.net web api framework must create an Activity instance when it recevies the http request, but how does it create it? could you show me the asp.net source code (https://source.dot.net/) that which class create a Activity instance and get this instance to Activity.Current?

0

There are 0 answers