Skip to content

feat(cli): add DataDog Go tracer #9411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(cli): add DataDog Go tracer
  • Loading branch information
ammario committed Aug 29, 2023
commit 6c1fef4627814fafe843f0335eceb2600be4bf50
1 change: 1 addition & 0 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,7 @@ func ConfigureTraceProvider(
sdkTracerProvider, _closeTracing, err := tracing.TracerProvider(ctx, "coderd", tracing.TracerOpts{
Default: cfg.Trace.Enable.Value(),
Coder: shouldCoderTrace,
DataDog: cfg.Trace.DataDog.Value(),
Honeycomb: cfg.Trace.HoneycombAPIKey.String(),
})
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cli/testdata/server-config.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ introspection:
# which may incur significant costs.
# (default: <unset>, type: bool)
captureLogs: false
# Enables sending Go runtime traces to the local DataDog agent.
# (default: false, type: bool)
dataDog: false
logging:
# Output debug-level logs.
# (default: <unset>, type: bool)
Expand Down
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions coderd/tracing/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.14.0"
ddotel "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry"
ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
ddprofiler "gopkg.in/DataDog/dd-trace-go.v1/profiler"

"golang.org/x/xerrors"
"google.golang.org/grpc/credentials"
)
Expand All @@ -25,6 +29,8 @@ type TracerOpts struct {
// Coder exports traces to Coder's public tracing ingest service and is used
// to improve the product. It is disabled when opting out of telemetry.
Coder bool
// DataDog exports traces and profiles to the local DataDog daemon.
DataDog bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add a comment

// Exports traces to Honeycomb.io with the provided API key.
Honeycomb string
}
Expand All @@ -45,6 +51,35 @@ func TracerProvider(ctx context.Context, service string, opts TracerOpts) (*sdkt
closers = []func(context.Context) error{}
)

if opts.DataDog {
// See more:
// https://docs.datadoghq.com/tracing/metrics/runtime_metrics/go/
dd := ddotel.NewTracerProvider(ddtracer.WithRuntimeMetrics())
closers = append(closers, func(_ context.Context) error {
// For some reason, this doesn't appear to actually wind down
// the goroutines.
return dd.Shutdown()
})

// See https://docs.datadoghq.com/profiler/enabling/go/
_ = ddprofiler.Start(
ddprofiler.WithService("coderd"),
ddprofiler.WithProfileTypes(
ddprofiler.CPUProfile,
ddprofiler.HeapProfile,
ddprofiler.GoroutineProfile,

// In the future, we may want to enable:
// ddprofiler.BlockProfile,
// ddprofiler.MutexProfile,
),
)
closers = append(closers, func(_ context.Context) error {
ddprofiler.Stop()
return nil
})
}

if opts.Default {
exporter, err := DefaultExporter(ctx)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ type TraceConfig struct {
Enable clibase.Bool `json:"enable" typescript:",notnull"`
HoneycombAPIKey clibase.String `json:"honeycomb_api_key" typescript:",notnull"`
CaptureLogs clibase.Bool `json:"capture_logs" typescript:",notnull"`
DataDog clibase.Bool `json:"data_dog" typescript:",notnull"`
}

type GitAuthConfig struct {
Expand Down Expand Up @@ -1237,6 +1238,22 @@ when required by your organization's security policy.`,
YAML: "captureLogs",
Annotations: clibase.Annotations{}.Mark(annotationExternalProxies, "true"),
},
{
Name: "Send Go runtime traces to DataDog",
Description: "Enables sending Go runtime traces to the local DataDog agent.",
Flag: "trace-datadog",
Env: "CODER_TRACE_DATADOG",
Value: &c.Trace.DataDog,
Group: &deploymentGroupIntrospectionTracing,
YAML: "dataDog",
// Hidden until an external user asks for it. For the time being,
// it's used to detect leaks in dogfood.
Hidden: true,
// Default is false because datadog creates a bunch of goroutines that
// don't get cleaned up and trip the leak detector.
Default: "false",
Annotations: clibase.Annotations{}.Mark(annotationExternalProxies, "true"),
},
// Provisioner settings
{
Name: "Provisioner Daemons",
Expand Down
1 change: 1 addition & 0 deletions docs/api/general.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions docs/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,22 @@ require (
tailscale.com v1.46.1
)

require gopkg.in/DataDog/dd-trace-go.v1 v1.54.0

require (
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/logging v1.8.1 // indirect
cloud.google.com/go/longrunning v0.5.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/DataDog/appsec-internal-go v1.0.0 // indirect
github.com/DataDog/datadog-agent/pkg/obfuscate v0.45.0-rc.1 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.48.0-devel.0.20230725154044-2549ba9058df // indirect
github.com/DataDog/datadog-go/v5 v5.1.1 // indirect
github.com/DataDog/go-libddwaf v1.4.2 // indirect
github.com/DataDog/go-tuf v1.0.1-0.5.2 // indirect
github.com/DataDog/gostackparse v0.5.0 // indirect
github.com/DataDog/sketches-go v1.2.1 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
Expand Down Expand Up @@ -247,11 +257,12 @@ require (
github.com/docker/docker v23.0.5+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ebitengine/purego v0.5.0-alpha // indirect
github.com/elastic/go-windows v1.0.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-chi/chi v1.5.4 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -276,6 +287,7 @@ require (
github.com/google/flatbuffers v23.1.21+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/nftables v0.1.1-0.20230115205135-9aa6fdf5a28c // indirect
github.com/google/pprof v0.0.0-20230509042627-b1315fad0c5a // indirect
github.com/google/s2a-go v0.1.5 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
Expand Down Expand Up @@ -335,16 +347,21 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/outcaste-io/ristretto v0.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pion/transport v0.14.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
Expand All @@ -357,13 +374,14 @@ require (
github.com/tcnksm/go-httpstat v0.2.0 // indirect
github.com/tdewolff/parse/v2 v2.6.6 // indirect
github.com/tdewolff/test v1.0.9 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
Expand All @@ -378,7 +396,9 @@ require (
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230215201556-9c5414ab4bde // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
Expand All @@ -388,5 +408,6 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v1.0.0 // indirect
inet.af/netaddr v0.0.0-20220811202034-502d2d690317 // indirect
inet.af/peercred v0.0.0-20210906144145-0893ea02156a // indirect
)
Loading