test: Add tests for MeterProvider API#1441
Conversation
- Make `name` a required argument
- Add test for `MeterProvider#meter`
- Add test for `OpenTelemetry.{meter_provider,meter_provider=}`
| # Returns a {Meter} instance. | ||
| # | ||
| # @param [optional String] name Instrumentation package name | ||
| # @param [String] name Instrumentation package name | ||
| # @param [optional String] version Instrumentation package version | ||
| # | ||
| # @return [Meter] | ||
| def meter(name = nil, version = nil) | ||
| def meter(name, version = nil) | ||
| @meter ||= Meter.new | ||
| end |
There was a problem hiding this comment.
I noticed that in Metrics API we have meter(name = nil, version = nil) but we have meter(name, version = nil) in Metrics SDK
Specification doesn't say name must be provided, however name is one of the identifying fields and all the other args are optional. Because of that, I wonder if we should make at least name required here in the API: https://opentelemetry.io/docs/reference/specification/metrics/api/#get-a-meter
Looking at JavaScript implementation as an example, name is required in the API: https://github.com/open-telemetry/opentelemetry-js/blob/cd0d8806e0ed4c9dc68be9773770349c712e5e76/api/src/metrics/MeterProvider.ts
Let me know what you think!
There was a problem hiding this comment.
Also, we could take the opportunity to turn version into a keyword arg if that's the pattern we would like to have like suggested here: #1237 (comment)
def meter(name, version: nil)And in the future,
def meter(name, version: nil, schema_url: nil, attributes: {})There was a problem hiding this comment.
I think named arguments makes sense. There's some inconsistency between this and the Tracing API because the Metrics API explicitly requires a name whereas the Tracing API waffled a little on whether it was required, whether it was honoured (an implementation can ignore it), and what to do when an invalid value was passed. IMO we should move Metrics in our preferred direction and subsequently update the Tracing interface to match.
| after do | ||
| # TODO: After Metrics SDK is incoporated into OpenTelemetry SDK, move this | ||
| # to OpenTelemetry::TestHelpers.reset_opentelemetry | ||
| OpenTelemetry.instance_variable_set( | ||
| :@meter_provider, | ||
| OpenTelemetry::Internal::ProxyMeterProvider.new | ||
| ) | ||
| end | ||
|
|
||
| describe '#meter_provider and #meter_provider=' do | ||
| it 'initializes with a global instance of ProxyMeterProvider' do | ||
| assert(OpenTelemetry.meter_provider.is_a?(OpenTelemetry::Internal::ProxyMeterProvider)) | ||
| end |
There was a problem hiding this comment.
I'd like to exercise that OpenTelemetry.meter_provider initially returns a ProxyMeterProvider. This test kind of exercises that, but it is not ideal. If this test runs first, then it exercises that; otherwise, it doesn't: it just exercises the reset
I was thinking if a proper reset would be calling load 'opentelemetry-metrics-api.rb to reload the file instead of manually setting @meter_provider with instance_variable_set like OpenTelemetry::TestHelpers suggests
There was a problem hiding this comment.
Yeah it's a bit tricky if you're looking to test the initial state before any tests run. I didn't put too much importance on this because in reality all you're testing with that is that this line of code contains no syntax errors.
If this test runs first, then it exercises that; otherwise, it doesn't: it just exercises the reset
If there was an issue in this code path, it would show up as a flakey test, which is not nothing.
|
Hey @elias19r, sorry for the delay on reviewing this. I'll carve out some time for it tomorrow. Thanks for the PR, excited to see some outside contributions to the metrics endeavour! |
Ruby 2.6 is the mininum version we support
|
My |
namea required argumentMeterProvider#meterOpenTelemetry.{meter_provider,meter_provider=}Also,