use git commit sha as version in traces (#287)

V3_GIT_ORIGIN_REV_ID: 9f0ff932d432802ddb9b6688ba7c0b738e2af201
This commit is contained in:
Puru Gupta 2024-01-09 12:43:02 +05:30 committed by hasura-bot
parent e88ddcdbe4
commit 0c4d0e7341
3 changed files with 23 additions and 2 deletions

View File

@ -2,6 +2,7 @@
name = "engine"
version = "3.0.0"
edition = "2021"
build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -20,8 +20,8 @@ use std::path::PathBuf;
use std::{fmt::Display, sync::Arc};
use tower_http::trace::TraceLayer;
use tracing_util::{
add_event_on_active_span, set_status_on_current_span, ErrorVisibility, SpanVisibility,
TraceableError, TraceableHttpResponse,
add_event_on_active_span, set_status_on_current_span, AttributeVisibility, ErrorVisibility,
SpanVisibility, TraceableError, TraceableHttpResponse,
};
#[derive(Parser)]
@ -42,6 +42,11 @@ struct EngineState {
auth_config: AuthConfig,
}
const GIT_HASH_VERSION: &str = env!(
"GIT_HASH",
"Unable to start engine: unable to fetch the current git hash to use as trace version"
);
#[tokio::main]
async fn main() {
let server = ServerOptions::parse();
@ -159,6 +164,11 @@ async fn graphql_request_tracing_middleware<B: Send>(
Ok(tracer
.in_span_async(path, SpanVisibility::User, || {
tracing_util::set_attribute_on_active_span(
AttributeVisibility::Internal,
"version",
GIT_HASH_VERSION,
);
Box::pin(async move {
let response = next.run(request).await;
TraceableHttpResponse::new(response, path)

10
v3/engine/build.rs Normal file
View File

@ -0,0 +1,10 @@
use std::process::Command;
fn main() {
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}