Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions declarative-configuration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Declarative Configuration Example

This example demonstrates how to use the [declarative configuration](https://opentelemetry.io/docs/specs/otel/configuration/#declarative-configuration) interface 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).
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
20 changes: 0 additions & 20 deletions file-configuration/README.md

This file was deleted.

8 changes: 5 additions & 3 deletions javaagent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading