Skip to content

Commit

Permalink
Report version from git describe in metrics & CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Dec 12, 2024
1 parent 8536411 commit f2221d3
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 3 deletions.
54 changes: 52 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ homepage.workspace = true
repository.workspace = true
publish = false

build = "build.rs"

[lints]
workspace = true

Expand Down Expand Up @@ -82,6 +84,10 @@ mas-templates.workspace = true
mas-tower.workspace = true
oauth2-types.workspace = true

[build-dependencies]
anyhow.workspace = true
vergen-gitcl = { version = "1.0.2", features = ["rustc"] }

[features]
# Features used for the prebuilt binaries
dist = ["mas-config/dist"]
Expand Down
18 changes: 18 additions & 0 deletions crates/cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.

use vergen_gitcl::{Emitter, GitclBuilder, RustcBuilder};

fn main() -> anyhow::Result<()> {
let gitcl = GitclBuilder::default().describe(true, true, None).build()?;
let rustc = RustcBuilder::default().semver(true).build()?;

Emitter::default()
.add_instructions(&gitcl)?
.add_instructions(&rustc)?
.emit()?;

Ok(())
}
1 change: 1 addition & 0 deletions crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum Subcommand {
}

#[derive(Parser, Debug)]
#[command(version = crate::VERSION)]
pub struct Options {
/// Path to the configuration file
#[arg(short, long, global = true, action = clap::ArgAction::Append)]
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/commands/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ impl Options {
let shutdown = ShutdownManager::new()?;
let config = AppConfig::extract(figment)?;

info!(version = crate::VERSION, "Starting up");

if self.migrate {
warn!("The `--migrate` flag is deprecated and will be removed in a future release. Please use `--no-migrate` to disable automatic migrations on startup.");
}
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ mod sync;
mod telemetry;
mod util;

/// The application version, as reported by `git describe` at build time
static VERSION: &str = env!("VERGEN_GIT_DESCRIBE");

#[derive(Debug)]
struct SentryTransportFactory {
client: reqwest::Client,
Expand Down
7 changes: 6 additions & 1 deletion crates/cli/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ fn init_meter(config: &MetricsConfig) -> anyhow::Result<()> {
fn resource() -> Resource {
let resource = Resource::new([
KeyValue::new(semcov::resource::SERVICE_NAME, env!("CARGO_PKG_NAME")),
KeyValue::new(semcov::resource::SERVICE_VERSION, env!("CARGO_PKG_VERSION")),
KeyValue::new(semcov::resource::SERVICE_VERSION, crate::VERSION),
KeyValue::new(semcov::resource::PROCESS_RUNTIME_NAME, "rust"),
KeyValue::new(
semcov::resource::PROCESS_RUNTIME_VERSION,
env!("VERGEN_RUSTC_SEMVER"),
),
]);

let detected = Resource::from_detectors(
Expand Down

0 comments on commit f2221d3

Please sign in to comment.