Skip to content

AttributeError: 'SpanRecorder' object has no attribute 'dropped_spans' on sentry-python >=2.21 #4303

@ripperdoc

Description

@ripperdoc

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.21.0

Steps to Reproduce

  1. Install Sentry at 2.21.0 or above
  2. Apply a Sentry config like this inside a FastAPI server
sentry_sdk.init(
        dsn=dsn,
        sample_rate=1.0,
        enable_tracing=True,
        traces_sample_rate=1.0,
        auto_session_tracking=False,
        trace_propagation_targets=[os.getenv("DOCUMENT_ENDPOINT", "")],
        environment=os.getenv("SENTRY_ENVIRONMENT"),
        release=VERSION,
        integrations=[
            AsyncioIntegration(),
        ],
    )
  1. Call a websocket endpoint

Expected Result

No error from Sentry.

Actual Result

Traceback (most recent call last):
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 409, in _sentry_patched_asgi_app
    return await middleware(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py", line 161, in _run_asgi3
    return await self._run_app(scope, receive, send, asgi_version=3)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py", line 262, in _run_app
    raise exc from None
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py", line 257, in _run_app
    return await self.app(
           ^^^^^^^^^^^^^^^
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
    return await old_call(app, scope, new_receive, new_send, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 151, in __call__
    await self.app(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 103, in __call__
    await self.app(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 77, in __call__
    await self.app(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 298, in _sentry_exceptionmiddleware_call
    await old_call(self, scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/integrations/starlette.py", line 200, in _create_span_call
    return await old_call(app, scope, new_receive, new_send, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/routing.py", line 373, in handle
    await self.app(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/routing.py", line 96, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/starlette/routing.py", line 94, in app
    await func(session)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/fastapi/routing.py", line 348, in app
    await dependant.call(**values)
  File "/Users/martin/dev/fictive/convai-vocode/app/vocode_router.py", line 456, in streaming
    with sentry_sdk.start_transaction(op="start_session") as sentry_txn:
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/tracing.py", line 846, in __exit__
    super().__exit__(ty, value, tb)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/tracing.py", line 383, in __exit__
    self.finish(scope)
  File "/Users/martin/dev/fictive/convai-vocode/venv/lib/python3.11/site-packages/sentry_sdk/tracing.py", line 979, in finish
    dropped_spans = len_diff + self._span_recorder.dropped_spans

AttributeError: 'SpanRecorder' object has no attribute 'dropped_spans'

The changelog for 2.21 mentions keeping track of dropped spans, so that matches this error. Sentry 2.20 and earlier works.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions