quickwit_telemetry/
lib.rs

1// Copyright (C) 2021 Quickwit, Inc.
2//
3// Quickwit is offered under the AGPL v3.0 and as commercial software.
4// For commercial licensing, contact us at hello@quickwit.io.
5//
6// AGPL:
7// This program is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Affero General Public License as
9// published by the Free Software Foundation, either version 3 of the
10// License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU Affero General Public License for more details.
16//
17// You should have received a copy of the GNU Affero General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20#![allow(clippy::bool_assert_comparison)]
21pub mod payload;
22/// This crate contains  the code responsible for sending usage data to Quickwit inc's server.
23mod sender;
24pub(crate) mod sink;
25
26use once_cell::sync::OnceCell;
27
28use crate::payload::TelemetryEvent;
29pub use crate::sender::is_telemetry_enabled;
30use crate::sender::{TelemetryLoopHandle, TelemetrySender};
31
32pub fn start_telemetry_loop() -> TelemetryLoopHandle {
33    get_telemetry_sender_singleton().start_loop()
34}
35
36fn get_telemetry_sender_singleton() -> &'static TelemetrySender {
37    static INSTANCE: OnceCell<TelemetrySender> = OnceCell::new();
38    INSTANCE.get_or_init(TelemetrySender::default)
39}
40
41/// Sends a telemetry event to Quickwit's server via HTTP.
42///
43/// Telemetry guarantees to send at most 1 request per minute.
44/// Each requests can ship at most 10 messages.
45///
46/// If this methods is called too often, some events will be dropped.
47///
48/// If the http requests fail, the error will be silent.
49///
50/// We voluntarily use an enum here to make it easier for reader
51/// to audit the type of information that is send home.
52pub async fn send_telemetry_event(event: TelemetryEvent) {
53    get_telemetry_sender_singleton().send(event).await
54}
55
56/// This environment variable can be set to disable sending telemetry events.
57pub const DISABLE_TELEMETRY_ENV_KEY: &str = "QW_DISABLE_TELEMETRY";