public static IProductConfiguration ApplyReleaseOrDevDefaults(this IProductConfiguration config) { const string EnvVarName = "DD_INTERNAL_USE_DEVELOPMENT_CONFIGURATION"; const bool ddInternalUseDevelopmentConfigurationValDefault = false; string ddInternalUseDevelopmentConfiguration = Environment.GetEnvironmentVariable(EnvVarName); if ( ConfigurationProviderUtils.TryParseBooleanSettingStr( ddInternalUseDevelopmentConfiguration, ddInternalUseDevelopmentConfigurationValDefault, out bool ddInternalUseDevelopmentConfigurationVal)) { Log.Info( LogComponentMoniker, "Use-Dev-Config environment setting found and parsed.", "Env var name", EnvVarName, "Parsed value", ddInternalUseDevelopmentConfigurationVal); } else { Log.Info( LogComponentMoniker, "Use-Dev-Config environment setting not found or not parsed. Default will be used.", "Env var name", EnvVarName, "Value", ddInternalUseDevelopmentConfiguration, "Used default value", ddInternalUseDevelopmentConfigurationVal); } if (ddInternalUseDevelopmentConfigurationVal) { return(DevProductConfigurationProvider.ApplyDevDefaults(config)); } else { return(DefaultReleaseProductConfigurationProvider.ApplyReleaseDefaults(config)); } }
public static IProductConfiguration ApplyEnvironmentVariables(this IProductConfiguration config) { if (config == null) { return(null); } var mutableConfig = new MutableProductConfiguration(config); if (TryGetEnvironmentVariable("SIGNALFX_PROFILING_UPLOAD_PERIOD", out string envProfilesExportDefaultInterval)) { if (int.TryParse(envProfilesExportDefaultInterval, out var profilesExportDefaultInterval)) { mutableConfig.ProfilesExport_DefaultInterval = TimeSpan.FromSeconds(profilesExportDefaultInterval); } else { Log.Error( Log.WithCallInfo(LogComponentMoniker), "The environment variable \"SIGNALFX_PROFILING_UPLOAD_PERIOD\" is specified (\"", envProfilesExportDefaultInterval, "\") but cannot be parsed as an int. Using original value: ", mutableConfig.ProfilesExport_DefaultInterval); } } if (TryGetEnvironmentVariable("SIGNALFX_PROFILING_OUTPUT_DIR", out string directory)) { mutableConfig.ProfilesExport_LocalFiles_Directory = directory; } // If Ingestion Endpoint Url is specified, the Host, Port and ApiPath are ignored. // However, that logic is inside the export loop that actually interprets those values. // At this point we just extract all of the info that is contained in the environment variables. // If both, URL and Host-Port-Etc are specified, we will extract them all and leave the // priorization logic of what to use to the config consumer. if (TryGetEnvironmentVariable("SIGNALFX_TRACE_AGENT_URL", out string ddTraceAgentUrl)) { mutableConfig.ProfilesIngestionEndpoint_Url = ddTraceAgentUrl; } if (TryGetEnvironmentVariable("SIGNALFX_AGENT_HOST", out string ddTraceAgentHost)) { mutableConfig.ProfilesIngestionEndpoint_Host = ddTraceAgentHost; } if (TryGetEnvironmentVariable("SIGNALFX_TRACE_AGENT_PORT", out string szTraceAgentPort)) { if (int.TryParse(szTraceAgentPort, out int port)) { mutableConfig.ProfilesIngestionEndpoint_Port = port; } else { Log.Error( Log.WithCallInfo(LogComponentMoniker), "The environment variable \"SIGNALFX_TRACE_AGENT_PORT\" is specified (", szTraceAgentPort, ") but cannot be parsed as a number and will be ignored."); } } // Api Key is not required for agent-based ingestion scnarios; it IS required for agent-less ingestion. if (TryGetEnvironmentVariable("SIGNALFX_API_KEY", out string ddApiKey)) { mutableConfig.ProfilesIngestionEndpoint_DatadogApiKey = ddApiKey; } if (TryGetEnvironmentVariable("SIGNALFX_HOSTNAME", out string ddHostName)) { mutableConfig.DDDataTags_Host = ddHostName; } if (TryGetEnvironmentVariable("SIGNALFX_SERVICE", out string ddServiceName)) { mutableConfig.DDDataTags_Service = ddServiceName; } if (TryGetEnvironmentVariable("SIGNALFX_ENV", out string ddEnvironment)) { mutableConfig.DDDataTags_Env = ddEnvironment; } if (TryGetEnvironmentVariable("SIGNALFX_VERSION", out string ddServiceVersion)) { mutableConfig.DDDataTags_Version = ddServiceVersion; } if (TryGetEnvironmentVariable("SIGNALFX_TAGS", out string ddTagsStr)) { mutableConfig.DDDataTags_CustomTags = ParseAndMergeDdTags(mutableConfig.DDDataTags_CustomTags, ddTagsStr); } if (TryGetEnvironmentVariable("SIGNALFX_TRACE_DEBUG", out string envIsTraceDebugEnabled)) { const bool isTraceDebugEnabled = true; if ( ConfigurationProviderUtils.TryParseBooleanSettingStr( envIsTraceDebugEnabled, isTraceDebugEnabled, out bool ddIsTraceDebugEnabledVal)) { mutableConfig.Log_IsDebugEnabled = ddIsTraceDebugEnabledVal; } else { Log.Error( Log.WithCallInfo(LogComponentMoniker), "The environment variable \"SIGNALFX_TRACE_DEBUG\" is specified (", envIsTraceDebugEnabled, $") but cannot be parsed as a boolean. Using {isTraceDebugEnabled.ToString()} as default"); mutableConfig.Log_IsDebugEnabled = isTraceDebugEnabled; } } if (TryGetEnvironmentVariable("SIGNALFX_PROFILING_LOG_DIR", out string ddTraceLogDirectory)) { mutableConfig.Log_PreferredLogFileDirectory = ddTraceLogDirectory; } if (TryGetEnvironmentVariable("SIGNALFX_INTERNAL_OPERATIONAL_METRICS_ENABLED", out string envIsEnabled)) { const bool isOperationalMetricsEnabled = false; if (ConfigurationProviderUtils.TryParseBooleanSettingStr(envIsEnabled, isOperationalMetricsEnabled, out bool isEnabled)) { mutableConfig.Metrics_Operational_IsEnabled = isEnabled; } else { Log.Error( Log.WithCallInfo(LogComponentMoniker), "The environment variable \"SIGNALFX_INTERNAL_OPERATIONAL_METRICS_ENABLED\" is specified (", envIsEnabled, $") but cannot be parsed as a boolean. Using {isOperationalMetricsEnabled.ToString()} as default"); mutableConfig.Log_IsDebugEnabled = isOperationalMetricsEnabled; } } if (TryGetEnvironmentVariable("SIGNALFX_PROFILING_FRAMES_NATIVE_ENABLED", out string envFramesNativeIsEnabled)) { const bool isFramesNativeEnabled = false; if (ConfigurationProviderUtils.TryParseBooleanSettingStr(envFramesNativeIsEnabled, isFramesNativeEnabled, out bool isEnabled)) { mutableConfig.FrameKinds_Native_IsEnabled = isEnabled; } else { Log.Error( Log.WithCallInfo(LogComponentMoniker), "The environment variable \"SIGNALFX_PROFILING_FRAMES_NATIVE_ENABLED\" is specified (", envFramesNativeIsEnabled, $") but cannot be parsed as a boolean. Using isFramesNativeEnabled.ToString() as default"); mutableConfig.FrameKinds_Native_IsEnabled = isFramesNativeEnabled; } } return(mutableConfig.CreateImmutableSnapshot()); }