diff --git a/src/sentry/seer/signed_seer_api.py b/src/sentry/seer/signed_seer_api.py index cdec9c2a94646c..35dd393fd4dcd5 100644 --- a/src/sentry/seer/signed_seer_api.py +++ b/src/sentry/seer/signed_seer_api.py @@ -2,11 +2,13 @@ import hmac from random import random from typing import Any +from urllib.parse import urlparse from django.conf import settings from urllib3 import BaseHTTPResponse, HTTPConnectionPool from sentry import options +from sentry.utils import metrics def make_signed_seer_api_request( @@ -21,13 +23,19 @@ def make_signed_seer_api_request( if timeout: timeout_options["timeout"] = timeout - return connection_pool.urlopen( - "POST", - path, - body=body, - headers={"content-type": "application/json;charset=utf-8", **auth_headers}, - **timeout_options, - ) + with metrics.timer( + "seer.request_to_seer", + sample_rate=1.0, + # Pull off query params, if any + tags={"endpoint": urlparse(path).path}, + ): + return connection_pool.urlopen( + "POST", + path, + body=body, + headers={"content-type": "application/json;charset=utf-8", **auth_headers}, + **timeout_options, + ) def sign_with_seer_secret(url: str, body: bytes): diff --git a/tests/sentry/seer/test_signed_seer_api.py b/tests/sentry/seer/test_signed_seer_api.py index 1b83acc0fbd285..101aebddf14678 100644 --- a/tests/sentry/seer/test_signed_seer_api.py +++ b/tests/sentry/seer/test_signed_seer_api.py @@ -1,4 +1,4 @@ -from unittest.mock import Mock +from unittest.mock import MagicMock, Mock, patch import pytest from django.test import override_settings @@ -67,3 +67,18 @@ def test_uses_shared_secret(): "Authorization": "Rpcsignature rpc0:96f23d5b3df807a9dc91f090078a46c00e17fe8b0bc7ef08c9391fa8b37a66b5", }, ) + + +@pytest.mark.django_db +@pytest.mark.parametrize("path", [PATH, f"{PATH}?dogs=great"]) +@patch("sentry.seer.signed_seer_api.metrics.timer") +def test_times_request(mock_metrics_timer: MagicMock, path: str): + run_test_case(path=path) + mock_metrics_timer.assert_called_with( + "seer.request_to_seer", + sample_rate=1.0, + tags={ + # In both cases the path is the same, because query params are stripped + "endpoint": PATH, + }, + )