Skip to content

Commit 12485fc

Browse files
committed
feat(cli): add DataDog Go tracer
1 parent 9ceba20 commit 12485fc

File tree

11 files changed

+110
-2
lines changed

11 files changed

+110
-2
lines changed

cli/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,7 @@ func ConfigureTraceProvider(
21052105
sdkTracerProvider, _closeTracing, err := tracing.TracerProvider(ctx, "coderd", tracing.TracerOpts{
21062106
Default: cfg.Trace.Enable.Value(),
21072107
Coder: shouldCoderTrace,
2108+
DataDog: cfg.Trace.DataDog.Value(),
21082109
Honeycomb: cfg.Trace.HoneycombAPIKey.String(),
21092110
})
21102111
if err != nil {

cli/testdata/server-config.yaml.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ introspection:
201201
# which may incur significant costs.
202202
# (default: <unset>, type: bool)
203203
captureLogs: false
204+
# Enables sending Go runtime traces to the local DataDog agent.
205+
# (default: false, type: bool)
206+
dataDog: false
204207
logging:
205208
# Output debug-level logs.
206209
# (default: <unset>, type: bool)

coderd/apidoc/docs.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/tracing/exporter.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
"go.opentelemetry.io/otel/sdk/resource"
1414
sdktrace "go.opentelemetry.io/otel/sdk/trace"
1515
semconv "go.opentelemetry.io/otel/semconv/v1.14.0"
16+
ddotel "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry"
17+
ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
18+
ddprofiler "gopkg.in/DataDog/dd-trace-go.v1/profiler"
19+
1620
"golang.org/x/xerrors"
1721
"google.golang.org/grpc/credentials"
1822
)
@@ -25,6 +29,8 @@ type TracerOpts struct {
2529
// Coder exports traces to Coder's public tracing ingest service and is used
2630
// to improve the product. It is disabled when opting out of telemetry.
2731
Coder bool
32+
// DataDog exports traces and profiles to the local DataDog daemon.
33+
DataDog bool
2834
// Exports traces to Honeycomb.io with the provided API key.
2935
Honeycomb string
3036
}
@@ -45,6 +51,35 @@ func TracerProvider(ctx context.Context, service string, opts TracerOpts) (*sdkt
4551
closers = []func(context.Context) error{}
4652
)
4753

54+
if opts.DataDog {
55+
// See more:
56+
// https://docs.datadoghq.com/tracing/metrics/runtime_metrics/go/
57+
dd := ddotel.NewTracerProvider(ddtracer.WithRuntimeMetrics())
58+
closers = append(closers, func(_ context.Context) error {
59+
// For some reason, this doesn't appear to actually wind down
60+
// the goroutines.
61+
return dd.Shutdown()
62+
})
63+
64+
// See https://docs.datadoghq.com/profiler/enabling/go/
65+
_ = ddprofiler.Start(
66+
ddprofiler.WithService("coderd"),
67+
ddprofiler.WithProfileTypes(
68+
ddprofiler.CPUProfile,
69+
ddprofiler.HeapProfile,
70+
ddprofiler.GoroutineProfile,
71+
72+
// In the future, we may want to enable:
73+
// ddprofiler.BlockProfile,
74+
// ddprofiler.MutexProfile,
75+
),
76+
)
77+
closers = append(closers, func(_ context.Context) error {
78+
ddprofiler.Stop()
79+
return nil
80+
})
81+
}
82+
4883
if opts.Default {
4984
exporter, err := DefaultExporter(ctx)
5085
if err != nil {

codersdk/deployment.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ type TraceConfig struct {
310310
Enable clibase.Bool `json:"enable" typescript:",notnull"`
311311
HoneycombAPIKey clibase.String `json:"honeycomb_api_key" typescript:",notnull"`
312312
CaptureLogs clibase.Bool `json:"capture_logs" typescript:",notnull"`
313+
DataDog clibase.Bool `json:"data_dog" typescript:",notnull"`
313314
}
314315

315316
type GitAuthConfig struct {
@@ -1237,6 +1238,22 @@ when required by your organization's security policy.`,
12371238
YAML: "captureLogs",
12381239
Annotations: clibase.Annotations{}.Mark(annotationExternalProxies, "true"),
12391240
},
1241+
{
1242+
Name: "Send Go runtime traces to DataDog",
1243+
Description: "Enables sending Go runtime traces to the local DataDog agent.",
1244+
Flag: "trace-datadog",
1245+
Env: "CODER_TRACE_DATADOG",
1246+
Value: &c.Trace.DataDog,
1247+
Group: &deploymentGroupIntrospectionTracing,
1248+
YAML: "dataDog",
1249+
// Hidden until an external user asks for it. For the time being,
1250+
// it's used to detect leaks in dogfood.
1251+
Hidden: true,
1252+
// Default is false because datadog creates a bunch of goroutines that
1253+
// don't get cleaned up and trip the leak detector.
1254+
Default: "false",
1255+
Annotations: clibase.Annotations{}.Mark(annotationExternalProxies, "true"),
1256+
},
12401257
// Provisioner settings
12411258
{
12421259
Name: "Provisioner Daemons",

docs/api/general.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/schemas.md

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ require (
202202
cloud.google.com/go/longrunning v0.5.1 // indirect
203203
filippo.io/edwards25519 v1.0.0 // indirect
204204
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
205+
github.com/DataDog/appsec-internal-go v1.0.0 // indirect
206+
github.com/DataDog/datadog-agent/pkg/obfuscate v0.45.0-rc.1 // indirect
207+
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.48.0-devel.0.20230725154044-2549ba9058df // indirect
208+
github.com/DataDog/datadog-go/v5 v5.1.1 // indirect
209+
github.com/DataDog/go-libddwaf v1.4.2 // indirect
210+
github.com/DataDog/go-tuf v1.0.1-0.5.2 // indirect
211+
github.com/DataDog/gostackparse v0.5.0 // indirect
212+
github.com/DataDog/sketches-go v1.2.1 // indirect
205213
github.com/KyleBanks/depth v1.2.1 // indirect
206214
github.com/Microsoft/go-winio v0.6.1 // indirect
207215
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
@@ -247,6 +255,8 @@ require (
247255
github.com/docker/docker v23.0.5+incompatible // indirect
248256
github.com/docker/go-connections v0.4.0 // indirect
249257
github.com/docker/go-units v0.5.0 // indirect
258+
github.com/dustin/go-humanize v1.0.1 // indirect
259+
github.com/ebitengine/purego v0.5.0-alpha // indirect
250260
github.com/elastic/go-windows v1.0.0 // indirect
251261
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
252262
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
@@ -276,6 +286,7 @@ require (
276286
github.com/google/flatbuffers v23.1.21+incompatible // indirect
277287
github.com/google/go-querystring v1.1.0 // indirect
278288
github.com/google/nftables v0.1.1-0.20230115205135-9aa6fdf5a28c // indirect
289+
github.com/google/pprof v0.0.0-20230509042627-b1315fad0c5a // indirect
279290
github.com/google/s2a-go v0.1.5 // indirect
280291
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
281292
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
@@ -335,16 +346,21 @@ require (
335346
github.com/opencontainers/go-digest v1.0.0 // indirect
336347
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
337348
github.com/opencontainers/runc v1.1.5 // indirect
349+
github.com/outcaste-io/ristretto v0.2.1 // indirect
338350
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
351+
github.com/philhofer/fwd v1.1.2 // indirect
339352
github.com/pierrec/lz4/v4 v4.1.17 // indirect
340353
github.com/pion/transport v0.14.1 // indirect
341354
github.com/pkg/errors v0.9.1 // indirect
342355
github.com/pmezard/go-difflib v1.0.0 // indirect
343356
github.com/prometheus/procfs v0.10.1 // indirect
344357
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
358+
github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052 // indirect
345359
github.com/rivo/uniseg v0.4.4 // indirect
346360
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
361+
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
347362
github.com/sirupsen/logrus v1.9.3 // indirect
363+
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 // indirect
348364
github.com/spf13/cast v1.5.1 // indirect
349365
github.com/swaggo/files/v2 v2.0.0 // indirect
350366
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
@@ -357,13 +373,14 @@ require (
357373
github.com/tcnksm/go-httpstat v0.2.0 // indirect
358374
github.com/tdewolff/parse/v2 v2.6.6 // indirect
359375
github.com/tdewolff/test v1.0.9 // indirect
376+
github.com/tinylib/msgp v1.1.8 // indirect
360377
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 // indirect
361378
github.com/ulikunitz/xz v0.5.11 // indirect
362379
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
363380
github.com/vishvananda/netns v0.0.4 // indirect
364381
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
365382
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
366-
github.com/vmihailenco/tagparser v0.1.1 // indirect
383+
github.com/vmihailenco/tagparser v0.1.2 // indirect
367384
github.com/x448/float16 v0.8.4 // indirect
368385
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
369386
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
@@ -378,15 +395,19 @@ require (
378395
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
379396
go.opentelemetry.io/otel/metric v1.16.0 // indirect
380397
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
398+
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
381399
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
400+
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
382401
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
383402
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230215201556-9c5414ab4bde // indirect
384403
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
385404
google.golang.org/appengine v1.6.7 // indirect
386405
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
387406
google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 // indirect
388407
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
408+
gopkg.in/DataDog/dd-trace-go.v1 v1.54.0 // indirect
389409
gopkg.in/yaml.v2 v2.4.0 // indirect
390410
howett.net/plist v1.0.0 // indirect
411+
inet.af/netaddr v0.0.0-20220811202034-502d2d690317 // indirect
391412
inet.af/peercred v0.0.0-20210906144145-0893ea02156a // indirect
392413
)

go.sum

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,26 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg6
5656
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
5757
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
5858
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
59+
github.com/DataDog/appsec-internal-go v1.0.0 h1:2u5IkF4DBj3KVeQn5Vg2vjPUtt513zxEYglcqnd500U=
60+
github.com/DataDog/appsec-internal-go v1.0.0/go.mod h1:+Y+4klVWKPOnZx6XESG7QHydOaUGEXyH2j/vSg9JiNM=
61+
github.com/DataDog/datadog-agent/pkg/obfuscate v0.45.0-rc.1 h1:XyYvstMFpSyZtfJHWJm1Sf1meNyCdfhKJrjB6+rUNOk=
62+
github.com/DataDog/datadog-agent/pkg/obfuscate v0.45.0-rc.1/go.mod h1:e933RWa4kAWuHi5jpzEuOiULlv21HcCFEVIYegmaB5c=
63+
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.48.0-devel.0.20230725154044-2549ba9058df h1:PbzrhHhs2+RRdKKti7JBSM8ATIeiji2T2cVt/d8GT8k=
64+
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.48.0-devel.0.20230725154044-2549ba9058df/go.mod h1:5Q39ZOIOwZMnFyRadp+5gH1bFdjmb+Pgxe+j5XOwaTg=
65+
github.com/DataDog/datadog-go/v5 v5.1.1 h1:JLZ6s2K1pG2h9GkvEvMdEGqMDyVLEAccdX5TltWcLMU=
66+
github.com/DataDog/datadog-go/v5 v5.1.1/go.mod h1:KhiYb2Badlv9/rofz+OznKoEF5XKTonWyhx5K83AP8E=
67+
github.com/DataDog/go-libddwaf v1.4.2 h1:JgHc+ARmfIzVqEl31HLedVYiNCu3LAQiluvpeNnEx2o=
68+
github.com/DataDog/go-libddwaf v1.4.2/go.mod h1:l2+rV8UlnYANNNECQyBE/a1dgc0qP0vg0xcgBscg7Mw=
69+
github.com/DataDog/go-tuf v1.0.1-0.5.2 h1:gld/e3MXfFVB/O8hc3mloP1ayFk75Mmdkmll/9lyd9I=
70+
github.com/DataDog/go-tuf v1.0.1-0.5.2/go.mod h1:zBcq6f654iVqmkk8n2Cx81E1JnNTMOAx1UEO/wZR+P0=
71+
github.com/DataDog/gostackparse v0.5.0 h1:jb72P6GFHPHz2W0onsN51cS3FkaMDcjb0QzgxxA4gDk=
72+
github.com/DataDog/gostackparse v0.5.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM=
73+
github.com/DataDog/sketches-go v1.2.1 h1:qTBzWLnZ3kM2kw39ymh6rMcnN+5VULwFs++lEYUUsro=
74+
github.com/DataDog/sketches-go v1.2.1/go.mod h1:1xYmPLY1So10AwxV6MJV0J53XVH+WL9Ad1KetxVivVI=
5975
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
6076
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
77+
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
78+
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
6179
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
6280
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
6381
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
@@ -333,7 +351,6 @@ github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxF
333351
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
334352
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
335353
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
336-
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
337354
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
338355
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
339356
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
@@ -1378,6 +1395,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
13781395
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
13791396
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
13801397
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
1398+
inet.af/netaddr v0.0.0-20220811202034-502d2d690317 h1:U2fwK6P2EqmopP/hFLTOAjWTki0qgd4GMJn5X8wOleU=
1399+
inet.af/netaddr v0.0.0-20220811202034-502d2d690317/go.mod h1:OIezDfdzOgFhuw4HuWapWq2e9l0H9tK4F1j+ETRtF3k=
13811400
inet.af/peercred v0.0.0-20210906144145-0893ea02156a h1:qdkS8Q5/i10xU2ArJMKYhVa1DORzBfYS/qA2UK2jheg=
13821401
inet.af/peercred v0.0.0-20210906144145-0893ea02156a/go.mod h1:FjawnflS/udxX+SvpsMgZfdqx2aykOlkISeAsADi5IU=
13831402
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)