Skip to content

Commit

Permalink
implement temporary telemetry fix to reporting integration config
Browse files Browse the repository at this point in the history
  • Loading branch information
zarirhamza committed Jan 23, 2025
1 parent 700f43e commit 267d936
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contrib/internal/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"context"
"fmt"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -67,6 +68,8 @@ func StartRequestSpan(r *http.Request, opts ...ddtrace.StartSpanOption) (tracer.
}
}
inferredProxySpan = startInferredProxySpan(requestProxyContext, spanParentCtx, inferredStartSpanOpts...)
telemetry.GlobalClient.IntegrationConfigChange([]telemetry.Configuration{{Name: "inferred_proxy_services_enabled",
Value: cfg.inferredProxyServicesEnabled}})
}
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/telemetry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
type Client interface {
RegisterAppConfig(name string, val interface{}, origin Origin)
ProductChange(namespace Namespace, enabled bool, configuration []Configuration)
IntegrationConfigChange(configuration []Configuration)
ConfigChange(configuration []Configuration)
Record(namespace Namespace, metric MetricKind, name string, value float64, tags []string, common bool)
Count(namespace Namespace, name string, value float64, tags []string, common bool)
Expand Down
23 changes: 23 additions & 0 deletions internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ func (c *client) ProductChange(namespace Namespace, enabled bool, configuration
}
}

// IntegrationConfigChange is a thread-safe method to enqueue an app-started event.
func (c *client) IntegrationConfigChange(configuration []Configuration) {
c.mu.Lock()
defer c.mu.Unlock()
c.integrationConfigChange(configuration)
}

// integrationConfigChange enqueues an app-started event to be flushed.
// Must be called with c.mu locked.
func (c *client) integrationConfigChange(configuration []Configuration) {
if !c.started {
log("attempted to send config change event, but telemetry client has not started")
return
}
if len(configuration) > 0 {
configChange := new(ConfigurationChange)
configChange.Configuration = configuration
configReq := c.newRequest(RequestTypeAppStarted)
configReq.Body.Payload = configChange
c.scheduleSubmit(configReq)
}
}

// ConfigChange is a thread-safe method to enqueue an app-client-configuration-change event.
func (c *client) ConfigChange(configuration []Configuration) {
c.mu.Lock()
Expand Down
14 changes: 14 additions & 0 deletions internal/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ func TestConfigChange(t *testing.T) {
Check(t, configPayload.Configuration, "delta_profiles", true)
}

func TestIntegrationConfigChange(t *testing.T) {
client := new(client)
client.start(nil, NamespaceTracers, true)
client.integrationConfigChange([]Configuration{BoolConfig("delta_profiles", true)})
require.Len(t, client.requests, 1)

body := client.requests[0].Body
assert.Equal(t, RequestTypeAppStarted, body.RequestType)
var configPayload = client.requests[0].Body.Payload.(*ConfigurationChange)
require.Len(t, configPayload.Configuration, 1)

Check(t, configPayload.Configuration, "delta_profiles", true)
}

// mockServer initializes a server that expects a strict amount of telemetry events. It saves these
// events in a slice until the expected number of events is reached.
// the `genTelemetry` argument accepts a function that should generate the expected telemetry events via calls to the global client
Expand Down
6 changes: 6 additions & 0 deletions internal/telemetry/telemetrytest/telemetrytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ func (c *MockClient) ConfigChange(args []telemetry.Configuration) {
c.On("ConfigChange", args).Return()
_ = c.Called(args)
}

// IntegrationConfigChange is a mock for the IntegrationConfigChange method.
func (c *MockClient) IntegrationConfigChange(args []telemetry.Configuration) {
c.On("IntegrationConfigChange", args).Return()
_ = c.Called(args)
}

0 comments on commit 267d936

Please sign in to comment.