Skip to content

Commit 8da7b4a

Browse files
committed
Fix integration to work with positional argument accepting middleware
1 parent 62b4856 commit 8da7b4a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

sentry_sdk/integrations/starlette.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def patch_middlewares():
362362

363363
if not_yet_patched:
364364
def _sentry_middleware_init(self, cls, *args, **kwargs):
365-
# type: (Any, Any, Any) -> None
365+
# type: (Any, Any, Any, Any) -> None
366366
if cls == SentryAsgiMiddleware:
367367
return old_middleware_init(self, cls, *args, **kwargs)
368368

tests/integrations/starlette/test_starlette.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ async def do_stuff(message):
237237

238238
await self.app(scope, receive, do_stuff)
239239

240+
class SampleMiddlewareWithArgs(Middleware):
241+
def __init__(self, app, bla):
242+
self.app = app
243+
self.bla = bla
240244

241245
class SampleReceiveSendMiddleware:
242246
def __init__(self, app):
@@ -862,6 +866,20 @@ def test_middleware_partial_receive_send(sentry_init, capture_events):
862866
idx += 1
863867

864868

869+
def test_middleware_args(sentry_init):
870+
sentry_init(
871+
traces_sample_rate=1.0,
872+
integrations=[StarletteIntegration()],
873+
)
874+
_ = starlette_app_factory(
875+
middleware=[Middleware(SampleMiddlewareWithArgs, "bla", "ba")]
876+
)
877+
878+
# Only creating the App with an Middleware with args
879+
# should not raise an error
880+
# So as long as test passes, we are good
881+
882+
865883
def test_legacy_setup(
866884
sentry_init,
867885
capture_events,

0 commit comments

Comments
 (0)