Skip to content

Conversation

hannahhaering
Copy link
Contributor

@hannahhaering hannahhaering commented Aug 28, 2025

Fixes #2532

Changes

I moved the validation of view name and instrument name into Guard helpers. I improved the log message, specifying the incorrect metric name, as suggested in the issue.

The code has changed quite a bit since this issue was opened, so I'm not entirely sure whether my approach matches the original intent.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Aug 28, 2025
@hannahhaering hannahhaering marked this pull request as ready for review August 28, 2025 15:55
@hannahhaering hannahhaering requested a review from a team as a code owner August 28, 2025 15:55
Copy link
Contributor

github-actions bot commented Sep 6, 2025

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Sep 6, 2025
Comment on lines 52 to 56
// Note: We don't use static readonly here because some customers
// replace this using reflection which is not allowed on initonly static
// fields. See: https://github.com/dotnet/runtime/issues/11571.
// Customers: This is not guaranteed to work forever. We may change this
// mechanism in the future do this at your own risk.
Copy link
Member

Choose a reason for hiding this comment

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

It seems to be broking #4136.

In general, it is not against OTel promises, but it might be still useful for @dpk83.

@dpk83, what is your perspective on changes?

@CodeBlanch, FYI as you introduced this functionality.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I make the changes in the contrib repo or is there anything else left to do?

@github-actions github-actions bot removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Sep 9, 2025
internal static class Guard
internal static partial class Guard
{
// Note: We don't use static readonly here because some customers
Copy link
Member

Choose a reason for hiding this comment

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

One more thing, for now, new logic seems to be related only to metrics. Maybe you could put all this stuff to separate class under src/OpenTelemetry/Metrics/MetricsGuard.cs (better name more than weslcomed)?

Do you think that we need some new unit tests?

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'm currently working on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the other hand, this doesn't need to be a regular expression. Length check and IndexOfAny would do the job.

Copy link

codecov bot commented Sep 15, 2025

Codecov Report

❌ Patch coverage is 38.88889% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.64%. Comparing base (5f66728) to head (ed6a109).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rc/OpenTelemetry/Metrics/Reader/MetricReaderExt.cs 8.33% 11 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #6457   +/-   ##
=======================================
  Coverage   86.63%   86.64%           
=======================================
  Files         258      259    +1     
  Lines       11888    11887    -1     
=======================================
  Hits        10299    10299           
+ Misses       1589     1588    -1     
Flag Coverage Δ
unittests-Project-Experimental 86.59% <38.88%> (+0.25%) ⬆️
unittests-Project-Stable 86.53% <38.88%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../Metrics/Builder/MeterProviderBuilderExtensions.cs 98.54% <100.00%> (-0.02%) ⬇️
...lemetry/Metrics/Builder/MeterProviderBuilderSdk.cs 100.00% <ø> (+1.63%) ⬆️
src/OpenTelemetry/Metrics/MeterProviderSdk.cs 93.36% <100.00%> (ø)
src/OpenTelemetry/Metrics/MetricGuard.cs 100.00% <100.00%> (ø)
...elemetry/Metrics/View/MetricStreamConfiguration.cs 100.00% <100.00%> (ø)
...rc/OpenTelemetry/Metrics/Reader/MetricReaderExt.cs 87.28% <8.33%> (-4.68%) ⬇️

... and 2 files with indirect coverage changes

@hannahhaering hannahhaering marked this pull request as draft September 15, 2025 02:59
@hannahhaering hannahhaering marked this pull request as ready for review September 16, 2025 19:22
Comment on lines +28 to +30
* Moved the `InstrumentNameRegex` from `MeterProviderBuilderSdk` to `Guard`.
([#6457](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6457))

Copy link
Member

Choose a reason for hiding this comment

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

This sounds like an internal implementation detail - all users need to know is what the external-facing behaviour change is.

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 agree. I added it to the changelog because the regex is public and someone may change it using reflection:
#6457 (comment)

I can also omit this in the changelog, if it is not necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Ah OK - I didn't realise it was public.

Copy link
Member

Choose a reason for hiding this comment

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

It wasn't . It was known internal feature used by reflection. Mostly by MS teams.

Copy link
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Sep 27, 2025
@Kielek Kielek removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve instrument name validation and log messages
5 participants