Skip to content

Commit f2d10b1

Browse files
committed
Revert "Capture GraphQL client errors (#2243)"
This reverts commit 5199d54.
1 parent c37dbb9 commit f2d10b1

File tree

10 files changed

+44
-1571
lines changed

10 files changed

+44
-1571
lines changed

sentry_sdk/integrations/aiohttp.py

Lines changed: 16 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import json
21
import sys
32
import weakref
43

5-
try:
6-
from urllib.parse import parse_qsl
7-
except ImportError:
8-
from urlparse import parse_qsl # type: ignore
9-
104
from sentry_sdk.api import continue_trace
115
from sentry_sdk._compat import reraise
126
from sentry_sdk.consts import OP, SPANDATA
13-
from sentry_sdk.hub import Hub, _should_send_default_pii
7+
from sentry_sdk.hub import Hub
148
from sentry_sdk.integrations import Integration, DidNotEnable
159
from sentry_sdk.integrations.logging import ignore_logger
1610
from sentry_sdk.sessions import auto_session_tracking
@@ -35,17 +29,14 @@
3529
CONTEXTVARS_ERROR_MESSAGE,
3630
SENSITIVE_DATA_SUBSTITUTE,
3731
AnnotatedValue,
38-
SentryGraphQLClientError,
39-
_get_graphql_operation_name,
40-
_get_graphql_operation_type,
4132
)
4233

4334
try:
4435
import asyncio
4536

4637
from aiohttp import __version__ as AIOHTTP_VERSION
47-
from aiohttp import ClientSession, ContentTypeError, TraceConfig
48-
from aiohttp.web import Application, HTTPException, UrlDispatcher, Response
38+
from aiohttp import ClientSession, TraceConfig
39+
from aiohttp.web import Application, HTTPException, UrlDispatcher
4940
except ImportError:
5041
raise DidNotEnable("AIOHTTP not installed")
5142

@@ -54,11 +45,7 @@
5445
if TYPE_CHECKING:
5546
from aiohttp.web_request import Request
5647
from aiohttp.abc import AbstractMatchInfo
57-
from aiohttp import (
58-
TraceRequestStartParams,
59-
TraceRequestEndParams,
60-
TraceRequestChunkSentParams,
61-
)
48+
from aiohttp import TraceRequestStartParams, TraceRequestEndParams
6249
from types import SimpleNamespace
6350
from typing import Any
6451
from typing import Dict
@@ -77,17 +64,15 @@
7764
class AioHttpIntegration(Integration):
7865
identifier = "aiohttp"
7966

80-
def __init__(self, transaction_style="handler_name", capture_graphql_errors=True):
81-
# type: (str, bool) -> None
67+
def __init__(self, transaction_style="handler_name"):
68+
# type: (str) -> None
8269
if transaction_style not in TRANSACTION_STYLE_VALUES:
8370
raise ValueError(
8471
"Invalid value for transaction_style: %s (must be in %s)"
8572
% (transaction_style, TRANSACTION_STYLE_VALUES)
8673
)
8774
self.transaction_style = transaction_style
8875

89-
self.capture_graphql_errors = capture_graphql_errors
90-
9176
@staticmethod
9277
def setup_once():
9378
# type: () -> None
@@ -126,7 +111,7 @@ async def sentry_app_handle(self, request, *args, **kwargs):
126111
# create a task to wrap each request.
127112
with hub.configure_scope() as scope:
128113
scope.clear_breadcrumbs()
129-
scope.add_event_processor(_make_server_processor(weak_request))
114+
scope.add_event_processor(_make_request_processor(weak_request))
130115

131116
transaction = continue_trace(
132117
request.headers,
@@ -154,7 +139,6 @@ async def sentry_app_handle(self, request, *args, **kwargs):
154139
reraise(*_capture_exception(hub))
155140

156141
transaction.set_http_status(response.status)
157-
158142
return response
159143

160144
Application._handle = sentry_app_handle
@@ -214,8 +198,7 @@ def create_trace_config():
214198
async def on_request_start(session, trace_config_ctx, params):
215199
# type: (ClientSession, SimpleNamespace, TraceRequestStartParams) -> None
216200
hub = Hub.current
217-
integration = hub.get_integration(AioHttpIntegration)
218-
if integration is None:
201+
if hub.get_integration(AioHttpIntegration) is None:
219202
return
220203

221204
method = params.method.upper()
@@ -250,95 +233,28 @@ async def on_request_start(session, trace_config_ctx, params):
250233
params.headers[key] = value
251234

252235
trace_config_ctx.span = span
253-
trace_config_ctx.is_graphql_request = params.url.path == "/graphql"
254-
255-
if integration.capture_graphql_errors and trace_config_ctx.is_graphql_request:
256-
trace_config_ctx.request_headers = params.headers
257-
258-
async def on_request_chunk_sent(session, trace_config_ctx, params):
259-
# type: (ClientSession, SimpleNamespace, TraceRequestChunkSentParams) -> None
260-
integration = Hub.current.get_integration(AioHttpIntegration)
261-
if integration is None:
262-
return
263-
264-
if integration.capture_graphql_errors and trace_config_ctx.is_graphql_request:
265-
trace_config_ctx.request_body = None
266-
with capture_internal_exceptions():
267-
try:
268-
trace_config_ctx.request_body = json.loads(params.chunk)
269-
except json.JSONDecodeError:
270-
return
271236

272237
async def on_request_end(session, trace_config_ctx, params):
273238
# type: (ClientSession, SimpleNamespace, TraceRequestEndParams) -> None
274-
hub = Hub.current
275-
integration = hub.get_integration(AioHttpIntegration)
276-
if integration is None:
239+
if trace_config_ctx.span is None:
277240
return
278241

279-
response = params.response
280-
281-
if trace_config_ctx.span is not None:
282-
span = trace_config_ctx.span
283-
span.set_http_status(int(response.status))
284-
span.set_data("reason", response.reason)
285-
286-
if (
287-
integration.capture_graphql_errors
288-
and trace_config_ctx.is_graphql_request
289-
and response.method in ("GET", "POST")
290-
and response.status == 200
291-
):
292-
with hub.configure_scope() as scope:
293-
with capture_internal_exceptions():
294-
try:
295-
response_content = await response.json()
296-
except ContentTypeError:
297-
pass
298-
else:
299-
scope.add_event_processor(
300-
_make_client_processor(
301-
trace_config_ctx=trace_config_ctx,
302-
response=response,
303-
response_content=response_content,
304-
)
305-
)
306-
307-
if (
308-
response_content
309-
and isinstance(response_content, dict)
310-
and response_content.get("errors")
311-
):
312-
try:
313-
raise SentryGraphQLClientError
314-
except SentryGraphQLClientError as ex:
315-
event, hint = event_from_exception(
316-
ex,
317-
client_options=hub.client.options
318-
if hub.client
319-
else None,
320-
mechanism={
321-
"type": AioHttpIntegration.identifier,
322-
"handled": False,
323-
},
324-
)
325-
hub.capture_event(event, hint=hint)
326-
327-
if trace_config_ctx.span is not None:
328-
span.finish()
242+
span = trace_config_ctx.span
243+
span.set_http_status(int(params.response.status))
244+
span.set_data("reason", params.response.reason)
245+
span.finish()
329246

330247
trace_config = TraceConfig()
331248

332249
trace_config.on_request_start.append(on_request_start)
333-
trace_config.on_request_chunk_sent.append(on_request_chunk_sent)
334250
trace_config.on_request_end.append(on_request_end)
335251

336252
return trace_config
337253

338254

339-
def _make_server_processor(weak_request):
255+
def _make_request_processor(weak_request):
340256
# type: (Callable[[], Request]) -> EventProcessor
341-
def aiohttp_server_processor(
257+
def aiohttp_processor(
342258
event, # type: Dict[str, Any]
343259
hint, # type: Dict[str, Tuple[type, BaseException, Any]]
344260
):
@@ -370,63 +286,7 @@ def aiohttp_server_processor(
370286

371287
return event
372288

373-
return aiohttp_server_processor
374-
375-
376-
def _make_client_processor(trace_config_ctx, response, response_content):
377-
# type: (SimpleNamespace, Response, Optional[Dict[str, Any]]) -> EventProcessor
378-
def aiohttp_client_processor(
379-
event, # type: Dict[str, Any]
380-
hint, # type: Dict[str, Tuple[type, BaseException, Any]]
381-
):
382-
# type: (...) -> Dict[str, Any]
383-
with capture_internal_exceptions():
384-
request_info = event.setdefault("request", {})
385-
386-
parsed_url = parse_url(str(response.url), sanitize=False)
387-
request_info["url"] = parsed_url.url
388-
request_info["method"] = response.method
389-
390-
if getattr(trace_config_ctx, "request_headers", None):
391-
request_info["headers"] = _filter_headers(
392-
dict(trace_config_ctx.request_headers)
393-
)
394-
395-
if _should_send_default_pii():
396-
if getattr(trace_config_ctx, "request_body", None):
397-
request_info["data"] = trace_config_ctx.request_body
398-
399-
request_info["query_string"] = parsed_url.query
400-
401-
if response.url.path == "/graphql":
402-
request_info["api_target"] = "graphql"
403-
404-
query = request_info.get("data")
405-
if response.method == "GET":
406-
query = dict(parse_qsl(parsed_url.query))
407-
408-
if query:
409-
operation_name = _get_graphql_operation_name(query)
410-
operation_type = _get_graphql_operation_type(query)
411-
event["fingerprint"] = [
412-
operation_name,
413-
operation_type,
414-
response.status,
415-
]
416-
event["exception"]["values"][0][
417-
"value"
418-
] = "GraphQL request failed, name: {}, type: {}".format(
419-
operation_name, operation_type
420-
)
421-
422-
if _should_send_default_pii() and response_content:
423-
contexts = event.setdefault("contexts", {})
424-
response_context = contexts.setdefault("response", {})
425-
response_context["data"] = response_content
426-
427-
return event
428-
429-
return aiohttp_client_processor
289+
return aiohttp_processor
430290

431291

432292
def _capture_exception(hub):

0 commit comments

Comments
 (0)