Skip to content

Commit 70f548d

Browse files
nipunn1313Convex, Inc.
authored and
Convex, Inc.
committed
Improve the self-host-beacon with clear messaging and make it opt-out (#33787)
Add clear messaging about how to disable the beacon. GitOrigin-RevId: b6cc700d3e2675fa513696cca80a7f555e6d312a
1 parent 14eb620 commit 70f548d

File tree

5 files changed

+44
-35
lines changed

5 files changed

+44
-35
lines changed

crates/local_backend/build.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
use std::env;
2-
31
use vergen::EmitBuilder;
42

53
fn main() -> anyhow::Result<()> {
6-
// recompile when there's a new git hash for /rev endpoint.
7-
if cfg!(not(debug_assertions)) || env::var("FORCE_EMIT").is_ok() {
8-
// Emit git sha
9-
EmitBuilder::builder()
10-
.git_sha(false)
11-
.git_commit_timestamp()
12-
.emit()?;
13-
} else {
14-
println!("cargo:rustc-env=VERGEN_GIT_SHA=dev");
15-
println!("cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP=0000-00-00T00:00:00.000000000Z");
16-
}
4+
// recompile when there's a new git hash for beacon.
5+
EmitBuilder::builder()
6+
.git_sha(false)
7+
.git_commit_timestamp()
8+
.emit()?;
179
Ok(())
1810
}

crates/local_backend/src/beacon.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,22 @@ pub async fn start_beacon(runtime: ProdRuntime, database: Database<ProdRuntime>)
3838
let globals = db_model.database_globals().await?;
3939

4040
let client = Client::new();
41-
let response = client
42-
.post("https://api.convex.dev/api/self_host_beacon")
43-
.json(&serde_json::json!({
44-
"document_id": globals.id().to_string(),
45-
"migration_version": globals.version,
46-
"compiled_revision": COMPILED_REVISION,
47-
"commit_timestamp": COMMIT_TIMESTAMP,
48-
}))
49-
.send()
50-
.await?;
41+
let sent_json = serde_json::json!({
42+
"database_uuid": globals.id().to_string(),
43+
"migration_version": globals.version,
44+
"compiled_revision": COMPILED_REVISION,
45+
"commit_timestamp": COMMIT_TIMESTAMP,
46+
});
47+
let url = "https://api.convex.dev/api/self_host_beacon";
48+
let response = client.post(url).json(&sent_json).send().await?;
5149

52-
if !response.status().is_success() {
50+
if response.status().is_success() {
51+
tracing::info!(
52+
"Beacon request with json {sent_json} sent successfully to {url}. This \
53+
anonymized data is used to help Convex understand and improve the product. \
54+
You can disable this telemetry by setting the --disable-beacon flag."
55+
);
56+
} else {
5357
tracing::warn!("Beacon request failed with status: {}", response.status());
5458
}
5559
Ok::<(), anyhow::Error>(())

crates/local_backend/src/config.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ pub struct LocalConfig {
6161
#[clap(long, requires = "instance_name")]
6262
pub instance_secret: Option<String>,
6363

64-
/// Identifier (like a user ID) to attach to any senty
65-
/// events generated by this backend.
66-
#[clap(long)]
64+
/// Identifier (like a user ID) to attach to any sentry
65+
/// events generated by this backend. Sentry is disabled
66+
/// by default.
67+
#[clap(long, hide = true)]
6768
pub sentry_identifier: Option<String>,
6869

69-
/// Which directory should local storage use
70+
/// Which directory should file storage use
7071
#[clap(long, default_value = "convex_local_storage")]
7172
local_storage: String,
7273

@@ -75,6 +76,16 @@ pub struct LocalConfig {
7576
/// tests.
7677
#[clap(long)]
7778
pub do_not_require_ssl: bool,
79+
80+
/// self-hosted Convex will periodically communicate with a remote beacon
81+
/// server. This is to help Convex understand and improve the product.
82+
/// If set, the self-host beacon will not be sent.
83+
#[clap(long)]
84+
pub disable_beacon: bool,
85+
86+
/// A tag to identify the self-hosted instance.
87+
#[clap(long, hide = true, default_value = "self-host")]
88+
pub beacon_tag: String,
7889
}
7990

8091
impl fmt::Debug for LocalConfig {

crates/local_backend/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,7 @@ pub async fn make_app(
258258
let origin = config.convex_origin_url();
259259
let instance_name = config.name().clone();
260260

261-
// Start the beacon coroutine to help Convex improve the self-hosted product.
262-
// This sends anonymous usage metrics like database version to help us
263-
// understand how self-hosted instances are being used. You can opt in by
264-
// setting CONVEX_ENABLE_BEACON=1
265-
if std::env::var("CONVEX_ENABLE_BEACON").is_ok_and(|v| v == "1") {
261+
if !config.disable_beacon {
266262
let beacon_future = beacon::start_beacon(runtime.clone(), database.clone());
267263
runtime.spawn("beacon_worker", beacon_future);
268264
}

crates/local_backend/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ use tokio::signal::{
3434
};
3535

3636
fn main() -> Result<(), MainError> {
37-
tracing::info!("Starting a local backend");
3837
let _guard = config_service();
3938
let config = LocalConfig::parse();
40-
tracing::info!("Starting with config {:?}", config);
39+
tracing::info!("Starting a Convex backend");
40+
if !config.disable_beacon {
41+
tracing::info!(
42+
"The self-host Convex backend will periodically communicate with a remote beacon \
43+
server. This is to help Convex understand and improve the product. You can disable \
44+
this telemetry by setting the --disable-beacon flag."
45+
);
46+
}
4147
let sentry = sentry::init(sentry::ClientOptions {
4248
release: Some(format!("local-backend@{}", *SERVER_VERSION_STR).into()),
4349
..Default::default()

0 commit comments

Comments
 (0)