client_rust
client_rust copied to clipboard
Override derived label value case
By default deriving label values for an enum:
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
enum EnumLabel {
One,
}
Results in a label that matches the variant identifier's, here "One".
To allow compatibility with metrics emitted from other processes, or compatibility when switching crates, this PR allows overriding the default case for EncodeLabelValue for an entire enum or for individual enum entries.
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
#[prometheus(value_case = "lower")]
enum EnumLabel {
One,
Two,
}
Would have labels for values EnumLabel::One and EnumLabel::Two would be "one" and "two" respectively.
The case can be overridden for a single variant as well:
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
enum EnumLabel {
#[prometheus(lower)]
One,
Two,
}
Would have labels for values EnumLabel::One and EnumLabel::Two would be "one" and "Two" respectively.