Skip to content
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

[ATO-1493] Only submit telemetry data if there is a license #12764

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1493.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Telemetry data is only send for licensed users.
5 changes: 5 additions & 0 deletions rasa/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ def _send_event(
logger.debug("Skipping request to external service: telemetry key not set.")
return

if not "license_hash" in context:
# only send telemetry data for customers
logger.debug("Skipping telemetry reporting: no license hash found.")
return

headers = segment_request_header(write_key)

resp = requests.post(
Expand Down
22 changes: 20 additions & 2 deletions tests/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ def test_segment_gets_called(monkeypatch: MonkeyPatch):
with responses.RequestsMock() as rsps:
rsps.add(responses.POST, "https://api.segment.io/v1/track", json={})

telemetry._track("test event", {"foo": "bar"}, {"foobar": "baz"})
telemetry._track(
"test event", {"foo": "bar"}, {"foobar": "baz", "license_hash": "foobar"}
)

assert len(rsps.calls) == 1
r = rsps.calls[0]
Expand All @@ -274,11 +276,27 @@ def test_segment_does_not_raise_exception_on_failure(monkeypatch: MonkeyPatch):
rsps.add(responses.POST, "https://api.segment.io/v1/track", body="", status=505)

# this call should complete without throwing an exception
telemetry._track("test event", {"foo": "bar"}, {"foobar": "baz"})
telemetry._track(
"test event", {"foo": "bar"}, {"foobar": "baz", "license_hash": "foobar"}
)

assert rsps.assert_call_count("https://api.segment.io/v1/track", 1)


def test_segment_does_not_get_called_without_license(monkeypatch: MonkeyPatch):
monkeypatch.setenv("RASA_TELEMETRY_ENABLED", "true")
monkeypatch.setenv("RASA_TELEMETRY_WRITE_KEY", "foobar")
telemetry.initialize_telemetry()

with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
rsps.add(responses.POST, "https://api.segment.io/v1/track", body="", status=505)

# this call should complete without throwing an exception
telemetry._track("test event", {"foo": "bar"}, {"foobar": "baz"})

assert rsps.assert_call_count("https://api.segment.io/v1/track", 0)


def test_environment_write_key_overwrites_key_file(monkeypatch: MonkeyPatch):
monkeypatch.setenv("RASA_TELEMETRY_WRITE_KEY", "foobar")
assert telemetry.telemetry_write_key() == "foobar"
Expand Down
Loading