-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce telemetry in datachain #411
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c40eefa
Introduce telemetry in datachain
amritghimire 3a026f4
Add test and implement telemetry to api call
amritghimire a3e8e45
Env
amritghimire 17a4873
Try new alternative
amritghimire 606e164
Remove unused log param
amritghimire c564916
Reset telemetry sent
amritghimire a46f300
Address PR comments
amritghimire f8f3ea4
Fix tests
amritghimire 8387229
Fix test
amritghimire f90c5af
Update telemetry.py
amritghimire 846f90e
Add import
amritghimire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from datachain.lib.file import File | ||
from datachain.query.schema import Column | ||
from datachain.sql.functions import path as pathfunc | ||
from datachain.telemetry import telemetry | ||
from datachain.utils import uses_glob | ||
|
||
if TYPE_CHECKING: | ||
|
@@ -79,6 +80,7 @@ def parse_listing_uri(uri: str, cache, client_config) -> tuple[str, str, str]: | |
""" | ||
client = Client.get_client(uri, cache, **client_config) | ||
storage_uri, path = Client.parse_url(uri) | ||
telemetry.log_param("client", client.PREFIX) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have telemetry call inside a utility function? |
||
|
||
# clean path without globs | ||
lst_uri_path = ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
from importlib.metadata import PackageNotFoundError, version | ||
|
||
from iterative_telemetry import IterativeTelemetryLogger | ||
|
||
from datachain.utils import env2bool | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def is_enabled(): | ||
""" | ||
Determine if telemetry is enabled based on environment variables and configuration. | ||
""" | ||
# Disable telemetry if running in test mode | ||
if env2bool("DATACHAIN_TEST"): | ||
return False | ||
|
||
# Check if telemetry is disabled by environment variable | ||
disabled = env2bool("DATACHAIN_NO_ANALYTICS") | ||
amritghimire marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if disabled: | ||
logger.debug("Telemetry is disabled by environment variable.") | ||
return False | ||
|
||
logger.debug("Telemetry is enabled.") | ||
return True | ||
|
||
|
||
# Try to get the version of the datachain package | ||
try: | ||
__version__ = version("datachain") | ||
except PackageNotFoundError: | ||
__version__ = "unknown" | ||
|
||
# Initialize telemetry logger | ||
telemetry = IterativeTelemetryLogger("datachain", __version__, is_enabled) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from datachain.lib.dc import DataChain | ||
from datachain.telemetry import telemetry | ||
|
||
|
||
def test_is_enabled(): | ||
assert not telemetry.is_enabled() | ||
|
||
|
||
def test_telemetry_api_call(mocker, tmp_dir): | ||
patch_send = mocker.patch("iterative_telemetry.IterativeTelemetryLogger.send") | ||
telemetry._event_sent = False | ||
|
||
DataChain.from_storage(tmp_dir.as_uri()) | ||
shcheklein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert patch_send.call_count == 1 | ||
args = patch_send.call_args_list[0].args[0] | ||
extra = args.pop("extra") | ||
|
||
assert args == {"interface": "class", "action": "datachain_init", "error": None} | ||
|
||
assert "name" in extra |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop it for now. CLI is not exposed/priority.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if it is not exposed, I believe it would be a good idea to get information if someone is using it IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who is using it?