Skip to content

Commit

Permalink
Add example listening for sigterm to docs (APMSP-15340) (#2978)
Browse files Browse the repository at this point in the history
Co-authored-by: Dario Castañé <dario.castane@datadoghq.com>
  • Loading branch information
ajgajg1134 and darccio authored Nov 27, 2024
1 parent ad7ae5f commit 0d0d008
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ddtrace/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"fmt"
"log"
"os"
"os/signal"
"syscall"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
Expand All @@ -27,6 +29,15 @@ func Example_datadog() {
tracer.Start(tracer.WithAgentAddr("host:port"))
defer tracer.Stop()

// If you expect your application to be shutdown via SIGTERM (e.g. a container in k8s)
// You likely want to listen for that signal and stop the tracer to ensure no data is lost
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM)
go func() {
<-sigChan
tracer.Stop()
}()

// Start a root span.
span := tracer.StartSpan("get.data")
defer span.Finish()
Expand Down

0 comments on commit 0d0d008

Please sign in to comment.