Kibana version: N/A
Elasticsearch version: N/A
APM Server version: 7.15.0
APM Agent language and version: c# .Net Core 3.1, v1.11.1
Browser version: N/A
Original install method (e.g. download page, yum, deb, from source, etc.) and version: Nuget package
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
Hi,
if Agent.Tracer.CaptureException(exception) gets called and the agent configuration 'enabled' is set to false, the method throws a System.NullReferenceException:
System.NullReferenceException: Object reference not set to an instance of an object.
at Elastic.Apm.BackendComm.BackendCommComponentBase.ThrowIfDisposed()
at Elastic.Apm.Report.PayloadSenderV2.EnqueueEvent(Object eventObj, String dbgEventKind)
at Elastic.Apm.Report.PayloadSenderV2.QueueError(IError error)
at Elastic.Apm.Model.ExecutionSegmentCommon.CaptureException(Exception exception, IApmLogger logger, IPayloadSender payloadSender, IExecutionSegment executionSegment, IConfigurationReader configurationReader, Transaction transaction, IApmServerInfo apmServerInfo, String culprit, Boolean isHandled, String parentId, Dictionary`2 labels)
at Elastic.Apm.Api.Tracer.CaptureException(Exception exception, String culprit, Boolean isHandled, String parentId, Dictionary`2 labels)
at ConsoleApp1.Program.Main(String[] args) in .\ConsoleApp1\ConsoleApp1\Program.cs:line 13
it looks like 'BackendCommComponentBase' aborts initialization of the '_disposableHelper' if 'enabled' is set to false.
// BackendCommComponentBase.cs Line 39
if (!_isEnabled)
{
_logger.Debug()?.Log("Disabled - exiting without initializing any members used by work loop");
return;
}
CancellationTokenSource = new CancellationTokenSource();
_disposableHelper = new DisposableHelper();
However, later if Agent.Tracer.CaptureException gets called 'PayloadSenderV2.EnqueueEvent' calls 'ThrowIfDisposed()' which checks '_disposableHelper.HasStarted' and '_disposableHelper' is null at this point because it was not initialized.
// BackendCommComponentBase.cs Line 131
protected void ThrowIfDisposed()
{
if (_disposableHelper.HasStarted) throw new ObjectDisposedException( /* objectName: */ _dbgName);
}
Steps to reproduce:
- Create .Net Core 3.1 console app
- Install Nuget 'Elastic.Apm.AspNetCore'
- Copy code:
static void Main(string[] args) { Console.WriteLine("Hello World!"); Environment.SetEnvironmentVariable("ELASTIC_APM_ENABLED", "false"); Agent.Tracer.CaptureException(new Exception()); }
Provide logs and/or server output (if relevant):
System.NullReferenceException: Object reference not set to an instance of an object.
at Elastic.Apm.BackendComm.BackendCommComponentBase.ThrowIfDisposed()
at Elastic.Apm.Report.PayloadSenderV2.EnqueueEvent(Object eventObj, String dbgEventKind)
at Elastic.Apm.Report.PayloadSenderV2.QueueError(IError error)
at Elastic.Apm.Model.ExecutionSegmentCommon.CaptureException(Exception exception, IApmLogger logger, IPayloadSender payloadSender, IExecutionSegment executionSegment, IConfigurationReader configurationReader, Transaction transaction, IApmServerInfo apmServerInfo, String culprit, Boolean isHandled, String parentId, Dictionary`2 labels)
at Elastic.Apm.Api.Tracer.CaptureException(Exception exception, String culprit, Boolean isHandled, String parentId, Dictionary`2 labels)
at ConsoleApp1.Program.Main(String[] args) in .\ConsoleApp1\ConsoleApp1\Program.cs:line 13