Skip to content

Commit

Permalink
Add basic call to scarf to get anonymous analytics (#1705)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tabossert authored Oct 11, 2023
1 parent 9500d04 commit f0a63e2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.21

* **Adds Scarf analytics**.

## 0.10.20

### Enhancements
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,5 @@ Encountered a bug? Please create a new [GitHub issue](https://github.com/Unstruc

## :chart_with_upwards_trend: Analytics

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).
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).
To opt out of this data collection, you can set the environment variable `SCARF_NO_ANALYTICS=true` before running any `unstructured` commands.
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.20" # pragma: no cover
__version__ = "0.10.21" # pragma: no cover
6 changes: 6 additions & 0 deletions unstructured/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from unstructured.utils import scarf_analytics

logger = logging.getLogger("unstructured")
trace_logger = logging.getLogger("unstructured.trace")

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


# Note(Trevor,Crag): to opt out of scarf analytics, set the environment variable:
# SCARF_NO_ANALYTICS=true. See the README for more info.
scarf_analytics()

# Add the custom log method to the logging.Logger class
logging.Logger.detail = detail # type: ignore
18 changes: 18 additions & 0 deletions unstructured/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import functools
import importlib
import json
import os
import platform
from datetime import datetime
from functools import wraps
from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union, cast

import requests
from typing_extensions import ParamSpec

from unstructured.__version__ import __version__

DATE_FORMATS = ("%Y-%m-%d", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%d+%H:%M:%S", "%Y-%m-%dT%H:%M:%S%z")


Expand Down Expand Up @@ -189,3 +194,16 @@ def validate_date_args(date: Optional[str] = None):
f"The argument {date} does not satisfy the format: "
"YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS or YYYY-MM-DD+HH:MM:SS or YYYY-MM-DDTHH:MM:SStz",
)


def scarf_analytics():
try:
if os.getenv("SCARF_NO_ANALYTICS") != "true" and os.getenv("DO_NOT_TRACK") != "true":
requests.get(
"https://packages.unstructured.io/python-telemetry?version="
+ __version__
+ "&platform="
+ platform.system()
)
except Exception:
pass

0 comments on commit f0a63e2

Please sign in to comment.