-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Label
derive macro
#17
Comments
Ah, maybe we could tackle this use case as well as #34 together by defining the following traits: pub trait ReturnTypeLabel {
/// Implement this method to show the type as a label.
/// Depending on whether the return value is `ok` or `error`,
/// the label will be `ok="label_value"` or `error="label_value"`
fn label_value(&self) -> Option<&'static str> {
None
}
/// Implement this method to control whether this value should be considered
// "successful" or not. If this returns `Some(true)`, the label `result="ok"`
// will be attached. If it returns `Some(false)`, the label `result="error"` will be used.
fn is_ok(&self) -> Option<bool> {
None
}
}
/// When this trait is implemented for an autometrics-instrumented function parameter,
/// the given label key and value will be attached to the generated metric (`label_key="label_value"`).
pub trait ParameterTypeLabel {
fn label_key(&self) -> &'static str;
fn label_value(&self) -> &'static str;
} One thing I'm not sure about is whether there should also be a |
As discussed with @sagacity, we're currently leaning towards having a trait like this: pub trait GetLabel {
fn get_label(&self) -> Option<(&'static str, &'static str)> {
None
}
} This can be used for both return types and parameters. This means we won't have the label keys |
Right now, autometrics adds the return type as a label if the concrete types in a
Result<T, E>
implementInto<&'static str>
.It would be better if Autometrics had its own
Label
derive macro that you would use with your enums. That would make it more explicit that you're opting into making that a label.One thing to consider: if you have a
Result
type, it currently uses the labelok="variant_name"
orerror="variant_name"
. If you wanted to include a label from a function parameter instead of the return value, we'd probably want the label to be something liketype_name="variant_name"
. If we do that, should we change the behavior forResult
s so you have the sametype_name="variant_name"
label or is it helpful to have a standarderror="variant_name
label?The text was updated successfully, but these errors were encountered: