open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.09k stars 2.38k forks source link

Filtering Tracing on v0.109.0 #36409

Open baikunthasahoo opened 1 hour ago

baikunthasahoo commented 1 hour ago

Component(s)

processor/filter

Describe the issue you're reporting

Hi Team,

I am trying to exclude spans in the OpenTelemetry Collector using the filterprocessor. Specifically, I need to exclude spans where the next.route attribute matches the following values:

/api/healthz /[locale]/api/healthz (where [locale] is dynamic, e.g., /en, /fr, etc.) Despite configuring the filterprocessor with a regular expression, I am still seeing these spans in the traces. Below are the steps, configurations, and behaviors observed.

filter/exclude-health-api-traces: spans: exclude: match_type: regexp attributes:

I need your support on above query

Note: I have deployed my application in Kubernetes and used health probes for every 10sc. my application send data to collector as daemonset from otel collector i am exporting my traces.

github-actions[bot] commented 1 hour ago

Pinging code owners:

bacherfl commented 16 minutes ago

Hi @baikunthasahoo!

Can you check whether something like the following config may help you to achieve this? This makes use of the IsMatch OTTL function:

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
processors:
  filter:
    traces:
      span:
        - 'IsMatch(attributes["http.target"], ".*\\/api\\/healthz.*")'

exporters:
  debug:
    verbosity: detailed

service:

  pipelines:
    traces:
      receivers: [otlp]
      processors: [filter]
      exporters: [debug]

With this config, the following span was filtered as expected:

telemetrygen traces --otlp-insecure --traces 1 --status-code Ok --span-duration 1s --telemetry-attributes http.target=\"/api/healthz\"
baikunthasahoo commented 8 minutes ago

@bacherfl

Thanks for your quick support. Here i want suppress the /api/healthz noise. Does above example will suppress the ./api/healthz. ?

bacherfl commented 6 minutes ago

Yes, this configuration will filter out all spans with the http.target attribute set to /api/healthz