Skip to content
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

internal/telemetry: don't send app-dependencies-loaded in the absence of Go deps #2740

Merged
merged 2 commits into from
Jun 12, 2024
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
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)
Copy link
Member

Choose a reason for hiding this comment

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

@Julio-Guerra Is this change required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, because I changed the global config with dependencies_available and DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED reported by default all the times, so I removed the enforcement to 2 and let the following assertions fail anyway if the expected config values are missing.

require.Contains(t, cfg, Configuration{Name: "key1", Value: "val1", Origin: OriginDefault})
require.Contains(t, cfg, Configuration{Name: "key2", Value: "val2", Origin: OriginDDConfig})

Expand Down
Loading