Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ce5328

Browse files
committed
Move into generic coder/tracer package
1 parent 8d0f107 commit 9ce5328

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

cli/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/coder/coder/provisionerd"
3737
"github.com/coder/coder/provisionersdk"
3838
"github.com/coder/coder/provisionersdk/proto"
39-
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
39+
"github.com/coder/coder/tracer"
4040
)
4141

4242
func start() *cobra.Command {

coderd/coderd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/coder/coder/httpapi"
1515
"github.com/coder/coder/httpmw"
1616
"github.com/coder/coder/site"
17-
chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5"
17+
"github.com/coder/coder/tracer"
1818
)
1919

2020
// Options are requires parameters for Coder to start.
@@ -42,7 +42,7 @@ func New(options *Options) (http.Handler, func()) {
4242

4343
r := chi.NewRouter()
4444
r.Route("/api/v2", func(r chi.Router) {
45-
r.Use(chitrace.Middleware())
45+
r.Use(tracer.Middleware())
4646
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
4747
httpapi.Write(w, http.StatusOK, httpapi.Response{
4848
Message: "👋",

tracer/tracer.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Package tracer provides application tracing and performance monitoring utilities.
2+
package tracer
3+
4+
import (
5+
"net/http"
6+
7+
chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5"
8+
ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
9+
)
10+
11+
// Starts the global tracer.
12+
// Call as early as possible in the application to capture the most data.
13+
// You must call Stop() to ensure all spans are properly flushed before exit.
14+
//
15+
// Common Usage:
16+
//
17+
// tracer.Start()
18+
// defer tracer.Stop()
19+
//
20+
func Start() {
21+
ddtracer.Start()
22+
}
23+
24+
// Stops the global tracer.
25+
// Should be called at the end of the program to flush the remaining traces.
26+
func Stop() {
27+
ddtracer.Stop()
28+
}
29+
30+
// Middleware will wrap a trace span around the next http.Handler.
31+
func Middleware() func(next http.Handler) http.Handler {
32+
return chitrace.Middleware()
33+
}

0 commit comments

Comments
 (0)