How to Drop and Filter OpenTelemetry Metrics

This guide explains different methods to filter out or disable metrics in your OpenTelemetry instrumentation. You can either:

  • Filter metrics at the collector level using the OpenTelemetry Collector
  • Disable metrics generation at the SDK level for different programming languages

Filtering Metrics at the Collector Level

The filter processor in OpenTelemetry allows you to drop metrics based on their name, label values, or other attributes. This is useful if you want to exclude certain metrics from being sent to SigNoz while still collecting them at the source.

The filter processor is configured in the processors::filter section of the otel-collector-config.yaml file.

📝 Note

The processor needs to be added to the metrics pipeline to take effect.

metrics:
  receivers: [otlp]
  processors: [filter/drop_metrics_by_name, batch]
  exporters: [otlp]

Drop Metrics by Exact Name Match

You can drop specific metrics by their exact names:

processors:
  filter/drop_metrics_by_name:
    metrics:
      exclude:
        match_type: strict
        metric_names:
          - http.client.request.body.size
          - http.client.response.body.size

Drop Metrics by Pattern Match

You can use regular expressions to drop metrics matching a pattern:

processors:
  filter/drop_metrics_by_name_regex:
    metrics:
      exclude:
        match_type: regexp
        metric_names:
          - http.client.*

Drop Metrics by Resource Attributes

You can filter metrics based on resource attributes such as service.name, host.name, k8s.pod.name, etc:

processors:
  filter/drop_metrics_by_label_values:
    metrics:
      metric:
        - resource.attributes["k8s.pod.name"] == "test-pod"

Drop Metrics by Resource Attributes Pattern

You can use regular expressions to match resource attributes:

processors:
  filter/drop_metrics_by_label_values_regex:
    metrics:
      metric:
        - IsMatch(resource.attributes["k8s.pod.name"], "test-pod-.*")

Drop Metrics by Metric Attributes

You can filter metrics based on their attributes like http.method, message.operation, etc:

processors:
  filter/drop_metrics_by_label_values:
    metrics:
      datapoint:
        - attributes["http.method"] == "GET"

Drop Metrics by Metric Attributes Pattern

You can use regular expressions to match metric attributes:

processors:
  filter/drop_metrics_by_label_values_regex:
    metrics:
      datapoint:
        - IsMatch(attributes["http.method"], "GET|POST")

Refer to the OpenTelemetry documentation for more details on how to configure the filter processor.

Disabling SDK-Generated Metrics

In addition to filtering metrics at the collector level, you can also control metric generation at the SDK level. This can be particularly useful when you want to disable specific instrumentations or all metrics from your application.

Disable All Metrics

If you want to completely disable metrics collection from the SDK while keeping tracing/logging enabled, you can set:

OTEL_METRICS_EXPORTER=none

This environment variable will prevent the SDK from generating any metrics, reducing the resource usage of your application.

Disable Specific Instrumentations

To disable instruments from specific packages, you can use environment variables depending on your programming language:

# This will disable both traces and metrics from the system-metrics instrumentation
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=system-metrics

For more configuration options, see the Python SDK Configuration documentation.

Get Help

If you need help with the steps in this topic, please reach out to us on SigNoz Community Slack.

If you are a SigNoz Cloud user, please use in product chat support located at the bottom right corner of your SigNoz instance or contact us at cloud-support@signoz.io.

Was this page helpful?