Skip to content

Commit a49c8c4

Browse files
jack-bergtrask
andauthored
Rebrand file configuration to declarative configuration (#512)
Co-authored-by: Trask Stalnaker <[email protected]>
1 parent 875431b commit a49c8c4

File tree

7 files changed

+35
-27
lines changed

7 files changed

+35
-27
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Declarative Configuration Example
2+
3+
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).
4+
5+
The configuration file is located at [otel-sdk-config.yaml](./otel-sdk-config.yaml).
6+
7+
# How to run
8+
9+
## Prerequisites
10+
11+
* Java 1.8
12+
13+
## Run
14+
15+
```shell script
16+
export OTEL_EXPERIMENTAL_CONFIG_FILE=$(pwd)/otel-sdk-config.yaml
17+
../gradlew run
18+
```
19+
20+
Observe how data is printed to the console as configured in [otel-sdk-config.yaml](./otel-sdk-config.yaml).
21+
22+
For use with the OpenTelemetry Java, see [Java Agent declarative configuration](../javaagent/README.md#declarative-configuration).

file-configuration/build.gradle.kts renamed to declarative-configuration/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id("application")
44
}
55

6-
description = "OpenTelemetry Example for File Configuration"
6+
description = "OpenTelemetry Example for Declarative Configuration"
77
val moduleName by extra { "io.opentelemetry.examples.fileconfig" }
88

99
dependencies {

file-configuration/otel-sdk-config.yaml renamed to declarative-configuration/otel-sdk-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# See https://github.com/open-telemetry/opentelemetry-configuration for details on schema and examples
2+
3+
# 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.
24
file_format: "0.1"
35

46
resource:
57
attributes:
6-
service.name: "file-configuration-example"
8+
- name: service.name
9+
value: file-configuration-example
710

811
tracer_provider:
912
processors:

file-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java renamed to declarative-configuration/src/main/java/io/opentelemetry/examples/fileconfig/Application.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public final class Application {
2626

2727
public static void main(String[] args) throws InterruptedException, IOException {
2828
// it is important to initialize your SDK as early as possible in your application's lifecycle
29-
InputStream is = Files.newInputStream(Paths.get(System.getenv("OTEL_CONFIG_FILE")));
29+
InputStream is =
30+
Files.newInputStream(Paths.get(System.getenv("OTEL_EXPERIMENTAL_CONFIG_FILE")));
3031
OpenTelemetrySdk openTelemetrySdk = FileConfiguration.parseAndCreate(is);
3132

3233
Tracer tracer = openTelemetrySdk.getTracer("io.opentelemetry.example");

file-configuration/README.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

javaagent/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ curl http://localhost:8080/ping
4545

4646
Watch for spans, metrics, and logs in the collector log output
4747

48-
## File Configuration
48+
## Declarative Configuration
4949

50-
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:
50+
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.
51+
52+
`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:
5153

5254
- Configuration of instrumentation (see `.instrumentation.java`)
5355
- Configuration of [rule based routing sampler](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/samplers) (see `.tracer_provider.sampler.parent_based.root`)
5456

55-
To use file configuration instead of the environment variable scheme, add the following before starting the application and collector:
57+
To use declarative configuration instead of the environment variable scheme, add the following before starting the application and collector:
5658

5759
```shell
5860
export OTEL_EXPERIMENTAL_CONFIG_FILE=/sdk-config.yaml

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ develocity {
4545
rootProject.name = "opentelemetry-java-examples"
4646
include(
4747
":opentelemetry-examples-autoconfigure",
48-
":opentelemetry-examples-file-configuration",
48+
":opentelemetry-examples-declarative-configuration",
4949
":opentelemetry-examples-http",
5050
":opentelemetry-examples-jaeger",
5151
":opentelemetry-examples-javaagent",

0 commit comments

Comments
 (0)