Skip to content

Commit

Permalink
[autometrics 1.0 compliance] add autometrics.version to build_info (
Browse files Browse the repository at this point in the history
#154)

* add `autometrics.version` to `build_info`

* update changelog

* use dot notation

* use a const to prevent repetition
  • Loading branch information
mellowagain authored Nov 13, 2023
1 parent b887363 commit 4cfd2f3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
The [Autometrics specification v1.0.0](https://github.com/autometrics-dev/autometrics-shared/blob/main/specs/autometrics_v1.0.0.md) has been released.
The following changes are made in order to bring the release in compliance with the spec:

- Added `repository_url` and `repository_provider` as `build_info` labels. They can be
- Added `repository.url` and `repository.provider` as `build_info` labels. They can be
configured either through environment variables or automatically based on your `Cargo.toml`
`package.repository` value (only GitHub, GitLab and BitBucket) (#152)
- Added `autometrics.version` as `build_info` label, specifying the autometrics spec
version that we are targeting. It is currently hardcoded to `1.0.0` (#154)

## [0.6.0](https://github.com/autometrics-dev/autometrics-rs/releases/tag/v0.5.0) - 2023-08-08

Expand Down
5 changes: 5 additions & 0 deletions autometrics/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Version of the autometrics spec we are targeting
pub const AUTOMETRICS_SPEC_TARGET: &str = "1.0.0";

// Metrics
pub const COUNTER_NAME: &str = "function.calls";
pub const HISTOGRAM_NAME: &str = "function.calls.duration";
Expand Down Expand Up @@ -41,3 +44,5 @@ pub const REPO_URL_KEY: &str = "repository.url";
pub const REPO_URL_KEY_PROMETHEUS: &str = "repository_url";
pub const REPO_PROVIDER_KEY: &str = "repository.provider";
pub const REPO_PROVIDER_KEY_PROMETHEUS: &str = "repository_provider";
pub const AUTOMETRICS_VERSION_KEY: &str = "autometrics.version";
pub const AUTOMETRICS_VERSION_KEY_PROMETHEUS: &str = "autometrics_version";
7 changes: 5 additions & 2 deletions autometrics/src/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct BuildInfoLabels {
pub(crate) service_name: &'static str,
pub(crate) repo_url: &'static str,
pub(crate) repo_provider: &'static str,
pub(crate) autometrics_version: &'static str,
}

impl BuildInfoLabels {
Expand All @@ -31,7 +32,8 @@ impl BuildInfoLabels {
branch,
service_name: &get_settings().service_name,
repo_url,
repo_provider
repo_provider,
autometrics_version: AUTOMETRICS_SPEC_TARGET
}
}

Expand All @@ -42,7 +44,8 @@ impl BuildInfoLabels {
(BRANCH_KEY, self.branch),
(SERVICE_NAME_KEY, self.service_name),
(REPO_URL_KEY, self.repo_url),
(REPO_PROVIDER_KEY, self.repo_provider)
(REPO_PROVIDER_KEY, self.repo_provider),
(AUTOMETRICS_VERSION_KEY, self.autometrics_version)
]
}

Expand Down
4 changes: 3 additions & 1 deletion autometrics/src/tracker/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ static BUILD_INFO: Lazy<IntGaugeVec> = Lazy::new(|| {
SERVICE_NAME_KEY_PROMETHEUS,
REPO_URL_KEY_PROMETHEUS,
REPO_PROVIDER_KEY_PROMETHEUS,
AUTOMETRICS_VERSION_KEY_PROMETHEUS,
],
get_settings().prometheus_registry.clone()
)
Expand Down Expand Up @@ -146,7 +147,8 @@ impl TrackMetrics for PrometheusTracker {
build_info_labels.branch,
build_info_labels.service_name,
build_info_labels.repo_url,
build_info_labels.repo_provider
build_info_labels.repo_provider,
AUTOMETRICS_SPEC_TARGET
])
.set(1);
});
Expand Down

0 comments on commit 4cfd2f3

Please sign in to comment.