Skip to content

Commit f2221d3

Browse files
committed
Report version from git describe in metrics & CLI
1 parent 8536411 commit f2221d3

File tree

7 files changed

+88
-3
lines changed

7 files changed

+88
-3
lines changed

Cargo.lock

Lines changed: 52 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ homepage.workspace = true
88
repository.workspace = true
99
publish = false
1010

11+
build = "build.rs"
12+
1113
[lints]
1214
workspace = true
1315

@@ -82,6 +84,10 @@ mas-templates.workspace = true
8284
mas-tower.workspace = true
8385
oauth2-types.workspace = true
8486

87+
[build-dependencies]
88+
anyhow.workspace = true
89+
vergen-gitcl = { version = "1.0.2", features = ["rustc"] }
90+
8591
[features]
8692
# Features used for the prebuilt binaries
8793
dist = ["mas-config/dist"]

crates/cli/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2024 New Vector Ltd.
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-only
4+
// Please see LICENSE in the repository root for full details.
5+
6+
use vergen_gitcl::{Emitter, GitclBuilder, RustcBuilder};
7+
8+
fn main() -> anyhow::Result<()> {
9+
let gitcl = GitclBuilder::default().describe(true, true, None).build()?;
10+
let rustc = RustcBuilder::default().semver(true).build()?;
11+
12+
Emitter::default()
13+
.add_instructions(&gitcl)?
14+
.add_instructions(&rustc)?
15+
.emit()?;
16+
17+
Ok(())
18+
}

crates/cli/src/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum Subcommand {
5151
}
5252

5353
#[derive(Parser, Debug)]
54+
#[command(version = crate::VERSION)]
5455
pub struct Options {
5556
/// Path to the configuration file
5657
#[arg(short, long, global = true, action = clap::ArgAction::Append)]

crates/cli/src/commands/server.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ impl Options {
6060
let shutdown = ShutdownManager::new()?;
6161
let config = AppConfig::extract(figment)?;
6262

63+
info!(version = crate::VERSION, "Starting up");
64+
6365
if self.migrate {
6466
warn!("The `--migrate` flag is deprecated and will be removed in a future release. Please use `--no-migrate` to disable automatic migrations on startup.");
6567
}

crates/cli/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ mod sync;
2424
mod telemetry;
2525
mod util;
2626

27+
/// The application version, as reported by `git describe` at build time
28+
static VERSION: &str = env!("VERGEN_GIT_DESCRIBE");
29+
2730
#[derive(Debug)]
2831
struct SentryTransportFactory {
2932
client: reqwest::Client,

crates/cli/src/telemetry.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,12 @@ fn init_meter(config: &MetricsConfig) -> anyhow::Result<()> {
232232
fn resource() -> Resource {
233233
let resource = Resource::new([
234234
KeyValue::new(semcov::resource::SERVICE_NAME, env!("CARGO_PKG_NAME")),
235-
KeyValue::new(semcov::resource::SERVICE_VERSION, env!("CARGO_PKG_VERSION")),
235+
KeyValue::new(semcov::resource::SERVICE_VERSION, crate::VERSION),
236+
KeyValue::new(semcov::resource::PROCESS_RUNTIME_NAME, "rust"),
237+
KeyValue::new(
238+
semcov::resource::PROCESS_RUNTIME_VERSION,
239+
env!("VERGEN_RUSTC_SEMVER"),
240+
),
236241
]);
237242

238243
let detected = Resource::from_detectors(

0 commit comments

Comments
 (0)