Side effect: Removes the report after sending it. The report is generated and stored in a temporary file, see: `collect_and_send_report`. Sending happens on another process, thus, the need of removing such file afterwards.
(path)
| 63 | |
| 64 | |
| 65 | def send(path): |
| 66 | """ |
| 67 | Side effect: Removes the report after sending it. |
| 68 | |
| 69 | The report is generated and stored in a temporary file, see: |
| 70 | `collect_and_send_report`. Sending happens on another process, |
| 71 | thus, the need of removing such file afterwards. |
| 72 | """ |
| 73 | import requests |
| 74 | from requests.exceptions import RequestException |
| 75 | |
| 76 | url = os.environ.get(DVC_ANALYTICS_ENDPOINT, "https://analytics.dvc.org") |
| 77 | headers = {"content-type": "application/json"} |
| 78 | |
| 79 | with open(path, encoding="utf-8") as fobj: |
| 80 | report = json.load(fobj) |
| 81 | |
| 82 | report.update(_runtime_info()) |
| 83 | |
| 84 | logger.debug("uploading report to %s", url) |
| 85 | logger.trace("Sending %s to %s", report, url) |
| 86 | |
| 87 | try: |
| 88 | requests.post(url, json=report, headers=headers, timeout=5) |
| 89 | except RequestException as e: |
| 90 | logger.trace("", exc_info=True) |
| 91 | logger.debug("failed to send analytics report %s", str(e)) |
| 92 | |
| 93 | logger.trace("removing report %s", path) |
| 94 | os.remove(path) |
| 95 | |
| 96 | |
| 97 | def _git_remote_url(scm: Optional["Base"]) -> Optional[str]: |