opentelemetry-java-contrib icon indicating copy to clipboard operation
opentelemetry-java-contrib copied to clipboard

[Samplers] How to drop multiple span_kinds

Open bwcxyk opened this issue 2 months ago • 2 comments

Component(s)

samplers

Is your feature request related to a problem? Please describe.

span_kind: SERVER

tracer_provider:
  sampler:
    parent_based:
      root:
        rule_based_routing:
          fallback_sampler:
            always_on:
          span_kind: SERVER
          rules:
            - action: DROP
              attribute: url.path
              pattern: /health.*
            - action: DROP
              attribute: url.path
              pattern: /actuator.*

I want to drop the redis heartbeat, I don't know if it's supported.

            - action: DROP
              attribute: db.statement
              pattern: ^PING$
            - action: DROP
              attribute: db.statement
              pattern: ^QUIT$

Describe the solution you'd like

I looked at https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/cel-sampler, is it necessary to add the CEL-Based sampler to the extension?

Describe alternatives you've considered

No response

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

bwcxyk avatar Dec 03 '25 03:12 bwcxyk

I think you could do something like:

tracer_provider:
  sampler:
    parent_based:
      root:
        rule_based_routing:
          fallback_sampler:
            rule_based_routing:
              fallback_sampler:
                always_on:
              span_kind: CLIENT
              rules:
                - action: DROP
                  attribute: db.statement
                  pattern: ^PING$
                - action: DROP
                  attribute: db.statement
                  pattern: ^QUIT$
          span_kind: SERVER
          rules:
            - action: DROP
              attribute: url.path
              pattern: /health.*
            - action: DROP
              attribute: url.path
              pattern: /actuator.*

I looked at https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/cel-sampler, is it necessary to add the CEL-Based sampler to the extension?

yes, though that module could be enhanced to publish a shaded jar that can be used directly as an extension similar to https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/gcp-auth-extension#with-opentelemetry-java-agent

trask avatar Dec 03 '25 19:12 trask

Thank you, the result was as expected.

bwcxyk avatar Dec 08 '25 02:12 bwcxyk