Skip to content

test: Add streaming tests to test_http_headers#6785

Draft
sentrivana wants to merge 1 commit into
masterfrom
ivana/sampling-http-headers-tests
Draft

test: Add streaming tests to test_http_headers#6785
sentrivana wants to merge 1 commit into
masterfrom
ivana/sampling-http-headers-tests

Conversation

@sentrivana

Copy link
Copy Markdown
Contributor

Description

WIP: Needs #6757

Issues

Part of #5395

Reminders

@sentrivana sentrivana changed the base branch from master to ivana/traceparent-test July 8, 2026 13:49
@sentrivana sentrivana changed the base branch from ivana/traceparent-test to master July 8, 2026 13:58
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

90585 passed | ❌ 30 failed | ⏭️ 6302 skipped | Total: 96917 | Pass Rate: 93.47% | Execution Time: 317m 55s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +60
Passed Tests 📈 +30
Failed Tests 📈 +30
Skipped Tests

➕ New Tests (30)

View new tests
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_to_traceparent_span_streaming[0.0]
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing
  • test_iter_headers_span_streaming
    • File: tests.tracing.test_http_headers
    • Status: ❌ Failing

❌ Failed Tests

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.10-common
Error: AssertionError: assert 'c78c6dbdf63f4a6b9a02e0823d206cb1' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + c78c6dbdf63f4a6b9a02e0823d206cb1

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
E   AssertionError: assert 'c78c6dbdf63f4a6b9a02e0823d206cb1' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + c78c6dbdf63f4a6b9a02e0823d206cb1

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.10-common
Error: AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
E   AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.10-gevent
Error: AssertionError: assert '58c07a1d3c394d52b2474905a5958241' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 58c07a1d3c394d52b2474905a5958241

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
E   AssertionError: assert '58c07a1d3c394d52b2474905a5958241' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + 58c07a1d3c394d52b2474905a5958241

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.10-gevent
Error: AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
E   AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.11-common
Error: AssertionError: assert 'ad4cb7eb9a284757ba1738d0b14703f1' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + ad4cb7eb9a284757ba1738d0b14703f1

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: assert 'ad4cb7eb9a284757ba1738d0b14703f1' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + ad4cb7eb9a284757ba1738d0b14703f1

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.11-common
Error: AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
           ^^^^^^^^^^^^^
E   AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.11-gevent
Error: AssertionError: assert 'eb6d9eed69bc4a9080facacab690e257' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + eb6d9eed69bc4a9080facacab690e257

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: assert 'eb6d9eed69bc4a9080facacab690e257' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + eb6d9eed69bc4a9080facacab690e257

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.11-gevent
Error: AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
           ^^^^^^^^^^^^^
E   AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.12-common
Error: AssertionError: assert '4e31fa4299a04550ac53c6b9134deb2b' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 4e31fa4299a04550ac53c6b9134deb2b

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: assert '4e31fa4299a04550ac53c6b9134deb2b' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + 4e31fa4299a04550ac53c6b9134deb2b

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.12-common
Error: AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
           ^^^^^^^^^^^^^
E   AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.12-gevent
Error: AssertionError: assert 'b6d5abd0e764430fad0f7fe86954aadb' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + b6d5abd0e764430fad0f7fe86954aadb

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: assert 'b6d5abd0e764430fad0f7fe86954aadb' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + b6d5abd0e764430fad0f7fe86954aadb

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.12-gevent
Error: AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
           ^^^^^^^^^^^^^
E   AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.13-common
Error: AssertionError: assert '2de939474db94266ac67ca3e302f0a0a' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 2de939474db94266ac67ca3e302f0a0a

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: assert '2de939474db94266ac67ca3e302f0a0a' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + 2de939474db94266ac67ca3e302f0a0a

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.13-common
Error: AttributeError: 'sentry_sdk.traces.NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
           ^^^^^^^^^^^^^
E   AttributeError: 'sentry_sdk.traces.NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.14-common
Error: AssertionError: assert '7fbbfba70e754d0c88c119965bfeee53' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 7fbbfba70e754d0c88c119965bfeee53

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: assert '7fbbfba70e754d0c88c119965bfeee53' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + 7fbbfba70e754d0c88c119965bfeee53

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.14-common
Error: AttributeError: 'sentry_sdk.traces.NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
           ^^^^^^^^^^^^^
E   AttributeError: 'sentry_sdk.traces.NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.14t-common
Error: AssertionError: assert '41323b43aa2a475680e9a2b27993bf59' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 41323b43aa2a475680e9a2b27993bf59

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   AssertionError: assert '41323b43aa2a475680e9a2b27993bf59' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + 41323b43aa2a475680e9a2b27993bf59

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.14t-common
Error: AttributeError: 'sentry_sdk.traces.NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
           ^^^^^^^^^^^^^
E   AttributeError: 'sentry_sdk.traces.NoOpStreamedSpan' object has no attribute '_segment'. Did you mean: '_is_segment'?

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.6-common
Error: AssertionError: assert '07fafb99ff4142e4897559f433e2df4e' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 07fafb99ff4142e4897559f433e2df4e

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
E   AssertionError: assert '07fafb99ff4142e4897559f433e2df4e' == '00000000000000000000000000000000'
E     - 00000000000000000000000000000000
E     + 07fafb99ff4142e4897559f433e2df4e

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.6-common
Error: AttributeError: _segment

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
E   AttributeError: _segment

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.6-gevent
Error: AssertionError: assert '471ffddd5dc742a4afc79ff404d60e0d' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 471ffddd5dc742a4afc79ff404d60e0d

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
E   AssertionError: assert '471ffddd5dc742a4afc79ff404d60e0d' == '00000000000000000000000000000000'
E     - 00000000000000000000000000000000
E     + 471ffddd5dc742a4afc79ff404d60e0d

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.6-gevent
Error: AttributeError: _segment

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
E   AttributeError: _segment

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.7-common
Error: AssertionError: assert '371b6e82fa944129849dd7344f8fe69d' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 371b6e82fa944129849dd7344f8fe69d

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
E   AssertionError: assert '371b6e82fa944129849dd7344f8fe69d' == '00000000000000000000000000000000'
E     - 00000000000000000000000000000000
E     + 371b6e82fa944129849dd7344f8fe69d

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.7-common
Error: AttributeError: _segment

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
E   AttributeError: _segment

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.8-common
Error: AssertionError: assert '5b5207690f0e44ee8c357d961bdde5dd' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 5b5207690f0e44ee8c357d961bdde5dd

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
E   AssertionError: assert '5b5207690f0e44ee8c357d961bdde5dd' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + 5b5207690f0e44ee8c357d961bdde5dd

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.8-common
Error: AttributeError: _segment

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
E   AttributeError: _segment

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.8-gevent
Error: AssertionError: assert '9c747ab11a2244839a6a50ee73cd61ca' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + 9c747ab11a2244839a6a50ee73cd61ca

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
E   AssertionError: assert '9c747ab11a2244839a6a50ee73cd61ca' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + 9c747ab11a2244839a6a50ee73cd61ca

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.8-gevent
Error: AttributeError: _segment

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
E   AttributeError: _segment

test_to_traceparent_span_streaming[0.0]

File: tests.tracing.test_http_headers
Suite: py3.9-common
Error: AssertionError: assert 'f80a72457c774e89a0c020a080a9074a' == '00000000000000000000000000000000' - 00000000000000000000000000000000 + f80a72457c774e89a0c020a080a9074a

Stack Trace
tests/tracing/test_http_headers.py:52: in test_to_traceparent_span_streaming
    assert parts[0] == span.trace_id  # trace_id
E   AssertionError: assert 'f80a72457c774e89a0c020a080a9074a' == '00000000000000000000000000000000'
E     
E     - 00000000000000000000000000000000
E     + f80a72457c774e89a0c020a080a9074a

test_iter_headers_span_streaming

File: tests.tracing.test_http_headers
Suite: py3.9-common
Error: AttributeError: _segment

Stack Trace
tests/tracing/test_http_headers.py:122: in test_iter_headers_span_streaming
    headers = dict(span._iter_headers())
sentry_sdk/traces.py:535: in _iter_headers
    if not self._segment:
E   AttributeError: _segment

✅ Patch coverage is 100.00%. Project has 2445 uncovered lines.
✅ Project coverage is 89.74%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.74%    89.74%        —%
==========================================
  Files          192       192         —
  Lines        23823     23823         —
  Branches      8226      8226         —
==========================================
+ Hits         21378     21378         —
- Misses        2445      2445         —
- Partials      1349      1349         —

Generated by Codecov Action

assert parts[0] == span.trace_id # trace_id
assert parts[1] == span.span_id # parent_span_id
assert parts[2] == "1" if traces_sample_rate == 1.0 else "0" # sampled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assertion for traces_sample_rate == 0.0 is always truthy and validates nothing

Due to Python operator precedence, assert parts[2] == "1" if traces_sample_rate == 1.0 else "0" is parsed as assert (parts[2] == "1") if traces_sample_rate == 1.0 else "0" — so when traces_sample_rate == 0.0 the asserted value is the string "0", which is always truthy and never checks the actual sampled flag. Use assert parts[2] == ("1" if traces_sample_rate == 1.0 else "0") instead.

Evidence
  • In test_to_traceparent_span_streaming the new assertion assert parts[2] == "1" if traces_sample_rate == 1.0 else "0" (line 54) parses as (parts[2] == "1") if traces_sample_rate == 1.0 else "0" because the conditional expression binds looser than ==.
  • With the parametrized traces_sample_rate == 0.0 case, the whole expression evaluates to the string literal "0", which is always truthy, so assert never validates the unsampled traceparent flag.
  • The parametrize decorator explicitly includes 0.0 to cover the unsampled path, but that path exercises no real assertion, silently passing regardless of parts[2].

Identified by Warden code-review · HRH-9YM

assert (
headers["sentry-trace"] == "12312012123120121231201212312012-0415201309082013-0"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test test_iter_headers_span_streaming uses traces_sample_rate=0.0, so span._iter_headers() raises AttributeError instead of exercising header generation

With traces_sample_rate=0.0, the sampling decision drops the span and start_streamed_span returns a NoOpStreamedSpan rather than a real StreamedSpan. The test then calls span._iter_headers() directly. NoOpStreamedSpan does not override _iter_headers, so the inherited StreamedSpan._iter_headers runs if not self._segment, but NoOpStreamedSpan.__init__ never assigns the inherited _segment slot, raising AttributeError. The monkeypatched StreamedSpan._to_traceparent is never reached and the headers["sentry-trace"] assertion is never evaluated, so the test errors out instead of validating streaming header generation. Note the production path in Scope.iter_headers guards with isinstance(span, (NoOpStreamedSpan, NoOpSpan)) before calling _iter_headers, so this only affects the test's direct call. Use traces_sample_rate=1.0 to obtain a real StreamedSpan.

Evidence
  • _make_sampling_decision short-circuits to sampled=False when sample_rate is 0.0; Scope.start_streamed_span (scope.py:1317-1321) then returns NoOpStreamedSpan(scope=self, unsampled_reason=outcome).
  • NoOpStreamedSpan.__init__ (traces.py:617) only sets _scope, _unsampled_reason, _finished; it never assigns the _segment slot declared on StreamedSpan.__slots__.
  • NoOpStreamedSpan does not override _iter_headers; the inherited StreamedSpan._iter_headers (traces.py:534-535) executes if not self._segment, raising AttributeError on the uninitialised slot.
  • Scope.iter_headers (scope.py:706-708) skips _iter_headers for NoOpStreamedSpan, so only this test's direct span._iter_headers() call at line 122 hits the error.

Identified by Warden code-review · P8Z-Q9L

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant