Skip to content

Commit

Permalink
Merge pull request #12762 from RasaHQ/licensed-only-telemetry-3.5
Browse files Browse the repository at this point in the history
[ATO-1493] Send telemetry only if there is License present 3.5
  • Loading branch information
m-vdb authored Sep 18, 2023
2 parents c2eddea + b24fd5b commit 543e952
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
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 "license_hash" not 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

0 comments on commit 543e952

Please sign in to comment.