Skip to content

Commit cb4f539

Browse files
committed
Use sdk-config.yaml, default to rule_based_routing sampler
1 parent cde4737 commit cb4f539

File tree

4 files changed

+254
-298
lines changed

4 files changed

+254
-298
lines changed

javaagent/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +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-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:
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-config.yaml) template, demonstrating:
5151

5252
- 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`)
53+
- Configuration of [rule based routing sampler](https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/samplers) (see `.tracer_provider.sampler.parent_based.root`)
5454

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

5757
```shell
58-
export OTEL_EXPERIMENTAL_CONFIG_FILE=/sdk-migration-config.yaml
58+
export OTEL_EXPERIMENTAL_CONFIG_FILE=/sdk-config.yaml
5959
```
6060

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.
61+
Note: toggling declarative configuration causes the env var configuration scheme to be ignored completely. However, there is support for [env var substitution](https://opentelemetry.io/docs/specs/otel/configuration/data-model/#environment-variable-substitution) within configuration files.

javaagent/docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ services:
1010
# Logs are disabled by default
1111
OTEL_LOGS_EXPORTER: "otlp"
1212
# Optional specify file configuration instead of using environment variable scheme
13-
# To use, call "export OTEL_EXPERIMENTAL_CONFIG_FILE=/sdk-migration-config.yaml" before calling docker compose up
14-
OTEL_EXPERIMENTAL_CONFIG_FILE: /sdk-migration-config.yaml
13+
# To use, call "export OTEL_EXPERIMENTAL_CONFIG_FILE=/sdk-config.yaml" before calling docker compose up
14+
OTEL_EXPERIMENTAL_CONFIG_FILE:
1515
ports:
1616
- "8080:8080"
1717
volumes:
18-
- ./sdk-migration-config.yaml:/sdk-migration-config.yaml
18+
- ./sdk-config.yaml:/sdk-config.yaml
1919
depends_on:
2020
- collector
2121
collector:

javaagent/sdk-config.yaml

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
# Copy of https://github.com/open-telemetry/opentelemetry-configuration/blob/v0.3.0/examples/sdk-config.yaml
2+
# with the following changes:
3+
# - OpenTelemetry Java Agent properties added at .instrumentation.java.
4+
# - OTLP exporter endpoints modified to point to http://collector:4318/v1/{path} to export to collector from docker-compose.yml
5+
# - .tracer_provider.sampler.parent_based.root set to rule_based_routing sampler to demonstrate turning off sampling for spring boot actuator endpoints.
6+
7+
#
8+
# sdk-config.yaml is a typical starting point for configuring the SDK, including exporting to
9+
# localhost via OTLP.
10+
11+
# NOTE: With the exception of env var substitution syntax (i.e. ${MY_ENV}), SDKs ignore
12+
# environment variables when interpreting config files. This including ignoring all env
13+
# vars defined in https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/.
14+
15+
# The file format version.
16+
# 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.
17+
file_format: "0.1"
18+
19+
# Configure if the SDK is disabled or not. This is not required to be provided to ensure the SDK isn't disabled, the default value when this is not provided is for the SDK to be enabled.
20+
disabled: false
21+
22+
# Configure resource for all signals.
23+
resource:
24+
# Configure resource attributes. Entries have higher priority than entries from .resource.attributes_list.
25+
# Entries must contain .name nand .value, and may optionally include .type, which defaults ot "string" if not set. The value must match the type. Values for .type include: string, bool, int, double, string_array, bool_array, int_array, double_array.
26+
attributes:
27+
- name: service.name
28+
value: unknown_service
29+
30+
# Configure general attribute limits. See also tracer_provider.limits, logger_provider.limits.
31+
attribute_limits:
32+
# Configure max attribute value size.
33+
attribute_value_length_limit:
34+
# Configure max attribute count.
35+
attribute_count_limit: 128
36+
37+
# Configure text map context propagators.
38+
propagator:
39+
# Configure the set of propagators to include in the composite text map propagator.
40+
composite: [ tracecontext, baggage ]
41+
42+
# Configure tracer provider.
43+
tracer_provider:
44+
# Configure span processors.
45+
processors:
46+
- # Configure a batch span processor.
47+
batch:
48+
# Configure delay interval (in milliseconds) between two consecutive exports.
49+
schedule_delay: 5000
50+
# Configure maximum allowed time (in milliseconds) to export data.
51+
export_timeout: 30000
52+
# Configure maximum queue size.
53+
max_queue_size: 2048
54+
# Configure maximum batch size.
55+
max_export_batch_size: 512
56+
# Configure exporter.
57+
exporter:
58+
# Configure exporter to be OTLP.
59+
otlp:
60+
# Configure protocol.
61+
protocol: http/protobuf
62+
# Configure endpoint.
63+
endpoint: http://collector:4318/v1/traces
64+
# Configure certificate.
65+
certificate:
66+
# Configure mTLS private client key.
67+
client_key:
68+
# Configure mTLS client certificate.
69+
client_certificate:
70+
# Configure compression.
71+
compression: gzip
72+
# Configure max time (in milliseconds) to wait for each export.
73+
timeout: 10000
74+
# Configure headers. Entries have higher priority than entries from .headers_list.
75+
headers: []
76+
# Configure span limits. See also attribute_limits.
77+
limits:
78+
# Configure max attribute value size. Overrides .attribute_limits.attribute_value_length_limit.
79+
attribute_value_length_limit: # Configure max span attribute count. Overrides attribute_limits.attribute_count_limit.
80+
# Configure max attribute count. Overrides .attribute_limits.attribute_count_limit.
81+
attribute_count_limit: 128
82+
# Configure max span event count.
83+
event_count_limit: 128
84+
# Configure max span link count.
85+
link_count_limit: 128
86+
# Configure max attributes per span event.
87+
event_attribute_count_limit: 128
88+
# Configure max attributes per span link.
89+
link_attribute_count_limit: 128
90+
# Configure the sampler.
91+
sampler:
92+
# Configure sampler to be parent_based.
93+
parent_based:
94+
# Configure the parent_based sampler's root sampler to be rule_based_routing sampler from https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/samplers.
95+
root:
96+
rule_based_routing:
97+
# Fallback to the always_on sampler if the criteria is not met.
98+
fallback_sampler:
99+
always_on:
100+
# Only apply to SERVER spans.
101+
span_kind: SERVER
102+
rules:
103+
# Drop spans where url.path matches the regex /actuator.* (i.e. spring boot actuator endpoints).
104+
- action: DROP
105+
attribute: url.path
106+
pattern: /actuator.*
107+
# Configure remote_parent_sampled sampler.
108+
remote_parent_sampled:
109+
# Configure sampler to be always_on.
110+
always_on: {}
111+
# Configure remote_parent_not_sampled sampler.
112+
remote_parent_not_sampled:
113+
# Configure sampler to be always_off.
114+
always_off: {}
115+
# Configure local_parent_sampled sampler.
116+
local_parent_sampled:
117+
# Configure sampler to be always_on.
118+
always_on: {}
119+
# Configure local_parent_not_sampled sampler.
120+
local_parent_not_sampled:
121+
# Configure sampler to be always_off.
122+
always_off: {}
123+
124+
# Configure meter provider.
125+
meter_provider:
126+
# Configure metric readers.
127+
readers:
128+
- # Configure a periodic metric reader.
129+
periodic:
130+
# Configure delay interval (in milliseconds) between start of two consecutive exports.
131+
interval: 60000
132+
# Configure maximum allowed time (in milliseconds) to export data.
133+
timeout: 30000
134+
# Configure exporter.
135+
exporter:
136+
# Configure exporter to be OTLP.
137+
otlp:
138+
# Configure protocol.
139+
protocol: http/protobuf
140+
# Configure endpoint.
141+
endpoint: http://collector:4318/v1/metrics
142+
# Configure certificate.
143+
certificate:
144+
# Configure mTLS private client key.
145+
client_key:
146+
# Configure mTLS client certificate.
147+
client_certificate:
148+
# Configure compression.
149+
compression: gzip
150+
# Configure max time (in milliseconds) to wait for each export.
151+
timeout: 10000
152+
# Configure headers. Entries have higher priority than entries from .headers_list.
153+
headers: []
154+
# Configure temporality preference.
155+
temporality_preference: cumulative
156+
# Configure default histogram aggregation.
157+
default_histogram_aggregation: explicit_bucket_histogram
158+
159+
# Configure logger provider.
160+
logger_provider:
161+
# Configure log record processors.
162+
processors:
163+
- # Configure a batch log record processor.
164+
batch:
165+
# Configure delay interval (in milliseconds) between two consecutive exports.
166+
schedule_delay: 1000
167+
# Configure maximum allowed time (in milliseconds) to export data.
168+
export_timeout: 30000
169+
# Configure maximum queue size.
170+
max_queue_size: 2048
171+
# Configure maximum batch size.
172+
max_export_batch_size: 512
173+
# Configure exporter.
174+
exporter:
175+
# Configure exporter to be OTLP.
176+
otlp:
177+
# Configure protocol.
178+
protocol: http/protobuf
179+
# Configure endpoint.
180+
endpoint: http://collector:4318/v1/logs
181+
# Configure certificate.
182+
certificate:
183+
# Configure mTLS private client key.
184+
client_key:
185+
# Configure mTLS client certificate.
186+
client_certificate:
187+
# Configure compression.
188+
compression: gzip
189+
# Configure max time (in milliseconds) to wait for each export.
190+
timeout: 10000
191+
# Configure headers. Entries have higher priority than entries from .headers_list.
192+
headers: []
193+
# Configure log record limits. See also attribute_limits.
194+
limits:
195+
# Configure max attribute value size. Overrides .attribute_limits.attribute_value_length_limit.
196+
attribute_value_length_limit: # Configure max log record attribute count. Overrides attribute_limits.attribute_count_limit.
197+
# Configure max attribute count. Overrides .attribute_limits.attribute_count_limit.
198+
attribute_count_limit: 128
199+
200+
201+
# Configure instrumentation.
202+
instrumentation:
203+
# Configure OpenTelemetry Java Agent. A standard translation process is applied to convert the
204+
# flat system properties / env var configuration scheme from https://opentelemetry.io/docs/zero-code/java/agent/
205+
# to the structured scheme used by declarative configuration:
206+
#
207+
# - Resolve properties starting with "otel.instrumentation."
208+
# - Strip the "otel.instrumentation." prefix.
209+
# - Split the remaining property string on "." character to break into segments
210+
# - Starting at .instrumentation.java, follow N-1 segments to resolve the leaf node to read the property from
211+
# - Read segment N from the resolved leaf node
212+
#
213+
# For example, the property "otel.instrumentation.common.default-enabled" is resolved by
214+
# reading: .instrumentation.java.common.default-enabled
215+
#
216+
# Some system properties / env vars cannot be configured via declarative configuration, normally
217+
# because they are resolved in the application lifecycle before declarative configuration is
218+
# available. The set of unsupported properties includes:
219+
# - otel.javaagent.enabled
220+
# - otel.javaagent.configuration-file
221+
# - otel.javaagent.extensions
222+
# - otel.javaagent.logging
223+
# - otel.resource.providers.[provider].enabled
224+
#
225+
# A sample set of OpenTelemetry Java Agent are shown below, with env var substitution references
226+
# reflecting agent defaults. For properties that are not referenced, consult the translation
227+
# steps discussed above.
228+
java:
229+
common:
230+
default-enabled: true
231+
# Configuration logback-appender instrumentation. Properties adapted from:
232+
# https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/java-util-logging/javaagent
233+
java-util-logging:
234+
enabled: true
235+
experimental-log-attributes: false
236+
# Configuration logback-appender instrumentation. Properties adapted from:
237+
# https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/logback/logback-appender-1.0/javaagent
238+
logback-appender:
239+
enabled: true
240+
experimental-log-attributes: false
241+
experimental:
242+
capture-code-attributes: false
243+
capture-marker-attributes: false
244+
capture-key-value-pair-attributes: false
245+
capture-logger-context-attributes: false
246+
capture-arguments: false
247+
capture-mdc-attributes: false

0 commit comments

Comments
 (0)