Skip to content

Commit 3389f08

Browse files
authored
improve javaagent declarative config example (#912)
1 parent 5007198 commit 3389f08

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ To build the all of examples, run:
8686
OpenTelemetry SDK to use a Zipkin exporter and send spans to a
8787
Zipkin backend using the OpenTelemetry API.
8888
- Note: This example requires Docker to be installed.
89+
- [Declarative Configuration with the OpenTelemetry Java Agent](javaagent-declarative-configuration)
90+
- This module demonstrates how to use declarative configuration with the
91+
OpenTelemetry Java Agent to configure tracing behavior, including
92+
excluding specific endpoints from tracing.
93+
- Note: This example requires Java 17 or higher.
8994

9095
## Contributing
9196

javaagent-declarative-configuration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This Spring Boot application includes two endpoints:
1111
## End-to-End Instructions
1212

1313
### Prerequisites
14-
* Java 17 or higher
14+
* Java 17 or higher (due to Spring Boot 3 requirement, not because of declarative config support)
1515
* OpenTelemetry Java Agent JAR file (see next step)
1616

1717
Download the OpenTelemetry Java Agent:

javaagent-declarative-configuration/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ plugins {
99
description = "OpenTelemetry Java Agent Declarative Configuration Example"
1010
val moduleName by extra { "io.opentelemetry.examples.javaagent.declarative" }
1111

12+
java {
13+
toolchain {
14+
languageVersion.set(JavaLanguageVersion.of(17))
15+
}
16+
}
17+
1218
dependencies {
1319
implementation(platform(SpringBootPlugin.BOM_COORDINATES))
1420
implementation("org.springframework.boot:spring-boot-starter-web")

javaagent-declarative-configuration/oats/docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ services:
77
environment:
88
OTEL_SERVICE_NAME: "declarative-config-example-app"
99
OTEL_EXPORTER_OTLP_ENDPOINT: http://lgtm:4318
10-
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: http://lgtm:4318/v1/traces
11-
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
1210
ports:
1311
- "8080:8080"
1412
healthcheck:
1513
test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
1614
interval: 10s
1715
timeout: 5s
18-
retries: 3
16+
retries: 3

javaagent-declarative-configuration/otel-agent-config.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1-
# See https://github.com/open-telemetry/opentelemetry-configuration for details on schema and examples
1+
# For schema documentation, including required properties, semantics, default behavior, etc,
2+
# see: https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema-docs.md
23

34
file_format: "1.0-rc.2"
45

56
resource:
67
attributes:
78
- name: service.name
89
value: spring-boot-declarative-config-example
10+
# Read resource attributes from the OTEL_RESOURCE_ATTRIBUTES environment variable.
11+
# This aligns well with the OpenTelemetry Operator and other deployment methods.
12+
attributes_list: ${OTEL_RESOURCE_ATTRIBUTES}
13+
detection/development: # /development properties may not be supported in all SDKs
14+
detectors:
15+
- service: # will add "service.instance.id" and "service.name" from the OTEL_SERVICE_NAME env var
16+
- host:
17+
- process:
18+
- container:
919

1020
propagator:
1121
composite:
1222
- tracecontext:
1323
- baggage:
1424

25+
# Read backend endpoint from the OTEL_EXPORTER_OTLP_ENDPOINT environment variable.
26+
# This aligns well with the OpenTelemetry Operator and other deployment methods.
27+
1528
tracer_provider:
1629
processors:
1730
- batch:
1831
exporter:
1932
otlp_http:
20-
endpoint: ${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT:-http://localhost:4318/v1/traces}
33+
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/traces
2134

2235
# Configure a console exporter for exploring without a collector/backend
2336
- batch:
@@ -45,11 +58,11 @@ meter_provider:
4558
- periodic:
4659
exporter:
4760
otlp_http:
48-
endpoint: ${OTEL_EXPORTER_OTLP_METRICS_ENDPOINT:-http://localhost:4318/v1/metrics}
61+
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/metrics
4962

5063
logger_provider:
5164
processors:
5265
- batch:
5366
exporter:
5467
otlp_http:
55-
endpoint: ${OTEL_EXPORTER_OTLP_LOGS_ENDPOINT:-http://localhost:4318/v1/logs}
68+
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/logs

0 commit comments

Comments
 (0)