Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aiohttp): parsed_url can be None #2734

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ async def on_request_start(session, trace_config_ctx, params):
% (method, parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE),
)
span.set_data(SPANDATA.HTTP_METHOD, method)
span.set_data("url", parsed_url.url)
span.set_data(SPANDATA.HTTP_QUERY, parsed_url.query)
span.set_data(SPANDATA.HTTP_FRAGMENT, parsed_url.fragment)
if parsed_url is not None:
span.set_data("url", parsed_url.url)
span.set_data(SPANDATA.HTTP_QUERY, parsed_url.query)
span.set_data(SPANDATA.HTTP_FRAGMENT, parsed_url.fragment)

if should_propagate_trace(hub, str(params.url)):
for key, value in hub.iter_trace_propagation_headers(span):
Expand Down
30 changes: 30 additions & 0 deletions tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,36 @@ async def hello(request):
assert event["transaction_info"] == {"source": expected_source}


@pytest.mark.tests_internal_exceptions
@pytest.mark.asyncio
async def test_tracing_unparseable_url(sentry_init, aiohttp_client, capture_events):
sentry_init(integrations=[AioHttpIntegration()], traces_sample_rate=1.0)

async def hello(request):
return web.Response(text="hello")

app = web.Application()
app.router.add_get("/", hello)

events = capture_events()

client = await aiohttp_client(app)
with mock.patch(
"sentry_sdk.integrations.aiohttp.parse_url", side_effect=ValueError
):
resp = await client.get("/")

assert resp.status == 200

(event,) = events

assert event["type"] == "transaction"
assert (
event["transaction"]
== "tests.integrations.aiohttp.test_aiohttp.test_tracing_unparseable_url.<locals>.hello"
Copy link
Member

Choose a reason for hiding this comment

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

Where does this string come from? I don't understand why this is the expected result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the expected transaction name if transaction style is handler_name, at least looking at the test before this one.

)


@pytest.mark.asyncio
async def test_traces_sampler_gets_request_object_in_sampling_context(
sentry_init,
Expand Down
Loading