def test_execution_environment_should_be_identified(self, requests_mock): telemetry = Telemetry(url=self.url) telemetry.emit("metric_name", {}) expected_execution_environment = "CLI" expected = { "metrics": [{ "metric_name": _ignore_other_attrs( {"executionEnvironment": expected_execution_environment}) }] } requests_mock.post.assert_called_once_with(ANY, json=expected, timeout=ANY)
def test_must_add_request_id_as_uuid_v4(self, uuid_mock, requests_mock): fake_uuid = uuid_mock.uuid4.return_value = "fake uuid" telemetry = Telemetry(url=self.url) telemetry.emit("metric_name", {}) expected = { "metrics": [{ "metric_name": _ignore_other_attrs({ "requestId": fake_uuid, }) }] } requests_mock.post.assert_called_once_with(ANY, json=expected, timeout=ANY)
def test_must_add_metric_with_attributes_to_registry(self, requests_mock): telemetry = Telemetry(url=self.url) metric_name = "mymetric" attrs = {"a": 1, "b": 2} telemetry.emit(metric_name, attrs) expected = { "metrics": [{ metric_name: { "a": 1, "b": 2, "requestId": ANY, "installationId": self.test_installation_id, "sessionId": self.test_session_id, "executionEnvironment": "CLI", "pyversion": platform.python_version(), "samcliVersion": samcli_version, } }] } requests_mock.post.assert_called_once_with(ANY, json=expected, timeout=ANY)
def test_default_request_should_be_fire_and_forget(self, requests_mock): telemetry = Telemetry(url=self.url) telemetry.emit(self.metric_mock) requests_mock.post.assert_called_once_with( ANY, json=ANY, timeout=(2, 0.1)) # 100ms response timeout
def test_must_send_when_telemetry_disabled_but_forced( self, gc_mock, requests_mock): telemetry = Telemetry(url=self.url) gc_mock.return_value.telemetry_enabled = False telemetry.emit(self.metric_mock, force_emit=True) requests_mock.post.assert_called()