elastic / apm-agent-dotnet

https://www.elastic.co/guide/en/apm/agent/dotnet/current/index.html
Apache License 2.0
585 stars 208 forks source link

[BUG] NullReferenceException in PayloadSenderV2 if APM is disabled #2433

Closed th3ragex closed 2 months ago

th3ragex commented 2 months ago

APM Agent version

1.28.5

Describe the bug

While debugging NullReferenceExceptions were observed in PayloadSenderV2. The APM was disabled via: "ELASTIC_APM_ENABLED": "false",

https://github.com/elastic/apm-agent-dotnet/blob/9a99a2e75d2bf875730d3b0d4ffeccf5e8ae26ce/src/Elastic.Apm/Report/PayloadSenderV2.cs#L184-L185

_logger was null, NRE was raised within Debug method.

Observed root causes:

1) Call of extension methods on null object 2) Execution of internal logic even though the object was not fully initialized https://github.com/elastic/apm-agent-dotnet/blob/9a99a2e75d2bf875730d3b0d4ffeccf5e8ae26ce/src/Elastic.Apm/Report/PayloadSenderV2.cs#L75-L77

Expected behavior

1) Do not call Extension methods on null 2) Do not call EnqueueEventInternal if APM is disabled

Mpdreamz commented 2 months ago

Thanks for reporting this rather nasty bug @th3ragex 🙏 , we will be pushing a new release with a fix shortly.

th3ragex commented 2 months ago

@Mpdreamz Thank you for your fast and continuous support on this library! 🙏