Skip to content

Commit

Permalink
build: Adding build info in logging
Browse files Browse the repository at this point in the history
  • Loading branch information
trygvis committed Jan 13, 2025
1 parent 340221e commit 536a69b
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 8 deletions.
83 changes: 80 additions & 3 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "skjera"
version = "0.1.0"
edition = "2021"


[features]
default = ["loki"]
otel = []
Expand Down Expand Up @@ -41,3 +42,6 @@ tracing-opentelemetry = { version = "0.28.0", features = [] }
tracing-loki = { version = "0.2.5", optional = true }
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "registry", "fmt"] }
url = "2.5.4"

[build-dependencies]
build-data = "0.2.1"
13 changes: 13 additions & 0 deletions backend/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
build_data::set_GIT_BRANCH();
build_data::set_GIT_COMMIT();
build_data::set_GIT_DIRTY();
// build_data::set_SOURCE_TIMESTAMP();
build_data::no_debug_rebuilds();

let git_commit = build_data::get_git_commit().unwrap();
let git_dirty = build_data::get_git_dirty().unwrap();

let value = format!("{}{}", git_commit, if git_dirty { " dirty" } else { "" });
println!("cargo:rustc-env=VERSION_INFO={value}");
}
8 changes: 4 additions & 4 deletions backend/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ type LoggingSubsystem = LokiLoggingSubsystem;
type LoggingSubsystem = OtelLoggingSubsystem;

pub(crate) fn configure_logging() -> Result<LoggingSubsystem, anyhow::Error> {
let resource = Resource::new_with_defaults(vec![KeyValue::new(
semconv::resource::SERVICE_NAME,
env!("CARGO_CRATE_NAME"),
)]);
let resource = Resource::new_with_defaults(vec![
KeyValue::new(semconv::resource::SERVICE_NAME, env!("CARGO_CRATE_NAME")),
KeyValue::new(semconv::resource::SERVICE_VERSION, crate::VERSION_INFO),
]);

// let span_exporter = SpanExporter::builder().with_tonic().build()?;
// Scaleway only supports HTTP (need to test if protobuf is supported, or we need to use json).
Expand Down
13 changes: 12 additions & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ use tower_sessions::cookie::SameSite::Lax;
use tower_sessions::{MemoryStore, SessionManagerLayer, SessionStore};
use tracing::{debug, info, warn};

// const GIT_BRANCH: &str = env!("GIT_BRANCH");
// const GIT_COMMIT: &str = env!("GIT_COMMIT");
// const GIT_DIRTY: &str = env!("GIT_DIRTY");
// SOURCE_TIMESTAMP doesn't work on my machine: https://gitlab.com/leonhard-llc/ops/-/issues/18
// const SOURCE_TIMESTAMP: &str = env!("SOURCE_TIMESTAMP");

// const VERSION_INFO: &str = concat!("{}{}", env!("GIT_COMMIT"), D);
const VERSION_INFO: &str = env!("VERSION_INFO");

#[tokio::main]
async fn main() {
println!("Starting skjera. version={}", VERSION_INFO);

// We don't care if there is a problem here
let env = dotenv::dotenv();
let is_local = env.is_ok();
Expand All @@ -43,7 +54,7 @@ async fn main() {
}
let logging_subsystem = logging_subsystem.unwrap();

warn!("skjera starting");
warn!(version = VERSION_INFO, "Starting skjera");

let options = match std::env::var("DATABASE_URL") {
Ok(url) => match url.parse::<PgConnectOptions>() {
Expand Down

0 comments on commit 536a69b

Please sign in to comment.