diff --git a/ddtrace/tracer/option.go b/ddtrace/tracer/option.go index de1359fc69..02ce91ced2 100644 --- a/ddtrace/tracer/option.go +++ b/ddtrace/tracer/option.go @@ -169,10 +169,6 @@ type config struct { // retryInterval is the interval between agent connection retries. It has no effect if sendRetries is not set retryInterval time.Duration - // logStartup, when true, causes various startup info to be written - // when the tracer starts. - logStartup bool - // serviceName specifies the name of this application. serviceName string @@ -476,7 +472,6 @@ func newConfig(opts ...StartOption) (*config, error) { c.isLambdaFunction = true } } - c.logStartup = internal.BoolEnv("DD_TRACE_STARTUP_LOGS", true) c.runtimeMetrics = internal.BoolVal(getDDorOtelConfig("metrics"), false) c.runtimeMetricsV2 = internal.BoolEnv("DD_RUNTIME_METRICS_V2_ENABLED", true) c.logDirectory = env.Get("DD_TRACE_LOG_DIRECTORY") @@ -613,11 +608,11 @@ func newConfig(opts ...StartOption) (*config, error) { } // 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.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.internalConfig.SetLogStartup(false, internalconfig.OriginCalculated) // 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 c.ciVisibilityNoopTracer = internal.BoolEnv(constants.CIVisibilityUseNoopTracer, false) } @@ -1300,7 +1295,7 @@ func WithTraceEnabled(enabled bool) StartOption { // WithLogStartup allows enabling or disabling the startup log. func WithLogStartup(enabled bool) StartOption { return func(c *config) { - c.logStartup = enabled + c.internalConfig.SetLogStartup(enabled, internalconfig.OriginCode) } } diff --git a/ddtrace/tracer/option_test.go b/ddtrace/tracer/option_test.go index b08360eca4..c3c232ed51 100644 --- a/ddtrace/tracer/option_test.go +++ b/ddtrace/tracer/option_test.go @@ -1547,11 +1547,11 @@ func TestWithTraceEnabled(t *testing.T) { func TestWithLogStartup(t *testing.T) { c, err := newTestConfig() assert.NoError(t, err) - assert.True(t, c.logStartup) + assert.True(t, c.internalConfig.LogStartup()) WithLogStartup(false)(c) - assert.False(t, c.logStartup) + assert.False(t, c.internalConfig.LogStartup()) WithLogStartup(true)(c) - assert.True(t, c.logStartup) + assert.True(t, c.internalConfig.LogStartup()) } func TestWithHeaderTags(t *testing.T) { diff --git a/ddtrace/tracer/telemetry.go b/ddtrace/tracer/telemetry.go index 4704efd773..0e66600fa4 100644 --- a/ddtrace/tracer/telemetry.go +++ b/ddtrace/tracer/telemetry.go @@ -28,6 +28,7 @@ func reportTelemetryOnAppStarted(c telemetry.Configuration) { // event is sent with tracer config data. // Note that the tracer is not considered as a standalone product by telemetry so we cannot send // an app-product-change event for the tracer. +// TODO (APMAPI-1771): This function should be deleted once config migration is complete func startTelemetry(c *config) telemetry.Client { if telemetry.Disabled() { // Do not do extra work populating config data if instrumentation telemetry is disabled. @@ -42,7 +43,7 @@ func startTelemetry(c *config) telemetry.Client { {Name: "lambda_mode", Value: c.logToStdout}, {Name: "send_retries", Value: c.sendRetries}, {Name: "retry_interval", Value: c.retryInterval}, - {Name: "trace_startup_logs_enabled", Value: c.logStartup}, + {Name: "trace_startup_logs_enabled", Value: c.internalConfig.LogStartup()}, {Name: "service", Value: c.serviceName}, {Name: "universal_version", Value: c.universalVersion}, {Name: "env", Value: c.env}, diff --git a/ddtrace/tracer/tracer.go b/ddtrace/tracer/tracer.go index a132067b1e..2d406d588c 100644 --- a/ddtrace/tracer/tracer.go +++ b/ddtrace/tracer/tracer.go @@ -273,7 +273,7 @@ func Start(opts ...StartOption) error { return fmt.Errorf("failed to start llmobs: %w", err) } } - if t.config.logStartup { + if t.config.internalConfig.LogStartup() { logStartup(t) } diff --git a/internal/config/config.go b/internal/config/config.go index b6ff17bafe..62f5185278 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -36,8 +36,9 @@ const ( type Config struct { mu sync.RWMutex // Config fields are protected by the mutex. - agentURL *url.URL - debug bool + agentURL *url.URL + debug bool + // logStartup, when true, causes various startup info to be written when the tracer starts. logStartup bool serviceName string version string @@ -73,7 +74,7 @@ func loadConfig() *Config { // TODO: Use defaults from config json instead of hardcoding them here cfg.agentURL = provider.getURL("DD_TRACE_AGENT_URL", &url.URL{Scheme: "http", Host: "localhost:8126"}) cfg.debug = provider.getBool("DD_TRACE_DEBUG", false) - cfg.logStartup = provider.getBool("DD_TRACE_STARTUP_LOGS", false) + cfg.logStartup = provider.getBool("DD_TRACE_STARTUP_LOGS", true) cfg.serviceName = provider.getString("DD_SERVICE", "") cfg.version = provider.getString("DD_VERSION", "") cfg.env = provider.getString("DD_ENV", "") @@ -147,3 +148,16 @@ func (c *Config) SetDataStreamsMonitoringEnabled(enabled bool, origin telemetry. c.dataStreamsMonitoringEnabled = enabled telemetry.RegisterAppConfig("DD_DATA_STREAMS_ENABLED", enabled, origin) } + +func (c *Config) LogStartup() bool { + c.mu.RLock() + defer c.mu.RUnlock() + return c.logStartup +} + +func (c *Config) SetLogStartup(enabled bool, origin telemetry.Origin) { + c.mu.Lock() + defer c.mu.Unlock() + c.logStartup = enabled + telemetry.RegisterAppConfig("DD_TRACE_STARTUP_LOGS", enabled, origin) +}