-
Notifications
You must be signed in to change notification settings - Fork 856
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make config file available in early agent initialization phase (#7550)
Fixes #7540 I think this kind of early config might be useful in general -- for instance, I think I'd like to use it for properties introduced in #7339
- Loading branch information
Mateusz Rzeszutek
authored
Jan 12, 2023
1 parent
09b63d2
commit 18cffb7
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/EarlyInitAgentConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.config; | ||
|
||
import io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil; | ||
import java.util.Map; | ||
|
||
/** | ||
* Agent config class that is only supposed to be used before the SDK (and {@link | ||
* io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties}) is initialized. | ||
*/ | ||
public final class EarlyInitAgentConfig { | ||
|
||
public static EarlyInitAgentConfig create() { | ||
return new EarlyInitAgentConfig(ConfigurationFileLoader.getConfigFileContents()); | ||
} | ||
|
||
private final Map<String, String> configFileContents; | ||
|
||
private EarlyInitAgentConfig(Map<String, String> configFileContents) { | ||
this.configFileContents = configFileContents; | ||
} | ||
|
||
public boolean getBoolean(String propertyName, boolean defaultValue) { | ||
String configFileValueStr = configFileContents.get(propertyName); | ||
boolean configFileValue = | ||
configFileValueStr == null ? defaultValue : Boolean.parseBoolean(configFileValueStr); | ||
return ConfigPropertiesUtil.getBoolean(propertyName, configFileValue); | ||
} | ||
} |