diff --git a/CHANGELOG.md b/CHANGELOG.md index afde608a..88b0a520 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ Data being sent: - Number of DAU (Daily Active Users) - App version -- Instance ID +- Instance ID (unique identifier of the Dawarich instance built by hashing the api key of the first user in the database) The data is being sent to a InfluxDB instance hosted by me and won't be shared with anyone. diff --git a/app/jobs/telemetry_sending_job.rb b/app/jobs/telemetry_sending_job.rb index bdbe96d8..5b84f11a 100644 --- a/app/jobs/telemetry_sending_job.rb +++ b/app/jobs/telemetry_sending_job.rb @@ -7,6 +7,7 @@ class TelemetrySendingJob < ApplicationJob return if ENV['DISABLE_TELEMETRY'] == 'true' data = Telemetry::Gather.new.call + Rails.logger.info("Telemetry data: #{data}") Telemetry::Send.new(data).call end diff --git a/app/services/telemetry/send.rb b/app/services/telemetry/send.rb index c3cce833..46401294 100644 --- a/app/services/telemetry/send.rb +++ b/app/services/telemetry/send.rb @@ -9,6 +9,8 @@ class Telemetry::Send end def call + return if ENV['DISABLE_TELEMETRY'] == 'true' + line_protocol = build_line_protocol response = send_request(line_protocol) handle_response(response) diff --git a/spec/jobs/telemetry_sending_job_spec.rb b/spec/jobs/telemetry_sending_job_spec.rb index dc58ff24..0acef0ee 100644 --- a/spec/jobs/telemetry_sending_job_spec.rb +++ b/spec/jobs/telemetry_sending_job_spec.rb @@ -21,5 +21,17 @@ RSpec.describe TelemetrySendingJob, type: :job do expect(gather_service).to have_received(:call) expect(send_service).to have_received(:call) end + + context 'when DISABLE_TELEMETRY is set to true' do + before do + stub_const('ENV', ENV.to_h.merge('DISABLE_TELEMETRY' => 'true')) + end + + it 'does not send telemetry data' do + described_class.perform_now + + expect(send_service).not_to have_received(:call) + end + end end end