Skip to content

Commit

Permalink
internal/telemetry: don't send app-dependencies-loaded without Go deps (
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio-Guerra authored Jun 12, 2024
1 parent 09bdc86 commit 79237af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 23 additions & 10 deletions internal/telemetry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ func (c *client) start(configuration []Configuration, namespace Namespace, flush
cfg = append(cfg, c.globalAppConfig...)
cfg = append(cfg, configuration...)

// State whether the app has its Go dependencies available or not
deps, ok := debug.ReadBuildInfo()
if !ok {
deps = nil // because not guaranteed to be nil by the public doc when !ok
}
cfg = append(cfg, BoolConfig("dependencies_available", ok))
collectDependenciesEnabled := collectDependencies()
cfg = append(cfg, BoolConfig("DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED", collectDependenciesEnabled)) // TODO: report all the possible telemetry config option automatically
if !collectDependenciesEnabled {
deps = nil // to simplify the condition below to `deps != nil`
}

payload := &AppStarted{
Configuration: cfg,
Products: productInfo,
Expand All @@ -219,18 +231,19 @@ func (c *client) start(configuration []Configuration, namespace Namespace, flush
appStarted.Body.Payload = payload
c.scheduleSubmit(appStarted)

if collectDependencies() {
if deps != nil {
var depPayload Dependencies
if deps, ok := debug.ReadBuildInfo(); ok {
for _, dep := range deps.Deps {
depPayload.Dependencies = append(depPayload.Dependencies,
Dependency{
Name: dep.Path,
Version: strings.TrimPrefix(dep.Version, "v"),
},
)
}
for _, dep := range deps.Deps {
depPayload.Dependencies = append(depPayload.Dependencies,
Dependency{
Name: dep.Path,
Version: strings.TrimPrefix(dep.Version, "v"),
},
)
}
// Send the telemetry request if and only if the dependencies are actually present in the binary.
// For instance, bazel doesn't include them out of the box (cf. https://github.com/bazelbuild/rules_go/issues/3090),
// which would result in an empty list of dependencies.
dep := c.newRequest(RequestTypeDependenciesLoaded)
dep.Body.Payload = depPayload
c.scheduleSubmit(dep)
Expand Down
1 change: 0 additions & 1 deletion internal/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func TestRegisterAppConfig(t *testing.T) {
require.Equal(t, RequestTypeAppStarted, req.RequestType)
appStarted := req.Payload.(*AppStarted)
cfg := appStarted.Configuration
require.Len(t, cfg, 2)
require.Contains(t, cfg, Configuration{Name: "key1", Value: "val1", Origin: OriginDefault})
require.Contains(t, cfg, Configuration{Name: "key2", Value: "val2", Origin: OriginDDConfig})

Expand Down

0 comments on commit 79237af

Please sign in to comment.