diff --git a/dd-java-agent/agent-logging/src/main/java/datadog/trace/logging/ddlogger/DDLoggerFactory.java b/dd-java-agent/agent-logging/src/main/java/datadog/trace/logging/ddlogger/DDLoggerFactory.java index efd8ef2293f..2a9f9ab5d8c 100644 --- a/dd-java-agent/agent-logging/src/main/java/datadog/trace/logging/ddlogger/DDLoggerFactory.java +++ b/dd-java-agent/agent-logging/src/main/java/datadog/trace/logging/ddlogger/DDLoggerFactory.java @@ -13,7 +13,7 @@ public class DDLoggerFactory implements ILoggerFactory, LogLevelSwitcher { - private final boolean telemetryLogCollectionEnabled = getLogCollectionEnabled(false); + private final boolean telemetryLogCollectionEnabled = isLogCollectionEnabled(); private volatile LoggerHelperFactory helperFactory = null; private volatile LogLevel override = null; @@ -88,17 +88,30 @@ public void reinitialize() { helperFactory = null; } - // DDLoggerFactory can be called at very early stage, before Config loaded + // DDLoggerFactory can be called at very early stage, before Config is loaded // So to get property/env we use this custom function - private static boolean getLogCollectionEnabled(boolean defaultValue) { - String value = System.getProperty("dd.telemetry.log-collection.enabled"); + private static boolean isLogCollectionEnabled() { + // FIXME: For the initial rollout, we default log collection to true for IAST and CI Visibility + // users. This should be removed once we default to true. + final boolean defaultValue = + isFlagEnabled("dd.iast.enabled", "DD_IAST_ENABLED", false) + || isFlagEnabled("dd.civisibility.enabled", "DD_CIVISIBILITY_ENABLED", false) + || isFlagEnabled( + "dd.dynamic.instrumentation.enabled", "DD_DYNAMIC_INSTRUMENTATION_ENABLED", false); + return isFlagEnabled( + "dd.telemetry.log-collection.enabled", "DD_TELEMETRY_LOG_COLLECTION_ENABLED", defaultValue); + } + + private static boolean isFlagEnabled( + final String systemProperty, final String envVar, final boolean defaultValue) { + String value = System.getProperty(systemProperty); if ("true".equalsIgnoreCase(value)) { return true; } if ("false".equalsIgnoreCase(value)) { return false; } - value = System.getenv("DD_TELEMETRY_LOG_COLLECTION_ENABLED"); + value = System.getenv(envVar); if ("true".equalsIgnoreCase(value)) { return true; } diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index 6219cd5f284..6ba0232ada5 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -1595,10 +1595,6 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment()) configProvider.getBoolean( TELEMETRY_DEPENDENCY_COLLECTION_ENABLED, DEFAULT_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED); - - isTelemetryLogCollectionEnabled = - configProvider.getBoolean( - TELEMETRY_LOG_COLLECTION_ENABLED, DEFAULT_TELEMETRY_LOG_COLLECTION_ENABLED); telemetryDependencyResolutionQueueSize = configProvider.getInteger( TELEMETRY_DEPENDENCY_RESOLUTION_QUEUE_SIZE, @@ -1910,6 +1906,19 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment()) debuggerThirdPartyIncludes = tryMakeImmutableSet(configProvider.getList(THIRD_PARTY_INCLUDES)); debuggerThirdPartyExcludes = tryMakeImmutableSet(configProvider.getList(THIRD_PARTY_EXCLUDES)); + // FIXME: For the initial rollout, we default log collection to true for IAST and CI Visibility + // users. This should be removed once we default to true, and then it can also be moved up + // together with the rest of telemetry ocnfig. + final boolean telemetryLogCollectionEnabledDefault = + instrumenterConfig.isTelemetryEnabled() + && (instrumenterConfig.getIastActivation() == ProductActivation.FULLY_ENABLED + || instrumenterConfig.isCiVisibilityEnabled() + || debuggerEnabled) + || DEFAULT_TELEMETRY_LOG_COLLECTION_ENABLED; + isTelemetryLogCollectionEnabled = + configProvider.getBoolean( + TELEMETRY_LOG_COLLECTION_ENABLED, telemetryLogCollectionEnabledDefault); + awsPropagationEnabled = isPropagationEnabled(true, "aws", "aws-sdk"); sqsPropagationEnabled = isPropagationEnabled(true, "sqs");