Skip to content
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

[Feature]: add derives for Key/Value conversions #1685

Open
Sufflope opened this issue Apr 28, 2024 · 0 comments · May be fixed by #1686
Open

[Feature]: add derives for Key/Value conversions #1685

Sufflope opened this issue Apr 28, 2024 · 0 comments · May be fixed by #1686
Labels
enhancement New feature or request triage:todo Needs to be traiged.

Comments

@Sufflope
Copy link

Related Problems?

In my projects I have multiple lightweight types that I want to trace with opentelemetry as key-values, where implementing the necessary conversions feels boilerplatey, and is actually longer than the types and their business logic themselves.

Think something like:

#[derive(strum::Display)]
#[strum(serialize_all = "UPPERCASE")]
enum Method {
    Get,
    Post,
}

impl Method {
    const KEY: &'static str = "method";
}

impl From<Method> for opentelemetry::Value {
    fn from(value: Method) -> Self {
        Self::String(value.to_string().into())
    }
}

impl From<Method> for opentelemetry::KeyValue {
    fn from(value: Method) -> Self {
        Self::new(Method::KEY, value)
    }
}

Describe the solution you'd like:

I would like to suggest derive macros to derive Key, Value, StringValue and KeyValue conversions. Above example would look like:

#[derive(strum::Display, Key, KeyValue, StringValue, Value)]
#[otel(variant = StringValue)]
// or override the key with
// #[otel(key = "custom", variant = StringValue)]
#[strum(serialize_all = "UPPERCASE")]
enum Method {
    Get,
    Post,
}

Considered Alternatives

No response

Additional Context

No response

@Sufflope Sufflope added enhancement New feature or request triage:todo Needs to be traiged. labels Apr 28, 2024
Sufflope added a commit to Sufflope/opentelemetry-rust that referenced this issue Apr 28, 2024
Sufflope added a commit to Sufflope/opentelemetry-rust that referenced this issue Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage:todo Needs to be traiged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant