I'm using Elastic APM on my .NET 6 API which works perfectly fine.
I'm trying to get it roll on my console and AWS Lamdba deploys as well.
I moved out the important pieces to a separate project to easier debug and show my setup here; https://github.com/privjimmie/ApmDebug
The bottom line is that I can't figure out how to get the APM transactions to be sent out / flushed before the app is shutdown.
warn: Elastic.Apm[0] {PayloadSenderV2} Cancellation requested. Following events were not transferred successfully to the server xxx
(Full log below)
Kibana version: 8.4.3
Elasticsearch version: 8.4.3
APM Server version: 8.4.3
APM Agent language and version: Elastic.Apm.NetCoreAll v 1.18.0
Provide logs and/or server output (if relevant):
info: Elastic.Apm[0]
{AbstractConfigurationReader (MicrosoftExtensionsConfig)} The agent was started without a service version. The service version will be automatically discovered.
info: Elastic.Apm[0]
{AbstractConfigurationReader (MicrosoftExtensionsConfig)} The agent was started without a service version. The automatically discovered service version is 1.0.0
info: Elastic.Apm[0]
{MetricsCollector} Collecting metrics in 30000 milliseconds interval
APM.MaxBatchEventCount: 1
APM.FlushInterval: 00:00:01
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:\data\Repositories\Private\ApmDebug\bin\Debug\net6.0
Simulate work here for 5 seconds
info: Elastic.Apm[0]
{CentralConfigurationFetcher} Updating ConfigurationStore. New central configuration: [ETag: `"-"']{}
info: Elastic.Apm[0]
{ConfigurationStore} Replaced current snapshot. Old: local. New: local + central (ETag: `"-"').
Call StopApplication()
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
StopAsync. Return CompletedTask
warn: Elastic.Apm[0]
{PayloadSenderV2} Cancellation requested. Following events were not transferred successfully to the server (https://xxxxxxxxxxxxxxxx.apm.eu-west-1.aws.cloud.es.io/):
Transaction{Id: 360515c4795a0e60, TraceId: 19ccacb77dd51c62819fb7cc4402e057, ParentId: null, Name: TestName, Type: exec, Outcome: Success, IsSampled: True}
Exiting..
How can I flush the transactions to elastic apm server before shutting down the app?