Skip to content

fix: Add null checks for span filtering attributes#849

Merged
CagriYonca merged 1 commit intomainfrom
fix/span-filtering
Mar 11, 2026
Merged

fix: Add null checks for span filtering attributes#849
CagriYonca merged 1 commit intomainfrom
fix/span-filtering

Conversation

@CagriYonca
Copy link
Contributor

Reproduced and fixed the errors below for the case where http.host is None

  • Before the fix
2026-03-11 13:45:01,464: 14999 DEBUG instana: Flask(blinker): Applying flask before/after instrumentation funcs
2026-03-11 13:45:01,465: 14999 DEBUG instana: urllib3 _collect_kvs error: 
Traceback (most recent call last):
  File "/Users/cagriyonca/Projects/pep0249/python-sensor/src/instana/instrumentation/urllib3.py", line 58, in _collect_kvs
    url = kvs["host"] + ":" + str(kvs["port"]) + kvs["path"]
          ~~~~~~~~~~~~^~~~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
127.0.0.1 - - [11/Mar/2026 13:45:01] "GET /test-urllib3-none-host HTTP/1.1" 500 -
2026-03-11 13:45:01,859: 14999 DEBUG instana: report_data_payload: Instana host agent connection error (<class 'TypeError'>)
Traceback (most recent call last):
  File "/Users/cagriyonca/Projects/pep0249/python-sensor/src/instana/agent/host.py", line 287, in report_data_payload
    response = self.report_spans(payload)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cagriyonca/Projects/pep0249/python-sensor/src/instana/agent/host.py", line 346, in report_spans
    filtered_spans = self.filter_spans(payload.get("spans", []))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cagriyonca/Projects/pep0249/python-sensor/src/instana/agent/host.py", line 389, in filter_spans
    if self.__is_endpoint_ignored(attributes_to_check):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cagriyonca/Projects/pep0249/python-sensor/src/instana/agent/host.py", line 411, in __is_endpoint_ignored
    if any(
       ^^^^
  File "/Users/cagriyonca/Projects/pep0249/python-sensor/src/instana/agent/host.py", line 412, in <genexpr>
    matches_rule(rule.get("attributes", []), span_attributes)
  File "/Users/cagriyonca/Projects/pep0249/python-sensor/src/instana/util/span_utils.py", line 42, in matches_rule
    if match_key_filter(span_value, rule_value, match_type):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cagriyonca/Projects/pep0249/python-sensor/src/instana/util/span_utils.py", line 58, in match_key_filter
    elif match_type == "contains" and rule_value in span_value:
                                      ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable
  • After the fix
2026-03-11 14:05:28,947: 20582 DEBUG instana: Flask(blinker): Applying flask before/after instrumentation funcs
127.0.0.1 - - [11/Mar/2026 14:05:28] "GET /test-urllib3-none-host HTTP/1.1" 200 -
2026-03-11 14:05:29,399: 20582 DEBUG instana: Reporting 2 spans

@CagriYonca CagriYonca self-assigned this Mar 11, 2026
@CagriYonca CagriYonca requested a review from a team as a code owner March 11, 2026 13:18
@CagriYonca CagriYonca added the bug label Mar 11, 2026
Signed-off-by: Cagri Yonca <cagri@ibm.com>
@sonarqubecloud
Copy link

Copy link
Member

@pvital pvital left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me.

@CagriYonca CagriYonca merged commit 33ab633 into main Mar 11, 2026
18 checks passed
@CagriYonca CagriYonca deleted the fix/span-filtering branch March 11, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants