diff --git a/declarative-configuration/README.md b/declarative-configuration/README.md new file mode 100644 index 000000000..059c9802b --- /dev/null +++ b/declarative-configuration/README.md @@ -0,0 +1,22 @@ +# Declarative Configuration Example + +This example demonstrates how to use [declarative configuration](https://opentelemetry.io/docs/specs/otel/configuration/#declarative-configuration) to configure the OpenTelemetry SDK using a YAML configuration file as defined in [opentelemetry-configuration](https://github.com/open-telemetry/opentelemetry-configuration). + +The configuration file is located at [otel-sdk-config.yaml](./otel-sdk-config.yaml). + +# How to run + +## Prerequisites + +* Java 1.8 + +## Run + +```shell script +export OTEL_EXPERIMENTAL_CONFIG_FILE=$(pwd)/otel-sdk-config.yaml +../gradlew run +``` + +Observe how data is printed to the console as configured in [otel-sdk-config.yaml](./otel-sdk-config.yaml). + +For use with the OpenTelemetry Java, see [Java Agent declarative configuration](../javaagent/README.md#declarative-configuration). diff --git a/file-configuration/build.gradle.kts b/declarative-configuration/build.gradle.kts similarity index 87% rename from file-configuration/build.gradle.kts rename to declarative-configuration/build.gradle.kts index 9867ae464..45bdb638d 100644 --- a/file-configuration/build.gradle.kts +++ b/declarative-configuration/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("application") } -description = "OpenTelemetry Example for File Configuration" +description = "OpenTelemetry Example for Declarative Configuration" val moduleName by extra { "io.opentelemetry.examples.fileconfig" } dependencies { diff --git a/file-configuration/otel-sdk-config.yaml b/declarative-configuration/otel-sdk-config.yaml similarity index 69% rename from file-configuration/otel-sdk-config.yaml rename to declarative-configuration/otel-sdk-config.yaml index 7b7727718..130c6058b 100644 --- a/file-configuration/otel-sdk-config.yaml +++ b/declarative-configuration/otel-sdk-config.yaml @@ -1,9 +1,12 @@ # See https://github.com/open-telemetry/opentelemetry-configuration for details on schema and examples + +# TODO: the current support file format is 0.3, but the opentelemetry-java errantly checks that it is 0.1. This will be fixed in 1.44.0. file_format: "0.1" resource: attributes: - service.name: "file-configuration-example" + - name: service.name + value: file-configuration-example tracer_provider: processors: diff --git a/file-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java b/declarative-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java similarity index 95% rename from file-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java rename to declarative-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java index 7547cdd50..6da275322 100644 --- a/file-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java +++ b/declarative-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java @@ -26,7 +26,8 @@ public final class Application { public static void main(String[] args) throws InterruptedException, IOException { // it is important to initialize your SDK as early as possible in your application's lifecycle - InputStream is = Files.newInputStream(Paths.get(System.getenv("OTEL_CONFIG_FILE"))); + InputStream is = + Files.newInputStream(Paths.get(System.getenv("OTEL_EXPERIMENTAL_CONFIG_FILE"))); OpenTelemetrySdk openTelemetrySdk = FileConfiguration.parseAndCreate(is); Tracer tracer = openTelemetrySdk.getTracer("io.opentelemetry.example"); diff --git a/file-configuration/README.md b/file-configuration/README.md deleted file mode 100644 index 74de44400..000000000 --- a/file-configuration/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# File Configuration Example - -This example demonstrates how to use a YAML configuration file as defined in [opentelemetry-configuration](https://github.com/open-telemetry/opentelemetry-configuration) to configure the OpenTelemetry SDK. - -The configuration file is located at [otel-sdk-config.yaml](./otel-sdk-config.yaml). - -# How to run - -## Prerequisites - -* Java 1.8 - -## Run - -```shell script -export OTEL_CONFIG_FILE=$(pwd)/otel-sdk-config.yaml -../gradlew run -``` - -Observe how data is printed to the console as configured in [otel-sdk-config.yaml](./otel-sdk-config.yaml). diff --git a/javaagent/README.md b/javaagent/README.md index cb994c2c9..1a93d96c8 100644 --- a/javaagent/README.md +++ b/javaagent/README.md @@ -45,14 +45,16 @@ curl http://localhost:8080/ping Watch for spans, metrics, and logs in the collector log output -## File Configuration +## Declarative Configuration -By default, this example uses the [environment variable configuration schema](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md) to configure the SDK. However, it also includes [sdk-config.yaml](./sdk-config.yaml) which demonstrates how the file configuration scheme can be used instead. `sdk-config.yaml` extends the [opentelemetry-configuration sdk-config.yaml](https://github.com/open-telemetry/opentelemetry-configuration/blob/v0.3.0/examples/sdk-config.yaml) template, demonstrating: +By default, this example uses the [environment variable configuration schema](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md) to configure the SDK. However, it also includes [sdk-config.yaml](./sdk-config.yaml) which demonstrates how the [declarative configuration](https://opentelemetry.io/docs/specs/otel/configuration/#declarative-configuration) scheme can be used to configure the SDK based on a YAML configuration file instead. + +`sdk-config.yaml` extends the [opentelemetry-configuration sdk-config.yaml](https://github.com/open-telemetry/opentelemetry-configuration/blob/v0.3.0/examples/sdk-config.yaml) template, demonstrating: - Configuration of instrumentation (see `.instrumentation.java`) - Configuration of [rule based routing sampler](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/samplers) (see `.tracer_provider.sampler.parent_based.root`) -To use file configuration instead of the environment variable scheme, add the following before starting the application and collector: +To use declarative configuration instead of the environment variable scheme, add the following before starting the application and collector: ```shell export OTEL_EXPERIMENTAL_CONFIG_FILE=/sdk-config.yaml diff --git a/settings.gradle.kts b/settings.gradle.kts index 3f482aada..02d232ef7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -45,7 +45,7 @@ develocity { rootProject.name = "opentelemetry-java-examples" include( ":opentelemetry-examples-autoconfigure", - ":opentelemetry-examples-file-configuration", + ":opentelemetry-examples-declarative-configuration", ":opentelemetry-examples-http", ":opentelemetry-examples-jaeger", ":opentelemetry-examples-javaagent",