Why can 'System.Diagnostics.Metrics' instruments be created with invalid names as per the OpenTelemetry spec? #3250
-
I just spent over 5h debugging my API application due to the fact my custom metrics were not being output on the exporters (console and OTLP): turned out my counter names had spaces in them. Why does the I created a whole sample app and then compared the sample to my API to understand why the sample was working and the API was not... only to test this difference hours later: the counter used in the sample used a I was unaware of the whole internal logging in the library, so I thought I was doing something wrong in the implementation. After finding out that changing the space to a This journey was not a lot of fun, to say the least. I understand that I can't really open a bug on the library now, as this was all "working as intended", however I don't understand why you'd even allow one to create an instrument with an invalid name in the first place. Why not restrict the name rules at creation time? Throw an These days, I expect to take a dependency on a library and start using it intuitively, but that's basically just impossible to do with OpenTelemetry integration. The very fact it logs using EventSource is baffling to me: couldn't you log using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Within OTel, instrument creation is not considered a Startup thing. i.e Instruments can be created any time in the application lifetime. And the general principle in OpenTelemetry, is NOT to throw exceptions at runtime. (The only time OTel will throw exception is at the startup i.e when building the OTel providers, and for any other time - only option is to log and move on..) Also, " Meter's CreateCounter" , is part of the .NET's runtime (https://github.com/dotnet/runtime), and it can be used even outside of OpenTelemetry. So it is unlikely that it can do validations based on OpenTelemetry rules and throw. I think it'd be good to point users to the troubleshooting guide right from the getting-started guides, so it is easier to quickly root cause these issues. Do you agree this doc fix is a good solution, given the limitations I shared above? (Of course, it won't help you now 😆 as you already figured out... but for future users?) |
Beta Was this translation helpful? Give feedback.
Within OTel, instrument creation is not considered a Startup thing. i.e Instruments can be created any time in the application lifetime. And the general principle in OpenTelemetry, is NOT to throw exceptions at runtime. (The only time OTel will throw exception is at the startup i.e when building the OTel providers, and for any other time - only option is to log and move on..)
Also, " Meter's CreateCounter" , is part of the .NET's runtime (https://github.com/dotnet/runtime), and it can be used even outside of OpenTelemetry. So it is unlikely that it can do validations based on OpenTelemetry rules and throw.
I think it'd be good to point users to the troubleshooting guide right from the get…