diff --git a/README.md b/README.md index 7a35020f0b..3833dfda0a 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,11 @@ To build the all of examples, run: OpenTelemetry SDK to use a Zipkin exporter and send spans to a Zipkin backend using the OpenTelemetry API. - Note: This example requires Docker to be installed. +- [Declarative Configuration with the OpenTelemetry Java Agent](javaagent-declarative-configuration) + - This module demonstrates how to use declarative configuration with the + OpenTelemetry Java Agent to configure tracing behavior, including + excluding specific endpoints from tracing. + - Note: This example requires Java 17 or higher. ## Contributing diff --git a/javaagent-declarative-configuration/README.md b/javaagent-declarative-configuration/README.md index 1cd1c1d69e..cf7cef2d91 100644 --- a/javaagent-declarative-configuration/README.md +++ b/javaagent-declarative-configuration/README.md @@ -11,7 +11,7 @@ This Spring Boot application includes two endpoints: ## End-to-End Instructions ### Prerequisites -* Java 17 or higher +* Java 17 or higher (due to Spring Boot 3 requirement, not because of declarative config support) * OpenTelemetry Java Agent JAR file (see next step) Download the OpenTelemetry Java Agent: diff --git a/javaagent-declarative-configuration/build.gradle.kts b/javaagent-declarative-configuration/build.gradle.kts index 0e763a3014..c5ae12a7a5 100644 --- a/javaagent-declarative-configuration/build.gradle.kts +++ b/javaagent-declarative-configuration/build.gradle.kts @@ -9,6 +9,12 @@ plugins { description = "OpenTelemetry Java Agent Declarative Configuration Example" val moduleName by extra { "io.opentelemetry.examples.javaagent.declarative" } +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} + dependencies { implementation(platform(SpringBootPlugin.BOM_COORDINATES)) implementation("org.springframework.boot:spring-boot-starter-web") diff --git a/javaagent-declarative-configuration/oats/docker-compose.yml b/javaagent-declarative-configuration/oats/docker-compose.yml index 4270de8304..e46e49106f 100644 --- a/javaagent-declarative-configuration/oats/docker-compose.yml +++ b/javaagent-declarative-configuration/oats/docker-compose.yml @@ -7,12 +7,10 @@ services: environment: OTEL_SERVICE_NAME: "declarative-config-example-app" OTEL_EXPORTER_OTLP_ENDPOINT: http://lgtm:4318 - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: http://lgtm:4318/v1/traces - OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf ports: - "8080:8080" healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"] interval: 10s timeout: 5s - retries: 3 \ No newline at end of file + retries: 3 diff --git a/javaagent-declarative-configuration/otel-agent-config.yaml b/javaagent-declarative-configuration/otel-agent-config.yaml index 25ae696e7c..7645e96df0 100644 --- a/javaagent-declarative-configuration/otel-agent-config.yaml +++ b/javaagent-declarative-configuration/otel-agent-config.yaml @@ -1,4 +1,5 @@ -# See https://github.com/open-telemetry/opentelemetry-configuration for details on schema and examples +# For schema documentation, including required properties, semantics, default behavior, etc, +# see: https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema-docs.md file_format: "1.0-rc.2" @@ -6,18 +7,30 @@ resource: attributes: - name: service.name value: spring-boot-declarative-config-example + # Read resource attributes from the OTEL_RESOURCE_ATTRIBUTES environment variable. + # This aligns well with the OpenTelemetry Operator and other deployment methods. + attributes_list: ${OTEL_RESOURCE_ATTRIBUTES} + detection/development: # /development properties may not be supported in all SDKs + detectors: + - service: # will add "service.instance.id" and "service.name" from the OTEL_SERVICE_NAME env var + - host: + - process: + - container: propagator: composite: - tracecontext: - baggage: +# Read backend endpoint from the OTEL_EXPORTER_OTLP_ENDPOINT environment variable. +# This aligns well with the OpenTelemetry Operator and other deployment methods. + tracer_provider: processors: - batch: exporter: otlp_http: - endpoint: ${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:-http://localhost:4318/v1/traces} + endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/traces # Configure a console exporter for exploring without a collector/backend - batch: @@ -45,11 +58,11 @@ meter_provider: - periodic: exporter: otlp_http: - endpoint: ${OTEL_EXPORTER_OTLP_METRICS_ENDPOINT:-http://localhost:4318/v1/metrics} + endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/metrics logger_provider: processors: - batch: exporter: otlp_http: - endpoint: ${OTEL_EXPORTER_OTLP_LOGS_ENDPOINT:-http://localhost:4318/v1/logs} + endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/logs