Skip to content

Commit 73d04ae

Browse files
authored
ref(metrics): Add normalization and update set metrics hashing (#658)
Add metrics normalization in accordance with the metrics developer docs. Add metric name, unit, and tag truncation to adhere to the metrics user docs. Add to_envelope for a single Metric instance to facilitate sending metrics from sentry-cli. Change hash function to crc32 as described here, this ensures compatibility between different SDKs using the same metric. Use clone_from instead of clone and clone_into instead of to_owned in a couple of places as suggested by clippy.
1 parent 8c701e8 commit 73d04ae

File tree

13 files changed

+1467
-139
lines changed

13 files changed

+1467
-139
lines changed

Cargo.lock

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

sentry-core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ UNSTABLE_cadence = ["dep:cadence", "UNSTABLE_metrics"]
3131

3232
[dependencies]
3333
cadence = { version = "0.29.0", optional = true }
34+
crc32fast = "1.4.0"
35+
itertools = "0.13.0"
3436
log = { version = "0.4.8", optional = true, features = ["std"] }
3537
once_cell = "1"
3638
rand = { version = "0.8.1", optional = true }
39+
regex = "1.7.3"
3740
sentry-types = { version = "0.32.3", path = "../sentry-types" }
3841
serde = { version = "1.0.104", features = ["derive"] }
3942
serde_json = { version = "1.0.46" }

sentry-core/src/cadence.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ mod tests {
154154

155155
println!("{metrics}");
156156

157-
assert!(metrics.contains("sentry.test.count.with.tags:1|c|#foo:bar|T"));
158-
assert!(metrics.contains("sentry.test.some.count:11|c|T"));
159-
assert!(metrics.contains("sentry.test.some.distr:1:2:3|d|T"));
157+
assert!(metrics
158+
.contains("sentry.test.count.with.tags@none:1|c|#environment:production,foo:bar|T"));
159+
assert!(metrics.contains("sentry.test.some.count@none:11|c|#environment:production|T"));
160+
assert!(metrics.contains("sentry.test.some.distr@none:1:2:3|d|#environment:production|T"));
160161
assert_eq!(items.next(), None);
161162
}
162163
}

sentry-core/src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ impl Client {
207207
}
208208

209209
if event.release.is_none() {
210-
event.release = self.options.release.clone();
210+
event.release.clone_from(&self.options.release);
211211
}
212212
if event.environment.is_none() {
213-
event.environment = self.options.environment.clone();
213+
event.environment.clone_from(&self.options.environment);
214214
}
215215
if event.server_name.is_none() {
216-
event.server_name = self.options.server_name.clone();
216+
event.server_name.clone_from(&self.options.server_name);
217217
}
218218
if &event.platform == "other" {
219219
event.platform = "native".into();

0 commit comments

Comments
 (0)