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

Skip to content

Commit 4b00a90

Browse files
committed
add datadog tracing to http handlers
1 parent 8c0f403 commit 4b00a90

File tree

4 files changed

+317
-3
lines changed

4 files changed

+317
-3
lines changed

cli/start.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +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"
3940
)
4041

4142
func start() *cobra.Command {
@@ -56,12 +57,15 @@ func start() *cobra.Command {
5657
root := &cobra.Command{
5758
Use: "start",
5859
RunE: func(cmd *cobra.Command, args []string) error {
60+
tracer.Start()
61+
defer tracer.Stop()
62+
5963
printLogo(cmd)
6064
if postgresURL == "" {
6165
// Default to the environment variable!
6266
postgresURL = os.Getenv("CODER_PG_CONNECTION_URL")
6367
}
64-
68+
logger := slog.Make(sloghuman.Sink(os.Stderr))
6569
listener, err := net.Listen("tcp", address)
6670
if err != nil {
6771
return xerrors.Errorf("listen %q: %w", address, err)

coderd/coderd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +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"
1718
)
1819

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

4243
r := chi.NewRouter()
4344
r.Route("/api/v2", func(r chi.Router) {
45+
r.Use(chitrace.Middleware())
4446
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
4547
httpapi.Write(w, http.StatusOK, httpapi.Response{
4648
Message: "👋",

go.mod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ replace github.com/urfave/cli/v2 => github.com/ipostelnik/cli/v2 v2.3.1-0.202103
2525

2626
replace github.com/rivo/tview => github.com/kylecarbs/tview v0.0.0-20220309202238-8464256e10a1
2727

28+
// glog has a single goroutine leak on start
29+
replace github.com/golang/glog => github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1
30+
2831
require (
2932
cdr.dev/slog v1.4.1
3033
cloud.google.com/go/compute v1.5.0
@@ -86,6 +89,21 @@ require (
8689
storj.io/drpc v0.0.30
8790
)
8891

92+
require (
93+
github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583 // indirect
94+
github.com/DataDog/datadog-go v4.8.2+incompatible // indirect
95+
github.com/DataDog/datadog-go/v5 v5.0.2 // indirect
96+
github.com/DataDog/sketches-go v1.0.0 // indirect
97+
github.com/dgraph-io/ristretto v0.1.0 // indirect
98+
github.com/dustin/go-humanize v1.0.0 // indirect
99+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
100+
github.com/josharian/intern v1.0.0 // indirect
101+
github.com/mailru/easyjson v0.7.7 // indirect
102+
github.com/philhofer/fwd v1.1.1 // indirect
103+
github.com/tinylib/msgp v1.1.2 // indirect
104+
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
105+
)
106+
89107
require (
90108
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
91109
github.com/BurntSushi/toml v1.0.0 // indirect
@@ -220,6 +238,7 @@ require (
220238
google.golang.org/appengine v1.6.7 // indirect
221239
google.golang.org/genproto v0.0.0-20220310185008-1973136f34c6 // indirect
222240
google.golang.org/grpc v1.45.0 // indirect
241+
gopkg.in/DataDog/dd-trace-go.v1 v1.37.0
223242
gopkg.in/coreos/go-oidc.v2 v2.2.1 // indirect
224243
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
225244
gopkg.in/square/go-jose.v2 v2.6.0 // indirect

0 commit comments

Comments
 (0)