Skip to content

fix(tracing): Skip child span creation in streaming path when no current span (misc)#6815

Draft
sentrivana wants to merge 1 commit into
masterfrom
ivana/streaming-child-spans-misc
Draft

fix(tracing): Skip child span creation in streaming path when no current span (misc)#6815
sentrivana wants to merge 1 commit into
masterfrom
ivana/streaming-child-spans-misc

Conversation

@sentrivana

Copy link
Copy Markdown
Contributor

Summary

  • When span streaming is enabled and there is no current span, integrations should not create new root segments for child-span operations
  • Adds a sentry_sdk.traces.get_current_span() is None guard before creating spans in the streaming path
  • Affected integrations: socket, grpc (client), asyncio, mcp, rust_tracing

Test plan

  • Existing tests pass
  • Verify that in streaming mode, no orphan root segments are created when there's no active span

🤖 Generated with Claude Code

…ent span (misc)

When span streaming is enabled and there is no current span,
integrations should not create new root segments for child-span
operations. This adds a guard check using
`sentry_sdk.traces.get_current_span()` before creating spans
in the streaming path.

Affected integrations: socket, grpc (client), asyncio, mcp,
rust_tracing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

89129 passed | ❌ 26 failed | ⏭️ 6302 skipped | Total: 95457 | Pass Rate: 93.37% | Execution Time: 301m 39s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -2045
Passed Tests 📉 -2071
Failed Tests 📈 +26
Skipped Tests

➕ New Tests (26)

View new tests
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing
  • test_on_new_span_without_transaction[True]
    • File: tests.integrations.rust_tracing.test_rust_tracing
    • Status: ❌ Failing
  • test_noop_for_unimplemented_method[True]
    • File: tests.integrations.grpc.test_grpc_aio
    • Status: ❌ Failing

❌ Failed Tests

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.10-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.10-gevent
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.10-grpc-v1.48.2
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
/usr/lib/python3.10/asyncio/tasks.py:304: in __wakeup
    future.result()
src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi:953: in _server_main_loop
    ???
src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi:935: in _request_call
    ???
E   grpc._cython.cygrpc._RequestCallError: Failed "grpc_server_request_call": None

During handling of the above exception, another exception occurred:
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
E   assert 0 == 1
E    +  where 0 = len([])

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.10-grpc-v1.82.0
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
E   assert 0 == 1
E    +  where 0 = len([])

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.11-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.11-gevent
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.11-grpc-v1.64.3
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
    ^^^^^^^^^^^^^^^^^^^^^^
E   assert 0 == 1
E    +  where 0 = len([])

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.12-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.12-gevent
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.12-grpc-v1.64.3
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
    ^^^^^^^^^^^^^^^^^^^^^^
E   assert 0 == 1
E    +  where 0 = len([])

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.13-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.13-grpc-v1.82.0
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
    ^^^^^^^^^^^^^^^^^^^^^^
E   assert 0 == 1
E    +  where 0 = len([])

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.14-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.14-grpc-v1.82.0
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
    ^^^^^^^^^^^^^^^^^^^^^^
E   assert 0 == 1
E    +  where 0 = len([])

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.14t-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.6-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.6-gevent
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.7-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.7-grpc-v1.32.0
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
E   assert 0 == 1
E    +  where 0 = len([])

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.7-grpc-v1.48.2
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
E   assert 0 == 1
E    +  where 0 = len([])

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.8-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.8-gevent
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.8-grpc-v1.32.0
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
E   assert 0 == 1
E    +  where 0 = len([])

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.8-grpc-v1.64.3
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
E   assert 0 == 1
E    +  where 0 = len([])

test_on_new_span_without_transaction[True]

File: tests.integrations.rust_tracing.test_rust_tracing
Suite: py3.9-common
Error: assert None is not None

Stack Trace
tests/integrations/rust_tracing/test_rust_tracing.py:314: in test_on_new_span_without_transaction
    assert current_span is not None
E   assert None is not None

test_noop_for_unimplemented_method[True]

File: tests.integrations.grpc.test_grpc_aio
Suite: py3.9-grpc-v1.48.2
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
../../_temp/uv-python-dir/cpython-3.9-linux-x86_64-gnu/lib/python3.9/asyncio/tasks.py:328: in __wakeup
    future.result()
src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi:953: in _server_main_loop
    ???
src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi:935: in _request_call
    ???
E   grpc._cython.cygrpc._RequestCallError: Failed "grpc_server_request_call": None

During handling of the above exception, another exception occurred:
tests/integrations/grpc/test_grpc_aio.py:103: in test_noop_for_unimplemented_method
    assert len(spans) == 1  # Only client span present.
E   assert 0 == 1
E    +  where 0 = len([])

❌ Patch coverage is 74.42%. Project has 2527 uncovered lines.
❌ Project coverage is 89.44%. Comparing base (base) to head (head).

Files with missing lines (4)
File Patch % Lines
sentry_sdk/integrations/mcp.py 78.26% ⚠️ 5 Missing and 8 partials
sentry_sdk/integrations/socket.py 50.00% ⚠️ 2 Missing and 2 partials
sentry_sdk/integrations/grpc/aio/client.py 66.67% ⚠️ 2 Missing and 1 partials
sentry_sdk/integrations/grpc/client.py 66.67% ⚠️ 2 Missing and 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    89.78%    89.44%    -0.34%
==========================================
  Files          193       193         —
  Lines        23898     23921       +23
  Branches      8258      8280       +22
==========================================
+ Hits         21454     21394       -60
- Misses        2444      2527       +83
- Partials      1353      1355        +2

Generated by Codecov Action

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