Skip to content

Commit 136a4d8

Browse files
committed
Add extension with rule based routing sampler
1 parent e72a958 commit 136a4d8

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

javaagent/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ FROM eclipse-temurin:11-jre
22

33
ADD build/libs/app.jar /app.jar
44
ADD build/agent/opentelemetry-javaagent.jar /opentelemetry-javaagent.jar
5+
ADD build/agent/opentelemetry-javaagent-extension.jar /opentelemetry-javaagent-extension.jar
56

6-
ENTRYPOINT java -jar -javaagent:/opentelemetry-javaagent.jar /app.jar
7+
ENTRYPOINT java -jar -javaagent:/opentelemetry-javaagent.jar -Dotel.javaagent.extensions=/opentelemetry-javaagent-extension.jar /app.jar

javaagent/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ Watch for spans, metrics, and logs in the collector log output
4747

4848
## File 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` demonstrates view configuration to disable a metric, something which is not available in the environment variable configuration scheme.
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-migration-config.yaml](./sdk-migration-config.yaml) which demonstrates how the file configuration scheme can be used instead. `sdk-migration-config.yaml` extends the [opentelemetry-configuration sdk-migration-config.yaml](https://github.com/open-telemetry/opentelemetry-configuration/blob/v0.3.0/examples/sdk-migration-config.yaml) template, demonstrating:
51+
52+
- Configuration of instrumentation (see `.instrumentation.java`)
53+
- Configuration of [rule based routing sampler](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/samplers) (see `.tracer_provider.sampler`)
5154

5255
To use file configuration instead of the environment variable scheme, add the following before starting the application and collector:
5356

5457
```shell
5558
export OTEL_EXPERIMENTAL_CONFIG_FILE=/sdk-migration-config.yaml
5659
```
5760

58-
Note that toggling file configuration causes the environment variable configuration scheme to be ignored completely. However, there is support for environment variable substitution within configuration files.
61+
Note besides the environment variables referenced in `sdk-migration-config.yaml` using [substitution syntax](https://opentelemetry.io/docs/specs/otel/configuration/data-model/#environment-variable-substitution), environment variables are ignored.

javaagent/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ java {
1616
}
1717

1818
val agent = configurations.create("agent")
19+
val extension = configurations.create("extension")
1920

2021
dependencies {
2122
implementation(platform(SpringBootPlugin.BOM_COORDINATES))
2223
implementation("io.opentelemetry:opentelemetry-api")
2324

2425
//spring modules
2526
implementation("org.springframework.boot:spring-boot-starter-web")
27+
implementation("org.springframework.boot:spring-boot-starter-actuator")
2628

2729
agent("io.opentelemetry.javaagent:opentelemetry-javaagent:2.9.0")
30+
extension("io.opentelemetry.contrib:opentelemetry-samplers:1.40.0-alpha")
2831
}
2932

3033
val copyAgent = tasks.register<Copy>("copyAgent") {
@@ -33,9 +36,19 @@ val copyAgent = tasks.register<Copy>("copyAgent") {
3336
rename("opentelemetry-javaagent-.*\\.jar", "opentelemetry-javaagent.jar")
3437
}
3538

39+
val copyExtension = tasks.register<Copy>("copyExtension") {
40+
from(extension.files) {
41+
include("opentelemetry-samplers-*.jar")
42+
exclude("*sources.jar")
43+
exclude("*javadoc.jar")
44+
}
45+
into(layout.buildDirectory.dir("agent"))
46+
rename(".*\\.jar", "opentelemetry-javaagent-extension.jar")
47+
}
3648

3749
tasks.named<BootJar>("bootJar") {
3850
dependsOn(copyAgent)
51+
dependsOn(copyExtension)
3952

4053
archiveFileName = "app.jar"
4154
}

javaagent/sdk-migration-config.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# NOTE: With the exception of env var substitution syntax, SDKs ignore environment variables
1414
# when interpreting config files. For example, if "disabled: ${OTEL_SDK_DISABLED:-false}"
1515
# is replaced with "disabled: false", then setting the env var OTEL_SDK_DISABLED will have
16-
# no effect. See https://opentelemetry.io/docs/specs/otel/configuration/file-configuration/
16+
# no effect. See https://opentelemetry.io/docs/specs/otel/configuration/data-model/#file-based-configuration-model
1717
# for more information. The following spec defined env vars are NOT referenced and are thus
1818
# ignored:
1919
#
@@ -143,6 +143,22 @@ tracer_provider:
143143
local_parent_not_sampled:
144144
# Configure sampler to be always_off.
145145
always_off: {}
146+
# Uncomment to configure the rule_based_routing sampler from https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/samplers
147+
# to drop spans to spring actuator endpoints.
148+
# Configure the parent_based sampler's root sampler to be rule_based_routing sampler.
149+
# root:
150+
# rule_based_routing:
151+
# # Fallback to the always_on sampler if the criteria is not met.
152+
# fallback_sampler:
153+
# always_on:
154+
# # Only apply to SERVER spans.
155+
# span_kind: SERVER
156+
# rules:
157+
# # Drop spans where url.path matches the regex /actuator.* (i.e. spring boot actuator endpoints).
158+
# - action: DROP
159+
# attribute: url.path
160+
# pattern: /actuator.*
161+
146162

147163
# Configure meter provider.
148164
meter_provider:
@@ -256,8 +272,11 @@ instrumentation:
256272
java:
257273
common:
258274
default-enabled: ${OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED:-true}
275+
# Configuration logback-appender instrumentation. Properties adapted from:
276+
# https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/java-util-logging/javaagent
259277
java-util-logging:
260278
enabled: ${OTEL_INSTRUMENTATION_JAVA_UTIL_LOGGING_ENABLED:-true}
279+
experimental-log-attributes: ${OTEL_INSTRUMENTATION_LOGBACK_APPENDER_EXPERIMENTAL_LOG_ATTRIBUTES:-false}
261280
# Configuration logback-appender instrumentation. Properties adapted from:
262281
# https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/logback/logback-appender-1.0/javaagent
263282
logback-appender:

0 commit comments

Comments
 (0)