Skip to content

Commit

Permalink
Enable telemetry logs for IAST and CI Visibility users (#7017)
Browse files Browse the repository at this point in the history
  • Loading branch information
smola committed May 30, 2024
1 parent e2a66df commit d46ec26
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 13 additions & 4 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit d46ec26

Please sign in to comment.