Skip to content

Commit f0a63e2

Browse files
authored
Add basic call to scarf to get anonymous analytics (#1705)
There is a built in option to not send data by setting an env var, SCARF_NO_ANALYTICS=true. DoD: - When importing or running unstructured package it will make a get call to scarf - When env variable is set to not track, call is not made
1 parent 9500d04 commit f0a63e2

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.21
2+
3+
* **Adds Scarf analytics**.
4+
15
## 0.10.20
26

37
### Enhancements

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,5 @@ Encountered a bug? Please create a new [GitHub issue](https://github.com/Unstruc
256256

257257
## :chart_with_upwards_trend: Analytics
258258

259-
We’ve partnered with Scarf (https://scarf.sh) to collect anonymized user statistics to understand which features our community is using and how to prioritize product decision-making in the future. To learn more about how we collect and use this data, please read our [Privacy Policy](https://unstructured.io/privacy-policy).
259+
We’ve partnered with Scarf (https://scarf.sh) to collect anonymized user statistics to understand which features our community is using and how to prioritize product decision-making in the future. To learn more about how we collect and use this data, please read our [Privacy Policy](https://unstructured.io/privacy-policy).
260+
To opt out of this data collection, you can set the environment variable `SCARF_NO_ANALYTICS=true` before running any `unstructured` commands.

Diff for: unstructured/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.10.20" # pragma: no cover
1+
__version__ = "0.10.21" # pragma: no cover

Diff for: unstructured/logger.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
22

3+
from unstructured.utils import scarf_analytics
4+
35
logger = logging.getLogger("unstructured")
46
trace_logger = logging.getLogger("unstructured.trace")
57

@@ -14,5 +16,9 @@ def detail(self, message, *args, **kws):
1416
self._log(DETAIL, message, args, **kws)
1517

1618

19+
# Note(Trevor,Crag): to opt out of scarf analytics, set the environment variable:
20+
# SCARF_NO_ANALYTICS=true. See the README for more info.
21+
scarf_analytics()
22+
1723
# Add the custom log method to the logging.Logger class
1824
logging.Logger.detail = detail # type: ignore

Diff for: unstructured/utils.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import functools
22
import importlib
33
import json
4+
import os
5+
import platform
46
from datetime import datetime
57
from functools import wraps
68
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union, cast
79

10+
import requests
811
from typing_extensions import ParamSpec
912

13+
from unstructured.__version__ import __version__
14+
1015
DATE_FORMATS = ("%Y-%m-%d", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%d+%H:%M:%S", "%Y-%m-%dT%H:%M:%S%z")
1116

1217

@@ -189,3 +194,16 @@ def validate_date_args(date: Optional[str] = None):
189194
f"The argument {date} does not satisfy the format: "
190195
"YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS or YYYY-MM-DD+HH:MM:SS or YYYY-MM-DDTHH:MM:SStz",
191196
)
197+
198+
199+
def scarf_analytics():
200+
try:
201+
if os.getenv("SCARF_NO_ANALYTICS") != "true" and os.getenv("DO_NOT_TRACK") != "true":
202+
requests.get(
203+
"https://packages.unstructured.io/python-telemetry?version="
204+
+ __version__
205+
+ "&platform="
206+
+ platform.system()
207+
)
208+
except Exception:
209+
pass

0 commit comments

Comments
 (0)