Scenario
I have followed this tutorial and created azure function v3
in net core 3.1
to monitor my web application. U used Visual Studio instead of developing it in the portal.
Problem
Unfortunately i received System.NullReferenceException: Object reference not set to an instance of an object.System.Diagnostics.Activity.Current.get returned null.
in line:
availability.Context.Operation.ParentId = Activity.Current.SpanId.ToString();
How to fix that?
Hmmm... I think the tutorial may have some error on the code, and we can comment the two lines where error took place.
This doc said :
Activities should be created by calling the constructor, configured as necessary, and then started with the Start method, which maintains parent-child relationships for the activities and sets Activity.Current.
and this is why availability.Context.Operation.ParentId = Activity.Current.SpanId.ToString();
burst an error. And focus on this line-code,
does this line make sense? So in my test, I made this line and the line behind it commented, and code executed well.