Dispose/Close/Finish does not wait trace to get flushed.
See original GitHub issueDescribe the bug When calling on of the methods Tracer.Dispose or Tracer.Close or Span.Finish the expected behavior is data to be sent to agent. Span.Finish says in its documentation: “Record the end time of the span and flushes it to the backend. After the span has been finished all modifications will be ignored”.
To Reproduce Steps to reproduce the behavior:
- Create simple .NET Console application
- Install Datadog.Trace NUGET version 1.18
- Write code to trace a span and don’t delay application closing and run it:
public static void Main(string[] args)
{
using (Scope scope = Tracer.Instance.StartActive("manual.fastshutdown"))
{
scope.Span.Type = SpanTypes.Custom;
}
//Thread.Sleep(10000); //uncomment this line to get trace into datadog
}
- Check datadog APM traces: there is no manual.fastshutdown trace in it.
- uncomment commented line and run again
- Check that trace manual.fastshutdown appeared in datadog
Runtime environment (please complete the following information):
- Instrumentation mode: NuGet package
- Tracer version: 1.18
- OS: Windows
- CLR: .NET Framework 4.8
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
SQLTRACE_BUFFER_FLUSH
Description. This wait accumulates when a trace (commonly run as Profiler) is waiting to be flushed to disk. SQL Server by default has...
Read more >Trace.Flush Method (System.Diagnostics)
Setting AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be...
Read more >CoreSight Program Flow Trace Architecture Specification
The PTM acknowledges the trace flush only after it has output all of the flushed data. If you have enabled timestamping, the PTM...
Read more >Flushing events - SDKs /
You can manually call flush to send events immediately without waiting for the next interval. Most customers do not need to use the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have discovered a viable work-around for my use case.
Traces are flushed if the flow of control exits the Scope’s scope gracefully. In the event of an ApplicationExit or other event initiating shutdown, the active Scope is not flushed. By adding the (VB.NET) code below in my ApplicationExit handler, I am able to force the active Scope to flush.
I am closing this issue.
For future reference:
Tracer.Instance.ForceFlushAsync()
to avoid losing the pending traces