7
7
from django .http .response import HttpResponseBase
8
8
from django .urls import resolve
9
9
10
+ from sentry import options
10
11
from sentry .integrations .gitlab .webhooks import GitlabWebhookEndpoint , GitlabWebhookMixin
11
12
from sentry .integrations .utils .scope import clear_tags_and_context
12
13
from sentry .middleware .integrations .parsers .base import BaseRequestParser
15
16
from sentry .models .outbox import WebhookProviderIdentifier
16
17
from sentry .services .hybrid_cloud .util import control_silo_function
17
18
from sentry .types .integrations import EXTERNAL_PROVIDERS , ExternalProviders
18
- from sentry .utils import json
19
+ from sentry .utils import json , metrics
19
20
20
21
logger = logging .getLogger (__name__ )
21
22
@@ -24,6 +25,7 @@ class GitlabRequestParser(BaseRequestParser, GitlabWebhookMixin):
24
25
provider = EXTERNAL_PROVIDERS [ExternalProviders .GITLAB ]
25
26
webhook_identifier = WebhookProviderIdentifier .GITLAB
26
27
_integration : Integration | None = None
28
+ _METRIC_CONTROL_PATH_FAILURE_KEY = "integrations.gitlab.get_integration_from_request.failure"
27
29
28
30
def _resolve_external_id (self ) -> tuple [str , str ] | HttpResponseBase :
29
31
clear_tags_and_context ()
@@ -43,14 +45,15 @@ def get_integration_from_request(self) -> Integration | None:
43
45
if not self .is_json_request ():
44
46
return None
45
47
try :
46
- _view , _args , kwargs = resolve (self .request .path )
47
- # Non-webhook endpoints
48
- if "integration_id" in kwargs and "organization_slug" in kwargs :
49
- self ._integration = Integration .objects .filter (
50
- id = kwargs ["integration_id" ],
51
- organization_slug = kwargs ["organization_slug" ],
52
- ).first ()
53
- return self ._integration
48
+ if not options .get ("api.remove-non-webhook-control-path-gitlab-parser" ):
49
+ _view , _args , kwargs = resolve (self .request .path )
50
+ # Non-webhook endpoints
51
+ if "integration_id" in kwargs and "organization_slug" in kwargs :
52
+ self ._integration = Integration .objects .filter (
53
+ id = kwargs ["integration_id" ],
54
+ organization_slug = kwargs ["organization_slug" ],
55
+ ).first ()
56
+ return self ._integration
54
57
55
58
# Webhook endpoints
56
59
result = self ._resolve_external_id ()
@@ -60,8 +63,12 @@ def get_integration_from_request(self) -> Integration | None:
60
63
external_id = external_id , provider = self .provider
61
64
).first ()
62
65
return self ._integration
63
- except Exception :
64
- pass
66
+ except Exception as e :
67
+ metrics .incr (
68
+ self ._METRIC_CONTROL_PATH_FAILURE_KEY ,
69
+ tags = {"integration" : self .provider , "error" : str (e )},
70
+ )
71
+ logger .exception ("Failed to get integration from request" )
65
72
66
73
return None
67
74
0 commit comments