diff --git a/contrib/internal/httptrace/httptrace.go b/contrib/internal/httptrace/httptrace.go index e5be0ddc4b..4b36264a94 100644 --- a/contrib/internal/httptrace/httptrace.go +++ b/contrib/internal/httptrace/httptrace.go @@ -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" @@ -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}}) } } } diff --git a/internal/telemetry/client.go b/internal/telemetry/client.go index 4e55b77a82..d6c63e7433 100644 --- a/internal/telemetry/client.go +++ b/internal/telemetry/client.go @@ -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) diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index 994dee89a8..a03138c5f1 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -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() diff --git a/internal/telemetry/telemetry_test.go b/internal/telemetry/telemetry_test.go index 87d40ff02a..47decf1ddf 100644 --- a/internal/telemetry/telemetry_test.go +++ b/internal/telemetry/telemetry_test.go @@ -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 diff --git a/internal/telemetry/telemetrytest/telemetrytest.go b/internal/telemetry/telemetrytest/telemetrytest.go index 0c8b22bd32..430cf59456 100644 --- a/internal/telemetry/telemetrytest/telemetrytest.go +++ b/internal/telemetry/telemetrytest/telemetrytest.go @@ -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) +}