# How to flush APM transaction before shutting down application (.net 6 / console / Lambda)

**URL:** https://discuss.elastic.co/t/how-to-flush-apm-transaction-before-shutting-down-application-net-6-console-lambda/317748
**Category:** APM
**Tags:** dotnet, aws-lambda
**Created:** [October 30, 2022, 8:52am UTC](https://discuss.elastic.co/t/how-to-flush-apm-transaction-before-shutting-down-application-net-6-console-lambda/317748 "2022-10-30T08:52:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jimmie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimmie/32/112685_2.png) [@jimmie](https://discuss.elastic.co/u/jimmie)
#### Post date: [October 30, 2022, 8:52am UTC](https://discuss.elastic.co/t/how-to-flush-apm-transaction-before-shutting-down-application-net-6-console-lambda/317748/1 "2022-10-30T08:52:05Z")

</div>

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](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.

```auto
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)**:

```auto
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?

---

<div class="post-metadata">

### Author: ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)
#### Post date: [October 30, 2022, 9:06am UTC](https://discuss.elastic.co/t/how-to-flush-apm-transaction-before-shutting-down-application-net-6-console-lambda/317748/2 "2022-10-30T09:06:12Z")

</div>

Hi @jimmie,

this is a known limitation - we plan to address this in a future release.

Here is a GitHub issue about it: [Agent API to flush all the queued events · Issue #288 · elastic/apm-agent-dotnet · GitHub](https://github.com/elastic/apm-agent-dotnet/issues/288) (there are some other related issues - including ones specifically for lambda - as well in the repo; but this comes down to the missing feature and the linked issue).

---

<div class="post-metadata">

### Author: ![jimmie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimmie/32/112685_2.png) [@jimmie](https://discuss.elastic.co/u/jimmie)
#### Post date: [October 30, 2022, 9:34am UTC](https://discuss.elastic.co/t/how-to-flush-apm-transaction-before-shutting-down-application-net-6-console-lambda/317748/3 "2022-10-30T09:34:37Z")

</div>

Oh, okey. I thought it was me missing something. Thanks for the quick feedback @GregKalapos

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 20, 2022, 5:35am UTC](https://discuss.elastic.co/t/how-to-flush-apm-transaction-before-shutting-down-application-net-6-console-lambda/317748/4 "2022-11-20T05:35:10Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
