Skip to content

Commit

Permalink
Merge branch 'master' into txiao/chore/change-continuous-profile-samp…
Browse files Browse the repository at this point in the history
…ling-frequency-and-buffer-size
  • Loading branch information
Zylphrex committed Feb 3, 2025
2 parents 98aec9b + 91bf322 commit 4bcc895
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
2 changes: 2 additions & 0 deletions sentry_sdk/_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@

class EmptyError(Exception):
"Exception raised by Queue.get(block=0)/get_nowait()."

pass


class FullError(Exception):
"Exception raised by Queue.put(block=0)/put_nowait()."

pass


Expand Down
11 changes: 9 additions & 2 deletions sentry_sdk/integrations/_wsgi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ def form(self):

def parsed_body(self):
# type: () -> Optional[Dict[str, Any]]
form = self.form()
files = self.files()
try:
form = self.form()
except Exception:
form = None
try:
files = self.files()
except Exception:
files = None

if form or files:
data = {}
if form:
Expand Down
11 changes: 10 additions & 1 deletion tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import json
import sys
from contextlib import suppress
from unittest import mock

Expand Down Expand Up @@ -473,9 +474,17 @@ async def hello(request):
assert error_event["contexts"]["trace"]["trace_id"] == trace_id


if sys.version_info < (3, 12):
# `loop` was deprecated in `pytest-aiohttp`
# in favor of `event_loop` from `pytest-asyncio`
@pytest.fixture
def event_loop(loop):
yield loop


@pytest.mark.asyncio
async def test_crumb_capture(
sentry_init, aiohttp_raw_server, aiohttp_client, loop, capture_events
sentry_init, aiohttp_raw_server, aiohttp_client, event_loop, capture_events
):
def before_breadcrumb(crumb, hint):
crumb["data"]["extra"] = "foo"
Expand Down
26 changes: 21 additions & 5 deletions tests/integrations/huggingface_hub/test_huggingface_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
from unittest import mock # python 3.3 and above


def mock_client_post(client, post_mock):
# huggingface-hub==0.28.0 deprecates the `post` method
# so patch `_inner_post` instead
client.post = post_mock
client._inner_post = post_mock


@pytest.mark.parametrize(
"send_default_pii, include_prompts, details_arg",
itertools.product([True, False], repeat=3),
Expand All @@ -28,7 +35,7 @@ def test_nonstreaming_chat_completion(

client = InferenceClient("some-model")
if details_arg:
client.post = mock.Mock(
post_mock = mock.Mock(
return_value=b"""[{
"generated_text": "the model response",
"details": {
Expand All @@ -40,9 +47,11 @@ def test_nonstreaming_chat_completion(
}]"""
)
else:
client.post = mock.Mock(
post_mock = mock.Mock(
return_value=b'[{"generated_text": "the model response"}]'
)
mock_client_post(client, post_mock)

with start_transaction(name="huggingface_hub tx"):
response = client.text_generation(
prompt="hello",
Expand Down Expand Up @@ -84,7 +93,8 @@ def test_streaming_chat_completion(
events = capture_events()

client = InferenceClient("some-model")
client.post = mock.Mock(

post_mock = mock.Mock(
return_value=[
b"""data:{
"token":{"id":1, "special": false, "text": "the model "}
Expand All @@ -95,6 +105,8 @@ def test_streaming_chat_completion(
}""",
]
)
mock_client_post(client, post_mock)

with start_transaction(name="huggingface_hub tx"):
response = list(
client.text_generation(
Expand Down Expand Up @@ -131,7 +143,9 @@ def test_bad_chat_completion(sentry_init, capture_events):
events = capture_events()

client = InferenceClient("some-model")
client.post = mock.Mock(side_effect=OverloadedError("The server is overloaded"))
post_mock = mock.Mock(side_effect=OverloadedError("The server is overloaded"))
mock_client_post(client, post_mock)

with pytest.raises(OverloadedError):
client.text_generation(prompt="hello")

Expand All @@ -147,13 +161,15 @@ def test_span_origin(sentry_init, capture_events):
events = capture_events()

client = InferenceClient("some-model")
client.post = mock.Mock(
post_mock = mock.Mock(
return_value=[
b"""data:{
"token":{"id":1, "special": false, "text": "the model "}
}""",
]
)
mock_client_post(client, post_mock)

with start_transaction(name="huggingface_hub tx"):
list(
client.text_generation(
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/pymongo/test_pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@pytest.fixture(scope="session")
def mongo_server():
server = MockupDB(verbose=True)
server.autoresponds("ismaster", maxWireVersion=6)
server.autoresponds("ismaster", maxWireVersion=7)
server.run()
server.autoresponds(
{"find": "test_collection"}, cursor={"id": 123, "firstBatch": []}
Expand Down

0 comments on commit 4bcc895

Please sign in to comment.