|
5 | 5 | import pytest
|
6 | 6 | from aiohttp import web
|
7 | 7 | from aiohttp.client import ServerDisconnectedError
|
| 8 | +from aiohttp.web_request import Request |
8 | 9 |
|
9 | 10 | from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
10 | 11 |
|
| 12 | +try: |
| 13 | + from unittest import mock # python 3.3 and above |
| 14 | +except ImportError: |
| 15 | + import mock # python < 3.3 |
| 16 | + |
11 | 17 |
|
12 | 18 | async def test_basic(sentry_init, aiohttp_client, loop, capture_events):
|
13 | 19 | sentry_init(integrations=[AioHttpIntegration()])
|
@@ -223,3 +229,35 @@ async def hello(request):
|
223 | 229 |
|
224 | 230 | assert event["type"] == "transaction"
|
225 | 231 | assert event["transaction"] == expected_transaction
|
| 232 | + |
| 233 | + |
| 234 | +async def test_traces_sampler_gets_request_object_in_sampling_context( |
| 235 | + sentry_init, |
| 236 | + aiohttp_client, |
| 237 | + DictionaryContaining, # noqa:N803 |
| 238 | + ObjectDescribedBy, # noqa:N803 |
| 239 | +): |
| 240 | + traces_sampler = mock.Mock() |
| 241 | + sentry_init( |
| 242 | + integrations=[AioHttpIntegration()], |
| 243 | + traces_sampler=traces_sampler, |
| 244 | + ) |
| 245 | + |
| 246 | + async def kangaroo_handler(request): |
| 247 | + return web.Response(text="dogs are great") |
| 248 | + |
| 249 | + app = web.Application() |
| 250 | + app.router.add_get("/tricks/kangaroo", kangaroo_handler) |
| 251 | + |
| 252 | + client = await aiohttp_client(app) |
| 253 | + await client.get("/tricks/kangaroo") |
| 254 | + |
| 255 | + traces_sampler.assert_any_call( |
| 256 | + DictionaryContaining( |
| 257 | + { |
| 258 | + "aiohttp_request": ObjectDescribedBy( |
| 259 | + type=Request, attrs={"method": "GET", "path": "/tricks/kangaroo"} |
| 260 | + ) |
| 261 | + } |
| 262 | + ) |
| 263 | + ) |
0 commit comments