question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dispose/Close/Finish does not wait trace to get flushed.

See original GitHub issue

Describe 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:

  1. Create simple .NET Console application
  2. Install Datadog.Trace NUGET version 1.18
  3. 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
        }
  1. Check datadog APM traces: there is no manual.fastshutdown trace in it.
  2. uncomment commented line and run again
  3. 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:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kehigginbothamcommented, Jun 30, 2021

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.

If Tracer.Instance.ActiveScope IsNot Nothing
    Tracer.Instance.ActiveScope.Dispose()
End If
0reactions
kevingossecommented, Sep 30, 2021

I am closing this issue.

For future reference:

  • When the process exits gracefully, the tracer should be able to flush the pending traces. If not, this is the bug, please open a issue to report it
  • When the process is about to exit brutally (threads being aborted for instance), you can first call Tracer.Instance.ForceFlushAsync() to avoid losing the pending traces
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found