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(api): Add delegating no-op meter provider #4858

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hectorhdzg
Copy link
Member

@hectorhdzg hectorhdzg commented Jul 9, 2024

Fixes #3622

Short description of the changes

Adding ProxyMeterProvider and ProxyMeter

Type of change

Please delete options that are not relevant.

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit tests

Checklist:

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

@hectorhdzg hectorhdzg requested a review from a team July 9, 2024 21:53
@hectorhdzg hectorhdzg changed the title feat(api) Add delegating no-op meter provider feat(api): Add delegating no-op meter provider Jul 11, 2024
Copy link
Contributor

@JacksonWeber JacksonWeber left a comment

Choose a reason for hiding this comment

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

LGTM

@maryliag
Copy link
Contributor

Hey Hector, you marked this as "Breaking change", would you mind providing more info on that?
Also, you still have the template part of "How Has This Been Tested?" on your PR description, you might want to update that 😄

@hectorhdzg
Copy link
Member Author

@maryliag sure thing, this is a breaking change because the behavior of metrics.getMeterProvider would be different now, it will return a ProxyMeterProvider instead of the actual registered meter provider, same as current behavior for tracerProvider

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. 🙂 I think for this to be feasible we also need the instruments to be proxies. 🤔

Comment on lines +51 to +53
createGauge(_name: string, _options?: MetricOptions): Gauge {
return this._getMeter().createGauge(_name, _options);
}
Copy link
Member

Choose a reason for hiding this comment

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

There's a certain difficulty in the case of the metrics API vs the trace/logs APIs - there's another layer that needs to be taken into account, which is the instruments.

In Traces, the (no-op) span is an object which is only kept for the time that the span is active. So one span being no-op is not too problematic. For logs, the record is passed straight to the logger so it's also not a problem there. In metrics however, an instrument is instantiated early and is kept over the lifetime of the app. That means that when a user gets a Meter, they usually also create the Instruments already. A later-updated ProxyMeter would therefore be of very limited help as the instruments would also need to be proxies in order to give a smooth experience.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for taking a look @pichlermarc, I wanted to fix #4112, so this is still relevant for us, I understand this change may need a major version update in the api package, maybe this is something I can move to a different branch and start experimenting with Instruments proxies or similar concept, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think the major bump is necessary for this (just as with logs and traces). The types we export from the API are what we guarantee will be there. If there's extra properties on the registered SDK and those are available on the API too in plain JavaScript, then that was never guaranteed to also be there when returned by the API.

We can merge this to a separate branch to experiment with delegating instruments, but I think that could also be done here on this branch, as the PR won't really address the whole problem (instruments created before SDK registration being no-op) as it stands right now.

Comment on lines +40 to +41
export { ProxyMeter, MeterDelegator } from './metrics/ProxyMeter';
export { ProxyMeterProvider } from './metrics/ProxyMeterProvider';
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, would it be required to export this? 🤔 It seems to me that it'd perfectly fine to keep this internal in case we want to change something about it in the future.

Comment on lines +43 to +45
public readonly name: string,
public readonly version?: string,
public readonly options?: MeterOptions
Copy link
Member

Choose a reason for hiding this comment

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

I think all of these could be private, right? 🤔

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.

[api] Implement a delegating no-op MeterProvider
4 participants