Greetings All !
I have an existing Windows Desktop C# .NET application that has been using Elastic.Apm for .Net library version 1.25.3 on .NET version 4.6.1 for several years now. I am working on the small project of updating everything to .NET version 4.8.1... which now has me using the Elastic.Apm for .Net library version 1.32.2.
This upgrade has somehow broken my existing code.
The only Elastic APM related initialization code I have is:
Environment.SetEnvironmentVariable("ELASTIC_APM_SERVER_URLS", SitMan.Config.Paths.APMServerURL);
Environment.SetEnvironmentVariable("ELASTIC_APM_SERVICE_NAME", <my application name> );
Environment.SetEnvironmentVariable("ELASTIC_APM_SERVICE_VERSION", Application.ProductVersion);
Environment.SetEnvironmentVariable("ELASTIC_APM_ENVIRONMENT", SelectedLaunchEnvironment.Name);
Agent.Setup(new AgentComponents(logger: new ApmLoggerBridge(logger)));
And then, what happens is, in the 70+ functions throughout my app where I want to apply APM tracing, I start with the lines:
ITransaction transaction = null;
ISpan span = null;
Dictionary<string, string> labels = new Dictionary<string, string>()
{
{ "request", putQuery },
};
And then I call a function:
Common.BeginAPMTransOrSpan(ref transaction, ref span, $"{action} Alarm Suppression Rule", labels);
This function starts with:
public static void BeginAPMTransOrSpan(ref ITransaction transaction, ref ISpan span, string name, Dictionary<string, string> labels = null, string type = null, string subtype = null)
{
if (!Application.Config.Integration.ElasticAPM)
{
transaction = null;
span = null;
return;
}
transaction = Agent.Tracer.CurrentTransaction;
span = null;
if (transaction == null)
{
(That first clause is just designed to return null if I have things configured so that we don't want to use Elastic APM at all throughout the application.)
My issue appears to be that when we get to that line:
transaction = Agent.Tracer.CurrentTransaction;
We throw an exception:
System.NullReferenceException: Object reference not set to an instance of an object.
Apparently, we throw it because .Tracer is null.
I put a bit of debugging code immediately after that initialization code. It shows that Agent.isConfigured is true, but Agent.Tracer is null.
What do I need to change here? Why is .Tracer not initialized properly following this upgrade?
Thanks!