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

Metrics usage examples - browser client #461

Open
cristianmadularu opened this issue Aug 8, 2023 · 7 comments
Open

Metrics usage examples - browser client #461

cristianmadularu opened this issue Aug 8, 2023 · 7 comments

Comments

@cristianmadularu
Copy link

cristianmadularu commented Aug 8, 2023

Hi,

I am using the js-libp2p-gossipsub lib in a browser application and I am interested in consuming the metrics support the library exposes. Our application is primarlyl using OTLP so I am interested in capturing the gossipsub metrics and convert them to OTLP equivalents, however I was not able to find any usage documentation.

I did see that the options interface exposes two properties 'metricsRegister' and 'metricsTopicStrToLabel' but not much into how to use them. I started looking in the actual code implementation in order to get an idea, but I was wondering if there are any examples/documentation available.

Thank you

@wemeetagain
Copy link
Member

Unfortunately there is no good documentation. And the MetricsRegister interface is very opinionated and overly dependent on https://github.com/ChainSafe/lodestar/blob/unstable/packages/beacon-node/src/metrics/utils/registryMetricCreator.ts#L12, requires implementing some specific methods (gauge, histogram, avgMinMax). This could/should be cleaned up cc @dapplion @tuyennhv

If you'd like an example, take a look here:
https://github.com/ChainSafe/lodestar/blob/unstable/packages/beacon-node/src/metrics/utils/registryMetricCreator.ts#L12
You can create a RegistryMetricCreator instance and pass that as the metricsRegister in the gossipsub constructor / init function.

Then, with a reference to the instance, you should be able to consume the metrics with methods described here: https://github.com/siimon/prom-client#register

@cristianmadularu
Copy link
Author

Thank you @wemeetagain

I'll have a look 👍

@cristianmadularu
Copy link
Author

cristianmadularu commented Aug 9, 2023

Would you happen to know why the instrument types(Gauge, Histogram, AvgMinMax) and their config types are not exported? (Since they are being used in the exported MetricsRegister interface).

Since we are using this library in a browser application, we are not planning on adding a dependency to the promclient lib.

image

Thank you!

PS: For now, I have copied the types in my code just to get me going but I really wish I didn't have to do that :)

@wemeetagain
Copy link
Member

@cristianmadularu the types you requested are now exported as of v10.1.0

@cristianmadularu
Copy link
Author

Thank you! :)

@dapplion
Copy link
Contributor

We should drop avgMinMax and have a regular prometheus interface that's generic

@cristianmadularu
Copy link
Author

cristianmadularu commented Aug 17, 2023

That would be very nice :) I would also suggest considering exposing an OTLP set of metrics in order to avoid being locked in any particular set of tools/vendors.

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

No branches or pull requests

3 participants