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

Sentry sdk causes requests to return an empty response when using graphql query #2285

Closed
reinoldus opened this issue Aug 1, 2023 · 10 comments · Fixed by #2286
Closed

Sentry sdk causes requests to return an empty response when using graphql query #2285

reinoldus opened this issue Aug 1, 2023 · 10 comments · Fixed by #2286
Assignees

Comments

@reinoldus
Copy link

reinoldus commented Aug 1, 2023

How do you use Sentry?

Cloud

Version

1.29.0
python version: 3.9

Steps to Reproduce

import requests

from flask import Flask
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration

dsn = "XXXXX"

sentry_sdk.init(
    dsn=dsn,
    integrations=[
        FlaskIntegration(),
    ],
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    # We recommend adjusting this value in production.
    traces_sample_rate=0.1,
)

headers = {
    "Content-Type": "application/json; charset=utf-8",
}
data = {
    "variables": {"email": "xxx"},
}


response = requests.post(
    "http://localhost:8089/v1/graphql",
    headers=headers,
    json=data,
)

x = response.json()


if you run the snippet above the response.content will come back as "", where if you run this:

import requests

from flask import Flask
# import sentry_sdk
# from sentry_sdk.integrations.flask import FlaskIntegration
#
# dsn = "httXXXXXXXX3611"
#
# sentry_sdk.init(
#     dsn=dsn,
#     integrations=[
#         FlaskIntegration(),
#     ],
#     # Set traces_sample_rate to 1.0 to capture 100%
#     # of transactions for performance monitoring.
#     # We recommend adjusting this value in production.
#     traces_sample_rate=0.1,
# )

headers = {
    "Content-Type": "application/json; charset=utf-8",
}
data = {
    "variables": {"email": "xxx"},
}


response = requests.post(
    "http://localhost:8089/v1/graphql",
    headers=headers,
    json=data,
)

x = response.json()

The response comes back as expected.

I am running the query against a hasura instance, but I assume it has something to do with this new feature, so I assume all requests to all graphql servers are affected:

image

Pip freeze:

annotated-types==0.5.0
asttokens==2.2.1
async-timeout==4.0.2
black==23.7.0
blinker==1.6.2
boto3==1.28.16
botocore==1.31.16
CacheControl==0.13.1
cachetools==5.3.1
certifi==2023.7.22
cffi==1.15.1
cfgv==3.3.1
charset-normalizer==3.2.0
click==8.1.6
colorama==0.4.6
contourpy==1.1.0
cryptography==41.0.2
cycler==0.11.0
Deprecated==1.2.14
distlib==0.3.7
dnspython==2.4.1
email-validator==2.0.0.post2
exceptiongroup==1.1.2
executing==1.2.0
filelock==3.12.2
firebase-admin==6.0.1
Flask==2.3.2
Flask-Cors==3.0.10
fonttools==4.41.1
google-api-core==2.11.1
google-api-python-client==2.95.0
google-auth==2.22.0
google-auth-httplib2==0.1.0
google-cloud-core==2.3.3
google-cloud-firestore==2.3.4
google-cloud-storage==2.10.0
google-crc32c==1.5.0
google-resumable-media==2.5.0
googleapis-common-protos==1.60.0
grpcio==1.56.2
grpcio-status==1.56.2
gunicorn==21.2.0
httplib2==0.22.0
icecream==2.1.3
identify==2.5.26
idna==3.4
importlib-metadata==6.8.0
importlib-resources==6.0.0
iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
jmespath==1.0.1
jwcrypto==1.5.0
kiwisolver==1.4.4
MarkupSafe==2.1.3
matplotlib==3.7.2
msgpack==1.0.5
mypy-extensions==1.0.0
nodeenv==1.8.0
numpy==1.25.2
opencv-python-headless==4.8.0.74
packaging==23.1
pathspec==0.11.2
Pillow==10.0.0
pip==22.3.1
platformdirs==3.10.0
pluggy==1.2.0
pre-commit==3.3.3
proto-plus==1.22.3
protobuf==4.23.4
psycopg2-binary==2.9.6
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycparser==2.21
pydantic==2.1.1
pydantic_core==2.4.0
Pygments==2.15.1
PyJWT==2.8.0
pyparsing==3.0.9
pytest==7.4.0
python-dateutil==2.8.2
python-dotenv==1.0.0
python-jwt==4.0.0
PyYAML==6.0.1
redis==4.6.0
requests==2.31.0
rsa==4.9
s3transfer==0.6.1
scipy==1.11.1
sentry-sdk==1.29.0
setuptools==65.5.1
six==1.16.0
tomli==2.0.1
typing_extensions==4.7.1
uritemplate==4.1.1
urllib3==1.26.16
virtualenv==20.24.2
Werkzeug==2.3.6
wheel==0.38.4
wrapt==1.15.0
zipp==3.16.2

Downgrading to 1.28.1 fixes the issue

Expected Result

Populated "text" field in requests response object

image

Actual Result

image (73)

The response is "stuck" in the raw HTTPResponse from urllib3

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Aug 1, 2023
@sentrivana
Copy link
Contributor

Hey @reinoldus, thanks for the report! Please downgrade to 1.28.1 for now, we're working on a fix.

@sentrivana
Copy link
Contributor

1.29.1 released now that should fix the issue.

@lpfann
Copy link

lpfann commented Aug 1, 2023

Now we get a different issue with 1.29.1: (using sgqlc library)

  File "/venv/lib/python3.9/site-packages/sgqlc/endpoint/requests.py", line 216, in __call__
    with self.session.send(
  File "/venv/lib/python3.9/site-packages/requests/sessions.py", line 747, in send
    r.content
  File "/venv/lib/python3.9/site-packages/requests/models.py", line 899, in content
    self._content = b"".join(self.iter_content(CONTENT_CHUNK_SIZE)) or b""
  File "/venv/lib/python3.9/site-packages/requests/models.py", line 818, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'\\x1f\\x8b\\x08\\x00\\x00\\x00\\x00\\x00\\x00\\x03\\x8c\\x91Ak\\xdc0\\x10\\x85\\xff\\x8b\\xae\\xcd\\x84\\x91mI+\\xdf\\x92\\xd2C \\x87@\\x1dr\\x08e\\x19K\\xe3D\\xc4\\xb6\\x8c\\xac\\xdd\\x12\\x96\\xfd\\xef\\x95\\xb7))=\\x15t\\xd0\\xcc|o\\x9ex:\\tO\\x99D{\\x12\\x13g\\xdaS\\xd8O\\xd1\\xf3x\\xacD\\xfb|\\x123M,Z\\xe1\\xa3', 0 bytes read)", InvalidChunkLength(got length b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x8c\x91Ak\xdc0\x10\x85\xff\x8b\xae\xcd\x84\x91mI+\xdf\x92\xd2C \x87@\x1dr\x08e\x19K\xe3D\xc4\xb6\x8c\xac\xdd\x12\x96\xfd\xef\x95\xb7))=\x15t\xd0\xcc|o\x9ex:\tO\x99D{\x12\x13g\xdaS\xd8O\xd1\xf3x\xacD\xfb|\x123M,Z\xe1\xa3', 0 bytes read))

@sentrivana

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Aug 1, 2023
@sentrivana
Copy link
Contributor

sentrivana commented Aug 1, 2023

@lpfann Thanks for reporting, looking into it. (In the meantime, downgrading to 1.28.1 will get rid of the issue.)

@MattLJoslin
Copy link

We're also seeing the same set of issues. Downgrading to 1.28.1 seems to fix for now.

@sentrivana
Copy link
Contributor

@lpfann Having trouble reproducing this -- anything specific about your setup? Maybe a small code sample?

@cleptric cleptric reopened this Aug 1, 2023
@MattLJoslin
Copy link

We are using
graphql-core==3.2.1
gql==3.4.0
requests==2.28.2
urllib3==1.26.16

this is a rough snippet of the code that is causing this issue

import requests
from gql import gql as gql_parse
from gql.client import Client
from gql.transport.requests import RequestsHTTPTransport

query_str = """"""
data_url = ""
variables = {}
userpass_data_headers = {}

reqsession = requests.Session()
adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100)
reqsession.mount('https://', adapter)
sync_transport = RequestsHTTPTransport(
url=data_url, headers=userpass_data_headers
)
_client = Client(
transport=sync_transport, fetch_schema_from_transport=True
)
session = _client.enter()
query = gql_parse(query_str)
data_obj = session.execute(query, variable_values=variables)

@sentrivana
Copy link
Contributor

Thanks a lot @MattLJoslin! This will help.

I'll revert the feature that caused this for now so that more folks don't run into issues -- we'll revisit it later. Really sorry for the issues this caused.

@sentrivana
Copy link
Contributor

1.29.2 is now out and will get you all the good stuff from 1.29.0 without the GraphQL issues.

@MattLJoslin
Copy link

Thanks for the quick responses! We are still looking forward to this feature since we almost exclusively use graphql in our services, but appreciate the rollback :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants