From 9159627434955e8d36e0bf1ffaf9ad3b27331158 Mon Sep 17 00:00:00 2001 From: Tony Redondo Date: Tue, 10 Dec 2024 23:25:53 +0100 Subject: [PATCH] [v2] fix(ddtrace/tracer): Disable agent features and remote configuration in CI Visibility agentless mode --- ddtrace/tracer/option.go | 26 +++++++++++++------------- ddtrace/tracer/tracer.go | 13 +++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/ddtrace/tracer/option.go b/ddtrace/tracer/option.go index afba52a0d8..9377dea837 100644 --- a/ddtrace/tracer/option.go +++ b/ddtrace/tracer/option.go @@ -531,8 +531,19 @@ func newConfig(opts ...StartOption) (*config, error) { if c.debug { log.SetLevel(log.LevelDebug) } - // if using stdout or traces are disabled, agent is disabled - agentDisabled := c.logToStdout || !c.enabled.current + + // Check if CI Visibility mode is enabled + if internal.BoolEnv(constants.CIVisibilityEnabledEnvironmentVariable, false) { + c.ciVisibilityEnabled = true // Enable CI Visibility mode + c.httpClientTimeout = time.Second * 45 // Increase timeout up to 45 seconds (same as other tracers in CIVis mode) + c.logStartup = false // If we are in CI Visibility mode we don't want to log the startup to stdout to avoid polluting the output + ciTransport := newCiVisibilityTransport(c) // Create a default CI Visibility Transport + c.transport = ciTransport // Replace the default transport with the CI Visibility transport + c.ciVisibilityAgentless = ciTransport.agentless + } + + // if using stdout or traces are disabled, or we are in ci visibility agentless mode, agent is disabled + agentDisabled := c.logToStdout || !c.enabled.current || c.ciVisibilityAgentless c.agent = loadAgentFeatures(agentDisabled, c.agentURL, c.httpClient) info, ok := debug.ReadBuildInfo() if !ok { @@ -550,17 +561,6 @@ func newConfig(opts ...StartOption) (*config, error) { // This allows persisting the initial value of globalTags for future resets and updates. globalTagsOrigin := c.globalTags.cfgOrigin c.initGlobalTags(c.globalTags.get(), globalTagsOrigin) - - // Check if CI Visibility mode is enabled - if internal.BoolEnv(constants.CIVisibilityEnabledEnvironmentVariable, false) { - c.ciVisibilityEnabled = true // Enable CI Visibility mode - c.httpClientTimeout = time.Second * 45 // Increase timeout up to 45 seconds (same as other tracers in CIVis mode) - c.logStartup = false // If we are in CI Visibility mode we don't want to log the startup to stdout to avoid polluting the output - ciTransport := newCiVisibilityTransport(c) // Create a default CI Visibility Transport - c.transport = ciTransport // Replace the default transport with the CI Visibility transport - c.ciVisibilityAgentless = ciTransport.agentless - } - return c, nil } diff --git a/ddtrace/tracer/tracer.go b/ddtrace/tracer/tracer.go index bd28385f2d..fdaf9d808a 100644 --- a/ddtrace/tracer/tracer.go +++ b/ddtrace/tracer/tracer.go @@ -203,6 +203,19 @@ func Start(opts ...StartOption) error { if t.dataStreams != nil { t.dataStreams.Start() } + if t.config.ciVisibilityAgentless { + // CI Visibility agentless mode doesn't require remote configuration. + + // start instrumentation telemetry unless it is disabled through the + // DD_INSTRUMENTATION_TELEMETRY_ENABLED env var + startTelemetry(t.config) + + // start appsec + appsec.Start(t.config.appsecStartOptions...) + globalinternal.SetTracerInitialized(true) + return nil + } + // Start AppSec with remote configuration cfg := remoteconfig.DefaultClientConfig() cfg.AgentURL = t.config.agentURL.String()