Skip to content

Commit 5259c28

Browse files
committed
refactor & centralize api key checks
1 parent a8108c6 commit 5259c28

File tree

1 file changed

+22
-15
lines changed
  • internal-api/src/main/java/datadog/trace/api

1 file changed

+22
-15
lines changed

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,10 +1774,6 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
17741774
this.traceFlushIntervalSeconds =
17751775
configProvider.getFloat(
17761776
TracerConfig.TRACE_FLUSH_INTERVAL, ConfigDefaults.DEFAULT_TRACE_FLUSH_INTERVAL);
1777-
if (profilingAgentless && apiKey == null) {
1778-
log.warn(
1779-
"Agentless profiling activated but no api key provided. Profile uploading will likely fail");
1780-
}
17811777

17821778
this.tracePostProcessingTimeout =
17831779
configProvider.getLong(
@@ -1790,23 +1786,34 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
17901786
"Attempt to enable LLM Observability without ML app defined."
17911787
+ "Please ensure that the name of the ML app is provided through properties or env variable");
17921788
}
1793-
if (llmObsAgentlessEnabled && (apiKey == null || apiKey.isEmpty())) {
1794-
throw new FatalAgentMisconfigurationError(
1795-
"Attempt to start LLM Observability in Agentless mode without API key. "
1796-
+ "Please ensure that either an API key is configured, or the tracer is set up to work with the Agent");
1797-
}
1789+
17981790
log.debug(
17991791
"LLM Observability enabled for ML app {}, agentless mode {}",
18001792
llmObsMlApp,
18011793
llmObsAgentlessEnabled);
18021794
}
18031795

1804-
if (isCiVisibilityEnabled()
1805-
&& ciVisibilityAgentlessEnabled
1806-
&& (apiKey == null || apiKey.isEmpty())) {
1807-
throw new FatalAgentMisconfigurationError(
1808-
"Attempt to start in Agentless mode without API key. "
1809-
+ "Please ensure that either an API key is configured, or the tracer is set up to work with the Agent");
1796+
// if API key is not provided, check if any products are using agentless mode and require it
1797+
if (apiKey == null || apiKey.isEmpty()) {
1798+
// CI Visibility
1799+
if (isCiVisibilityEnabled() && ciVisibilityAgentlessEnabled) {
1800+
throw new FatalAgentMisconfigurationError(
1801+
"Attempt to start in CI Visibility in Agentless mode without API key. "
1802+
+ "Please ensure that either an API key is configured, or the tracer is set up to work with the Agent");
1803+
}
1804+
1805+
// Profiling
1806+
if (profilingAgentless) {
1807+
log.warn(
1808+
"Agentless profiling activated but no api key provided. Profile uploading will likely fail");
1809+
}
1810+
1811+
// LLM Observability
1812+
if (isLlmObsEnabled() && llmObsAgentlessEnabled) {
1813+
throw new FatalAgentMisconfigurationError(
1814+
"Attempt to start LLM Observability in Agentless mode without API key. "
1815+
+ "Please ensure that either an API key is configured, or the tracer is set up to work with the Agent");
1816+
}
18101817
}
18111818

18121819
this.telemetryDebugRequestsEnabled =

0 commit comments

Comments
 (0)