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

fix(sdk-metrics): metric names should be case-insensitive #4059

Merged
merged 4 commits into from
Sep 7, 2023

Conversation

legendecas
Copy link
Member

Which problem is this PR solving?

Fixes #4057

Short description of the changes

  • Warn if the metric name is invalid.
  • Checks two instrument descriptor compatibility with case-insensitive names.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Create instruments with invalid names
  • isDescriptorCompatibleWith

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@legendecas legendecas requested a review from a team August 14, 2023 17:49
@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #4059 (61194cb) into main (9452607) will decrease coverage by 0.51%.
The diff coverage is 100.00%.

❗ Current head 61194cb differs from pull request most recent head e0e7d78. Consider uploading reports for the commit e0e7d78 to get more accurate results

@@            Coverage Diff             @@
##             main    #4059      +/-   ##
==========================================
- Coverage   92.39%   91.89%   -0.51%     
==========================================
  Files         321      320       -1     
  Lines        9282     9248      -34     
  Branches     1973     1961      -12     
==========================================
- Hits         8576     8498      -78     
- Misses        706      750      +44     
Files Changed Coverage
packages/sdk-metrics/src/InstrumentDescriptor.ts 100.00%
packages/sdk-metrics/src/utils.ts 100.00%

descriptor.unit === otherDescriptor.unit &&
descriptor.type === otherDescriptor.type &&
descriptor.valueType === otherDescriptor.valueType
);
}

const NAME_REGEXP = /^[a-z][a-z0-9_.-]{0,62}$/i;
Copy link
Member

Choose a reason for hiding this comment

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

Is always good to include a comment with the description of the regex expression for easier reading
// ASCII string with a length no greater than 63 characters

Copy link
Member

Choose a reason for hiding this comment

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

Names were increased to <=255 character length open-telemetry/opentelemetry-specification#3648

Suggested change
const NAME_REGEXP = /^[a-z][a-z0-9_.-]{0,62}$/i;
// ASCII string with a length no greater than 255 characters
const NAME_REGEXP = /^[a-z][a-z0-9_.-]{0,255}$/i;

@@ -50,6 +52,7 @@ export class Meter implements IMeter {
* Create a {@link Histogram} instrument.
*/
createHistogram(name: string, options?: MetricOptions): Histogram {
this._warnIfInvalidName(name);
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to add the warning during the call to createInstrumentDescriptor?

@dyladan
Copy link
Member

dyladan commented Sep 6, 2023

@legendecas will you have time to make the changes or would it be easier for me to take this over?

@legendecas
Copy link
Member Author

@dyladan sorry for the delay. Updated!

Copy link
Member

@hectorhdzg hectorhdzg left a comment

Choose a reason for hiding this comment

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

LGTM

@haddasbronfman haddasbronfman merged commit 4d662cf into open-telemetry:main Sep 7, 2023
15 checks passed
@legendecas legendecas deleted the metrics/metric-name branch September 7, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metric names are case sensitive
4 participants