PayloadSenderV2 NullReferenceException when stopping a dotnet core IHostedService background service

Kibana version:
7.13.4

Elasticsearch version:
7.13.4

APM Agent language and version:
C#, 1.11.1

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,

I have a .net core(3.1) application which essentially is a background service running as a windows service. I'm implementing the "BackgroundService" from .net similar to the example in the following link: Background tasks with hosted services in ASP.NET Core | Microsoft Docs

I'm configuring the apm agent by using ".UseAllElasticApm()" on the hosted service and "UseElasticApm" on the Redis connection that I have.

My issue is that I'm getting an exception when my service tries stop by calling
await base.StopAsync(cancellationToken);

The error is: "WARN Elastic.Apm {PayloadSenderV2} Exception during execution of the filter on transaction
System.NullReferenceException: Object reference not set to an instance of an object.
at Elastic.Apm.Filters.ErrorContextSanitizerFilter.Filter(IError error)
at Elastic.Apm.Report.PayloadSenderV2.TryExecuteFilter[T](List`1 filters, T item)"

Steps to reproduce:

  1. Run a dotnet background service
  2. Call base.StopAsync()

Errors in browser console (if relevant):

Provide logs and/or server output (if relevant):


Hi @diosifidis. The following error

I believe is the same issue as

This has been addressed in

and will be in the next release.