Skip to content

Commit

Permalink
feature(telemetry): new optional api_key
Browse files Browse the repository at this point in the history
feature(telemetry): new optional `custom_api_key`

changelog

better change log
  • Loading branch information
LatentDream committed Nov 29, 2024
1 parent d449c8d commit ab62f3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.2.26dev

* [Feature] New optional custom telemetry `api_key`

## 0.2.25 (2024-02-01)

* [Feature] Updates cloud message
Expand Down
4 changes: 2 additions & 2 deletions src/ploomber_core/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,12 @@ def __init__(self, api_key, package_name, version, *, print_cloud_message=True):
self.print_cloud_message = print_cloud_message

@classmethod
def from_package(cls, package_name, *, print_cloud_message=True):
def from_package(cls, package_name, *, print_cloud_message=True, api_key=None):
"""
Initialize a Telemetry client with the default configuration for
a package with the given name
"""
default_api_key = "phc_P9SpSeypyPwxrMdFn2edOOEooQioF2axppyEeDwtMSP"
default_api_key = api_key or "phc_P9SpSeypyPwxrMdFn2edOOEooQioF2axppyEeDwtMSP"
version = get_package_version(package_name)
return cls(
api_key=default_api_key,
Expand Down
8 changes: 7 additions & 1 deletion tests/telemetry/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,11 +1080,17 @@ def test_check_cloud(tmp_directory, monkeypatch, capsys, last_cloud_check):
def test_from_package():
_telemetry = telemetry.Telemetry.from_package("ploomber-core")

assert _telemetry.api_key
assert _telemetry.api_key == "phc_P9SpSeypyPwxrMdFn2edOOEooQioF2axppyEeDwtMSP"
assert _telemetry.version
assert _telemetry.package_name == "ploomber-core"


def test_from_package_custom_api_key():
_telemetry = telemetry.Telemetry.from_package("ploomber-core", api_key="test_custom_key")

assert _telemetry.api_key == "test_custom_key"


def test_runs_check_cloud(monkeypatch):
mock = Mock()
monkeypatch.setattr(telemetry, "check_cloud", mock)
Expand Down

0 comments on commit ab62f3e

Please sign in to comment.