-
Notifications
You must be signed in to change notification settings - Fork 84
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
Dynamically nameable metrics #160
Comments
I'm open to reviewing a PR in this direction but won't be able to do much else to assist your efforts in this. |
See tracing docs, search on page for "constant". There's no good heading to generate a better link for you. You can use constant expressions for field names, so does that solve the issue for you? The example shows just span, but I think it works for events too. I also think there is a bug that if you try to use constants as the first field it does not currently work, so try adding a dummy field first. |
@mladedav I did some more digging. This is what I ran into initially when I first tested this:
I think I should've been more thorough when checking the docs. I assumed that all syntax for the event macro would be valid on the shorthands, but this is not the case. Sorry - I am new to the Rust ecosystem! The following does work:
I will leave this issue open for now incase a runtime evaluated solution wants to be discussed, but I think this is actually sufficient for most use cases. Thanks :) I will edit the main issue body to reflect what the issue now represents, but the title can remain the same as the original request was for runtime nameable metrics. |
The shorthands should work the same as the I think you just bumped into the constant name as the first field bug I mentioned, i.e. I think that this would work: #[test]
fn it_works() {
const METRIC_HANDLE: &str = "counter.test";
info!(foo = 1, { METRIC_HANDLE} = 1);
} |
@mladedav does this then only work if you want at least 1 attribute on your metric? |
From what I remember, just the first thing cannot be a field with const name. I think it was because fields can be optionally enclosed in curly brackets for historical reasons. If you use It's just a bug which I think was fixed but not yet released. |
Feature Request
I would like a way for metrics to be nameable at runtime.
Motivation
With the current API, I don't believe you can pass in a metric name which is determined at runtime. This is fully within the realm of possibility when using the OpenTelemtry API, so it would be reasonable for this crate to support that somehow.
Proposal
I assume the most reasonable way might be a reserved field name for the metric name and metric value. However, I am not sure how this would interact with the existing interface.
Below is something like what I just described, but if there is any better way I'd prefer that. I just don't know how much flexibility or control we have here as we are using the tracing macros.
The text was updated successfully, but these errors were encountered: