Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void parseDeclarativeConfiguration() {
// make sure to test enums too: "instrument_type: histogram"
String string =
"""
file_format: "1.0-rc.1"
file_format: "1.0"
tracer_provider:
processors:
- batch:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,18 @@ private static AutoConfiguredOpenTelemetrySdk maybeConfigureFromFile(
}
}

String otelConfigFile = config.getString("otel.config.file");
if (otelConfigFile != null && !otelConfigFile.isEmpty()) {
logger.warning(
"otel.config.file was set, but has been replaced with otel.experimental.config.file");
String configurationFile = config.getString("otel.config.file");
if (configurationFile == null || configurationFile.isEmpty()) {
configurationFile = config.getString("otel.experimental.config.file");
if (configurationFile == null || configurationFile.isEmpty()) {
logger.warning(
"otel.experimental.config.file is deprecated and will be removed after 1.62.0 release. Please use otel.config.file instead.");
}
}
String configurationFile = config.getString("otel.experimental.config.file");
if (configurationFile == null || configurationFile.isEmpty()) {
return null;
}

if (!INCUBATOR_AVAILABLE) {
throw new ConfigurationException(
"Cannot autoconfigure from config file without opentelemetry-sdk-extension-incubator on the classpath");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DeclarativeConfigurationTest {
@Test
void configFile(@TempDir Path tempDir) throws IOException {
String yaml =
"file_format: \"1.0-rc.1\"\n"
"file_format: \"1.0\"\n"
+ "resource:\n"
+ " attributes:\n"
+ " - name: service.name\n"
Expand All @@ -37,7 +37,7 @@ void configFile(@TempDir Path tempDir) throws IOException {
Files.write(path, yaml.getBytes(StandardCharsets.UTF_8));
ConfigProperties config =
DefaultConfigProperties.createFromMap(
Collections.singletonMap("otel.experimental.config.file", path.toString()));
Collections.singletonMap("otel.config.file", path.toString()));

assertThatThrownBy(() -> AutoConfiguredOpenTelemetrySdk.builder().setConfig(config).build())
.isInstanceOf(ConfigurationException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TestDeclarativeConfigurationProvider implements DeclarativeConfigur
@Override
public OpenTelemetryConfigurationModel getConfigurationModel() {
String yaml =
"file_format: \"1.0-rc.1\"\n"
"file_format: \"1.0\"\n"
+ "resource:\n"
+ " detection/development:\n"
+ " detectors:\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DeclarativeConfigurationTest {
@BeforeEach
void setup() throws IOException {
String yaml =
"file_format: \"1.0-rc.1\"\n"
"file_format: \"1.0\"\n"
+ "resource:\n"
+ " attributes:\n"
+ " - name: service.name\n"
Expand Down Expand Up @@ -94,15 +94,15 @@ void configFile_fileNotFound() {
AutoConfiguredOpenTelemetrySdk.builder()
.setConfig(
DefaultConfigProperties.createFromMap(
Collections.singletonMap("otel.experimental.config.file", "foo")))
Collections.singletonMap("otel.config.file", "foo")))
.build())
.isInstanceOf(ConfigurationException.class)
.hasMessageContaining("Configuration file not found");

assertThatCode(
() ->
AutoConfiguredOpenTelemetrySdk.builder()
.addPropertiesSupplier(() -> singletonMap("otel.experimental.config.file", ""))
.addPropertiesSupplier(() -> singletonMap("otel.config.file", ""))
.addPropertiesSupplier(() -> singletonMap("otel.sdk.disabled", "true"))
.build())
.doesNotThrowAnyException();
Expand All @@ -112,7 +112,7 @@ void configFile_fileNotFound() {
void configFile_Valid() {
ConfigProperties config =
DefaultConfigProperties.createFromMap(
Collections.singletonMap("otel.experimental.config.file", configFilePath.toString()));
Collections.singletonMap("otel.config.file", configFilePath.toString()));
AutoConfiguredOpenTelemetrySdkBuilder builder = spy(AutoConfiguredOpenTelemetrySdk.builder());
Thread thread = new Thread();
doReturn(thread).when(builder).shutdownHook(any());
Expand Down Expand Up @@ -151,7 +151,7 @@ void configFile_setComponentLoader() {
ComponentLoader.forClassLoader(DeclarativeConfigurationTest.class.getClassLoader());
ConfigProperties config =
DefaultConfigProperties.createFromMap(
Collections.singletonMap("otel.experimental.config.file", configFilePath.toString()));
Collections.singletonMap("otel.config.file", configFilePath.toString()));

AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk =
AutoConfiguredOpenTelemetrySdk.builder()
Expand All @@ -172,7 +172,7 @@ void configFile_setComponentLoader() {
void configFile_NoShutdownHook() {
ConfigProperties config =
DefaultConfigProperties.createFromMap(
Collections.singletonMap("otel.experimental.config.file", configFilePath.toString()));
Collections.singletonMap("otel.config.file", configFilePath.toString()));
AutoConfiguredOpenTelemetrySdkBuilder builder = spy(AutoConfiguredOpenTelemetrySdk.builder());

AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk =
Expand All @@ -185,7 +185,7 @@ void configFile_NoShutdownHook() {
@Test
void configFile_Error(@TempDir Path tempDir) throws IOException {
String yaml =
"file_format: \"1.0-rc.1\"\n"
"file_format: \"1.0\"\n"
+ "resource:\n"
+ " attributes:\n"
+ " - name: service.name\n"
Expand All @@ -199,7 +199,7 @@ void configFile_Error(@TempDir Path tempDir) throws IOException {
Files.write(path, yaml.getBytes(StandardCharsets.UTF_8));
ConfigProperties config =
DefaultConfigProperties.createFromMap(
Collections.singletonMap("otel.experimental.config.file", path.toString()));
Collections.singletonMap("otel.config.file", path.toString()));

assertThatThrownBy(() -> AutoConfiguredOpenTelemetrySdk.builder().setConfig(config).build())
.isInstanceOf(ConfigurationException.class)
Expand All @@ -211,7 +211,7 @@ void configFile_Error(@TempDir Path tempDir) throws IOException {
void configFile_ConfigProvider() {
ConfigProperties config =
DefaultConfigProperties.createFromMap(
Collections.singletonMap("otel.experimental.config.file", configFilePath.toString()));
Collections.singletonMap("otel.config.file", configFilePath.toString()));

AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk =
AutoConfiguredOpenTelemetrySdk.builder().setConfig(config).setResultAsGlobal().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void setUp(@TempDir Path tempDir) throws IOException {

String endpoint = "http://localhost:" + server.httpPort();
String yaml =
"file_format: \"1.0-rc.1\"\n"
"file_format: \"1.0\"\n"
+ "resource:\n"
+ " attributes:\n"
+ " - name: service.name\n"
Expand Down Expand Up @@ -178,7 +178,7 @@ void setUp(@TempDir Path tempDir) throws IOException {
GlobalOpenTelemetry.resetForTest();
ConfigProperties config =
DefaultConfigProperties.createFromMap(
Collections.singletonMap("otel.experimental.config.file", path.toString()));
Collections.singletonMap("otel.config.file", path.toString()));
openTelemetrySdk =
AutoConfiguredOpenTelemetrySdk.builder()
.setConfig(config)
Expand Down
6 changes: 3 additions & 3 deletions sdk-extensions/incubator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Usage:
File yamlConfigFile = new File("/path/to/config.yaml");
OpenTelemetrySdk openTelemetrySdk;
try (FileInputStream yamlConfigFileInputStream = new FileInputStream("/path/to/config.yaml")) {
openTelemetrySdk = FileConfiguration.parseAndCreate(yamlConfigFileInputStream);
openTelemetrySdk = DeclarativeConfiguration.parseAndCreate(yamlConfigFileInputStream);
}
// ...proceed with application after successful initialization of OpenTelemetrySdk
```

Notes:
* Environment variable substitution is supported as [defined in the spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/data-model.md#environment-variable-substitution)
* Currently, there is no support for the customization (i.e. `AutoConfigurationCustomizerProvider`) SPIs defined in [opentelemetry-sdk-extension-autoconfigure-spi](../autoconfigure-spi).
* Customization is limited to customizing the in-memory config model, or exporters. See `DeclarativeConfigurationCustomizer` SPI for details.
* Custom SDK extension components which reference the [ComponentProvider](https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/autoconfigure-spi/src/main/java/io/opentelemetry/sdk/autoconfigure/spi/internal/ComponentProvider.java) SPI can be referenced in declarative configuration. Supported types include:
* `Resource`
* `SpanExporter`
Expand All @@ -29,7 +29,7 @@ Notes:
* `LogRecordProcessor`
* `TextMapPropagator`
* `Sampler`
* You can use declarative configuration with [autoconfigure](https://opentelemetry.io/docs/languages/java/configuration/#declarative-configuration) to specify a configuration file via environment variable, e.g. `OTEL_EXPERIMENTAL_CONFIG_FILE=/path/to/config.yaml`.
* You can use declarative configuration with [autoconfigure](https://opentelemetry.io/docs/languages/java/configuration/#declarative-configuration) to specify a configuration file via environment variable, e.g. `OTEL_CONFIG_FILE=/path/to/config.yaml`.

## View File Configuration

Expand Down
4 changes: 2 additions & 2 deletions sdk-extensions/incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
// 6. deleteJs2pTmp - delete tmp directory
// ... proceed with normal sourcesJar, compileJava, etc

val configurationTag = "1.0.0-rc.3"
val configurationTag = "1.0.0"
val configurationRef = "refs/tags/v$configurationTag" // Replace with commit SHA to point to experiment with a specific commit
val configurationRepoZip = "https://github.com/open-telemetry/opentelemetry-configuration/archive/$configurationRef.zip"
val buildDirectory = layout.buildDirectory.asFile.get()
Expand Down Expand Up @@ -212,7 +212,7 @@ tasks {
environment(
mapOf(
// Expose the kitchen sink example file to tests
"CONFIG_EXAMPLE_DIR" to "$buildDirectory/configuration/examples/"
"CONFIG_REPO_ROOT" to "$buildDirectory/configuration"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static class LoggerConfigFactory
public LoggerConfig create(
ExperimentalLoggerConfigModel model, DeclarativeConfigContext context) {
LoggerConfigBuilder configBuilder = LoggerConfig.builder();
if (model.getDisabled() != null && model.getDisabled()) {
if (model.getEnabled() != null && !model.getEnabled()) {
configBuilder.setEnabled(false);
}
if (model.getTraceBased() != null && model.getTraceBased()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static class MeterConfigFactory
@Override
public MeterConfig create(
ExperimentalMeterConfigModel model, DeclarativeConfigContext context) {
if (model.getDisabled() != null && model.getDisabled()) {
if (model.getEnabled() != null && !model.getEnabled()) {
return MeterConfig.disabled();
}
return MeterConfig.defaultConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class OpenTelemetryConfigurationFactory
private static final Logger logger =
Logger.getLogger(OpenTelemetryConfigurationFactory.class.getName());
private static final Pattern SUPPORTED_FILE_FORMATS = Pattern.compile("^(0.4)|(1.0(-rc.\\d*)?)$");
private static final String EXPECTED_FILE_FORMAT = "1.0-rc.3";
private static final String EXPECTED_FILE_FORMAT = "1.0";

private static final OpenTelemetryConfigurationFactory INSTANCE =
new OpenTelemetryConfigurationFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static class TracerConfigFactory
@Override
public TracerConfig create(
ExperimentalTracerConfigModel model, DeclarativeConfigContext context) {
if (model.getDisabled() != null && model.getDisabled()) {
if (model.getEnabled() != null && !model.getEnabled()) {
return TracerConfig.disabled();
}
return TracerConfig.defaultConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.cert.CertificateEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.event.Level;

class DeclarativeConfigurationCreateTest {
Expand All @@ -59,9 +66,10 @@ class DeclarativeConfigurationCreateTest {
* href="https://github.com/open-telemetry/opentelemetry-configuration/tree/main/examples">open-telemetry/opentelemetry-configuration/examples</a>
* can pass {@link DeclarativeConfiguration#parseAndCreate(InputStream)}.
*/
@Test
@ParameterizedTest
@MethodSource("exampleFiles")
@SuppressLogger(ParentBasedSamplerBuilder.class)
void parseAndCreate_Examples(@TempDir Path tempDir)
void parseAndCreate_Examples(File example, @TempDir Path tempDir)
throws IOException, CertificateEncodingException {
// Write certificates to temp files
String certificatePath =
Expand All @@ -73,39 +81,40 @@ void parseAndCreate_Examples(@TempDir Path tempDir)
createTempFileWithContent(
tempDir, "clientCertificate.cert", clientTls.certificate().getEncoded());

File examplesDir = new File(System.getenv("CONFIG_EXAMPLE_DIR"));
assertThat(examplesDir).isDirectory();

for (File example : Objects.requireNonNull(examplesDir.listFiles())) {
// Rewrite references to cert files in examples
String exampleContent =
new String(Files.readAllBytes(example.toPath()), StandardCharsets.UTF_8);
String rewrittenExampleContent =
exampleContent
// TODO: remove jaeger, ottrace workarounds after next release
.replaceAll(".*- jaeger:.*\n", "")
.replaceAll("jaeger", "")
.replaceAll(".*- ottrace:.*\n", "")
.replaceAll("ottrace", "")
.replaceAll(
"ca_file: .*\n",
"ca_file: " + certificatePath.replace("\\", "\\\\") + System.lineSeparator())
.replaceAll(
"key_file: .*\n",
"key_file: " + clientKeyPath.replace("\\", "\\\\") + System.lineSeparator())
.replaceAll(
"cert_file: .*\n",
"cert_file: "
+ clientCertificatePath.replace("\\", "\\\\")
+ System.lineSeparator());
InputStream is =
new ByteArrayInputStream(rewrittenExampleContent.getBytes(StandardCharsets.UTF_8));

// Verify that file can be parsed and interpreted without error
assertThatCode(() -> cleanup.addCloseable(DeclarativeConfiguration.parseAndCreate(is)))
.as("Example file: " + example.getName())
.doesNotThrowAnyException();
}
// Rewrite references to cert files in examples
String exampleContent =
new String(Files.readAllBytes(example.toPath()), StandardCharsets.UTF_8);
String rewrittenExampleContent =
exampleContent
.replaceAll(
"ca_file: .*\n",
"ca_file: " + certificatePath.replace("\\", "\\\\") + System.lineSeparator())
.replaceAll(
"key_file: .*\n",
"key_file: " + clientKeyPath.replace("\\", "\\\\") + System.lineSeparator())
.replaceAll(
"cert_file: .*\n",
"cert_file: "
+ clientCertificatePath.replace("\\", "\\\\")
+ System.lineSeparator());
InputStream is =
new ByteArrayInputStream(rewrittenExampleContent.getBytes(StandardCharsets.UTF_8));

// Verify that file can be parsed and interpreted without error
assertThatCode(() -> cleanup.addCloseable(DeclarativeConfiguration.parseAndCreate(is)))
.as("Example file: " + example.getName())
.doesNotThrowAnyException();
}

private static Stream<Arguments> exampleFiles() {
File configRepoRoot = new File(System.getenv("CONFIG_REPO_ROOT"));
File examplesDir = new File(configRepoRoot + "/examples/");
File snippetsDir = new File(configRepoRoot + "/snippets/");
List<File> examples = new ArrayList<>();
examples.addAll(Arrays.asList(Objects.requireNonNull(examplesDir.listFiles())));
examples.addAll(Arrays.asList(Objects.requireNonNull(snippetsDir.listFiles())));

return examples.stream().map(file -> Arguments.argumentSet(file.getName(), file));
}

@Test
Expand All @@ -114,7 +123,7 @@ void parseAndCreate_Exception_CleansUpPartials() {
// exporter with OTLP exporter, following by invalid batch exporter which references invalid
// exporter "foo".
String yaml =
"file_format: \"1.0-rc.3\"\n"
"file_format: \"1.0\"\n"
+ "logger_provider:\n"
+ " processors:\n"
+ " - batch:\n"
Expand All @@ -141,7 +150,7 @@ void parseAndCreate_Exception_CleansUpPartials() {
@Test
void parseAndCreate_EmptyComponentProviderConfig() {
String yaml =
"file_format: \"1.0-rc.3\"\n"
"file_format: \"1.0\"\n"
+ "logger_provider:\n"
+ " processors:\n"
+ " - test:\n"
Expand All @@ -159,7 +168,7 @@ void parseAndCreate_EmptyComponentProviderConfig() {
@Test
void create_ModelCustomizer() {
OpenTelemetryConfigurationModel model = new OpenTelemetryConfigurationModel();
model.withFileFormat("1.0-rc.3");
model.withFileFormat("1.0");
model.withTracerProvider(
new TracerProviderModel()
.withProcessors(
Expand Down
Loading
Loading