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(sdk-metrics-base): meter registration #2666

Merged
merged 7 commits into from
Jan 8, 2022

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Dec 15, 2021

Which problem is this PR solving?

Register created meters in MeterProviderSharedState so that their metric instruments can be collected.

Extracted from #2636
Related: #2593

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • MeterProvider.getMeter

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 December 15, 2021 17:19
@codecov
Copy link

codecov bot commented Dec 15, 2021

Codecov Report

Merging #2666 (f5220ac) into main (354c002) will increase coverage by 0.33%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #2666      +/-   ##
==========================================
+ Coverage   92.72%   93.05%   +0.33%     
==========================================
  Files         155      155              
  Lines        5372     5373       +1     
  Branches     1133     1133              
==========================================
+ Hits         4981     5000      +19     
+ Misses        391      373      -18     
Impacted Files Coverage Δ
...ckages/opentelemetry-sdk-metrics-base/src/Meter.ts 78.57% <0.00%> (+0.52%) ⬆️
...emetry-sdk-metrics-base/src/export/MetricReader.ts 100.00% <0.00%> (+2.70%) ⬆️
...emetry-core/src/platform/node/RandomIdGenerator.ts 93.75% <0.00%> (+6.25%) ⬆️
...pentelemetry-sdk-metrics-base/src/MeterProvider.ts 57.50% <0.00%> (+40.00%) ⬆️

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

Implementation itself looks fine, but the identity issues surrounding schema url might be confusing for users. Saying a new meter is always created seems much simpler to document and understand.

constructor(options: MeterProviderOptions) {
this._sharedState = new MeterProviderSharedState(options.resource ?? Resource.empty());
constructor(options?: MeterProviderOptions) {
this._sharedState = new MeterProviderSharedState(options?.resource ?? Resource.empty());
}

getMeter(name: string, version = '', options: metrics.MeterOptions = {}): metrics.Meter {
Copy link
Member

Choose a reason for hiding this comment

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

If the schema URL is part of the identity, shouldn't it be a top-level property and not buried in options?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, there is only one requirement for meter creation:

Implementations MUST NOT require users to repeatedly obtain a Meter again with the same name+version+schema_url to pick up configuration changes. This can be achieved either by allowing to work with an outdated configuration or by ensuring that new configuration applies also to previously returned Meters.
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#get-a-meter

It also suggests that:

It is unspecified whether or under which conditions the same or different Meter instances are returned from this function.

So, as long as we propagate the configurations to all meters created without another getMeter call, it should be spec-compliant.

As we are using the MeterProviderSharedState pattern to share the meter provider configurations, I'd believe we've already met the bar that the created meters can automatically get configuration updates without the need to call getMeter again. So it seems that we actually don't have to return an identical meter for each getMeter call.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another problem is that the spec is said instrument names are unique in a meter:

Meter implementations MUST return an error when multiple Instruments are registered under the same Meter instance using the same name.
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#instrument

So, if we are going to return a new meter instance for every getMeter, how do we define "same Meter instance" in the above context?

Copy link
Member Author

Choose a reason for hiding this comment

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

Submitted a spec issue for this: open-telemetry/opentelemetry-specification#2226

# Conflicts:
#	experimental/packages/opentelemetry-sdk-metrics-base/src/state/MeterProviderSharedState.ts
#	packages/exporter-trace-otlp-grpc/protos
#	packages/exporter-trace-otlp-proto/protos
@legendecas legendecas changed the title feat(sdk-metrics-base): meter identity feat(sdk-metrics-base): meter registration Jan 6, 2022
@legendecas
Copy link
Member Author

legendecas commented Jan 6, 2022

@dyladan I updated the PR to just register the created meters to MeterProviderSharedState so that we can wire up basic API usage like collecting metrics with MetricReaders. I'll wait for the meter identity spec issue to be resolved before submitting another PR for it.

# Conflicts:
#	experimental/packages/opentelemetry-sdk-metrics-base/test/state/MetricCollector.test.ts
@vmarchaud vmarchaud added the enhancement New feature or request label Jan 8, 2022
@vmarchaud vmarchaud merged commit 6b94e26 into open-telemetry:main Jan 8, 2022
@legendecas legendecas deleted the metrics-ff/meter branch January 9, 2022 02:05
rauno56 pushed a commit to rauno56/opentelemetry-js that referenced this pull request Jan 14, 2022
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
None yet
Development

Successfully merging this pull request may close these issues.

3 participants