opentelemetry-java-contrib/samplers
renovate[bot] 5a3c5f6cd1
fix(deps): update dependency io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha to v2.16.0-alpha (#1886)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Lauri Tulmin <ltulmin@splunk.com>
2025-05-16 14:36:50 +00:00
..
src fix(deps): update dependency io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha to v2.16.0-alpha (#1886) 2025-05-16 14:36:50 +00:00
README.md Add LogRecordProcessor to record event log records as span events (#1551) 2024-11-20 15:43:36 -08:00
build.gradle.kts Fix compilation errors due to declarative config breaking changes (#1784) 2025-03-14 09:17:53 -07:00

README.md

Samplers

Declarative configuration

The following samplers support declarative configuration:

  • RuleBasedRoutingSampler

To use:

  • Add a dependency on io.opentelemetry:opentelemetry-sdk-extension-incubator:<version>
  • Follow the instructions to configure OpenTelemetry with declarative configuration.
  • Configure the .tracer_provider.sampler to include the rule_based_routing sampler.

NOTE: Not yet available for use with the OTEL java agent, but should be in the near future. Please check back for updates.

Schema for rule_based_routing sampler:

# The fallback sampler to the use if the criteria is not met.
fallback_sampler:
  always_on:
# Filter to spans of this span_kind. Must be one of: SERVER, CLIENT, INTERNAL, CONSUMER, PRODUCER.
span_kind: SERVER   # only apply to server spans
# List of rules describing spans to drop. Spans are dropped if they match one of the rules.
rules:
  # The action to take when the rule is matches. Must be of: DROP, RECORD_AND_SAMPLE.
  - action: DROP
    # The span attribute to match against.
    attribute: url.path
    # The pattern to compare the span attribute to.
    pattern: /actuator.*

rule_based_routing sampler can be used anywhere a sampler is used in the configuration model. For example, the following YAML demonstrates a typical configuration, setting rule_based_routing sampler as the root sampler of parent_based sampler. In this configuration:

  • The parent_based sampler samples based on the sampling status of the parent.
  • Or, if there is no parent, delegates to the rule_based_routing sampler.
  • The rule_based_routing sampler drops spans where kind=SERVER and url.full matches /actuator.*, else it samples and records.
// ... the rest of the configuration file is omitted for brevity
// For more examples see: https://github.com/open-telemetry/opentelemetry-configuration/blob/main/README.md#starter-templates
tracer_provider:
  sampler:
    parent_based:
      # Configure the parent_based sampler's root sampler to be rule_based_routing sampler.
      root:
        rule_based_routing:
          # Fallback to the always_on sampler if the criteria is not met.
          fallback_sampler:
            always_on:
          # Only apply to SERVER spans.
          span_kind: SERVER
          rules:
            # Drop spans where url.path matches the regex /actuator.* (i.e. spring boot actuator endpoints).
            - action: DROP
              attribute: url.path
              pattern: /actuator.*

Component owners

Learn more about component owners in component_owners.yml.