File tree Expand file tree Collapse file tree 2 files changed +31
-8
lines changed Expand file tree Collapse file tree 2 files changed +31
-8
lines changed Original file line number Diff line number Diff line change 22import hmac
33from random import random
44from typing import Any
5+ from urllib .parse import urlparse
56
67from django .conf import settings
78from urllib3 import BaseHTTPResponse , HTTPConnectionPool
89
910from sentry import options
11+ from sentry .utils import metrics
1012
1113
1214def make_signed_seer_api_request (
@@ -21,13 +23,19 @@ def make_signed_seer_api_request(
2123 if timeout :
2224 timeout_options ["timeout" ] = timeout
2325
24- return connection_pool .urlopen (
25- "POST" ,
26- path ,
27- body = body ,
28- headers = {"content-type" : "application/json;charset=utf-8" , ** auth_headers },
29- ** timeout_options ,
30- )
26+ with metrics .timer (
27+ "seer.request_to_seer" ,
28+ sample_rate = 1.0 ,
29+ # Pull off query params, if any
30+ tags = {"endpoint" : urlparse (path ).path },
31+ ):
32+ return connection_pool .urlopen (
33+ "POST" ,
34+ path ,
35+ body = body ,
36+ headers = {"content-type" : "application/json;charset=utf-8" , ** auth_headers },
37+ ** timeout_options ,
38+ )
3139
3240
3341def sign_with_seer_secret (url : str , body : bytes ):
Original file line number Diff line number Diff line change 1- from unittest .mock import Mock
1+ from unittest .mock import MagicMock , Mock , patch
22
33import pytest
44from django .test import override_settings
@@ -67,3 +67,18 @@ def test_uses_shared_secret():
6767 "Authorization" : "Rpcsignature rpc0:96f23d5b3df807a9dc91f090078a46c00e17fe8b0bc7ef08c9391fa8b37a66b5" ,
6868 },
6969 )
70+
71+
72+ @pytest .mark .django_db
73+ @pytest .mark .parametrize ("path" , [PATH , f"{ PATH } ?dogs=great" ])
74+ @patch ("sentry.seer.signed_seer_api.metrics.timer" )
75+ def test_times_request (mock_metrics_timer : MagicMock , path : str ):
76+ run_test_case (path = path )
77+ mock_metrics_timer .assert_called_with (
78+ "seer.request_to_seer" ,
79+ sample_rate = 1.0 ,
80+ tags = {
81+ # In both cases the path is the same, because query params are stripped
82+ "endpoint" : PATH ,
83+ },
84+ )
You can’t perform that action at this time.
0 commit comments