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

feat(forge): Add semconv_const filter to support semantic convention namespacing rules. #200

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

lquerel
Copy link
Contributor

@lquerel lquerel commented Jun 6, 2024

@lquerel lquerel requested a review from jsuereth as a code owner June 6, 2024 18:12
@lquerel lquerel self-assigned this Jun 6, 2024
@lquerel lquerel added the enhancement New feature or request label Jun 6, 2024
Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.4%. Comparing base (24965a1) to head (fb90c08).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #200   +/-   ##
=====================================
  Coverage   74.3%   74.4%           
=====================================
  Files         44      44           
  Lines       2921    2936   +15     
=====================================
+ Hits        2172    2185   +13     
- Misses       749     751    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@lmolkova lmolkova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

/// to the specified case convention.
pub fn str_to_case_converter(case_convention: &str) -> Result<fn(&str) -> String, Error> {
match case_convention {
"lower_case" => Ok(lower_case),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not strictly related to this PR, do we really need helpers for upper|lower|title - they are supported by jinja directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, the idea was to align all the case converters with the same naming pattern: <mode>_case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a strong opinion, but I'd rather not redefine filters provided by jinja out of the box.

"snake_case" => Ok(snake_case),
"screaming_snake_case" => Ok(screaming_snake_case),
"kebab_case" => Ok(kebab_case),
"screaming_kebab_case" => Ok(screaming_kebab_case),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need kebab case and it's variations for constant names?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove them, but I was wondering if there are programming languages with this type of convention for declaring constants. None come to mind, but perhaps they exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok we probably don't have an SDK for Lisp, but in Common Lisp constants are following the kebab-case pattern.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems Closure also allows -. I don't mind having a specific method for kebab_case constant (maybe not the screaming one though?)

@@ -24,6 +25,7 @@ pub(crate) fn add_tests_and_filters(env: &mut minijinja::Environment<'_>) {
env.add_filter("not_required", not_required);
env.add_filter("instantiated_type", instantiated_type);
env.add_filter("enum_type", enum_type);
env.add_filter("semconv_const", semconv_const);
Copy link
Contributor

@lmolkova lmolkova Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since most of the cases don't make sense in the context of semconv_const (and we only need them as convenience), I'd prefer to have a filter per class of constants:

  • pascal_case_const
  • camel_case_const
  • snake_case_const
  • screaming_snake_case_const

That's all we have in build-tools and it seems it was sufficient for all languages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can follow this pattern if it's already the existing approach (I thought these filters didn't exist, so I didn't check).

Copy link
Contributor

@lmolkova lmolkova Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are called differently: https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/src/opentelemetry/semconv/templating/code.py#L166-L181

but my main point is that semconv_const(name, "title") does not make sense, so instead of allowing someone to use it wrong with arbitrary case value, we can provide specific methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the code to follow your proposal.

Copy link
Contributor

@jsuereth jsuereth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. Only nit: In the docs we should call out this generates constants which follow semantic convention namespacing rules (Underscores are ignored, but . is meaningful).

@lquerel lquerel merged commit 7f675c7 into open-telemetry:main Jun 7, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[feature] Weaver needs to update to_XYZ_case helpers to match namespacing rules in semconv
3 participants