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: gradually add metrics capabilities to Instrumentation::Base #1324

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zvkemp
Copy link
Contributor

@zvkemp zvkemp commented Jan 7, 2025

Proposed implementation for adding optional metrics capabilities to existing instrumentation libraries.

See #1377, #1314, or zvkemp#1 (example of observables) for example implementations. (<- note that these PRs are based on top of this branch, so you may see some duplication between here and there)

Proposed api:

  • Libraries with metrics must add a boolean option called :metrics.
  • Each instrument is configured at compile/boot time — this prevents library authors from creating instruments which are identically named, but have different attributes, callbacks, or advisory parameters, which makes registering them quite difficult. The intention here is that they are declared once in the instrumentation, then subsequent lookups in the instrumentation instance will spawn the instrument (if it has not been spawned already).
  • All of the logic in base/metrics works in the absence of metrics-sdk or metrics-api, so library authors can add metrics to libraries without requiring users to use the metrics system at all. This means that any of the instrument-lookup instance methods may return nil (so this will need to be handled, e.g. via short-circuiting https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/1377/files#diff-6732dfa68439092c8ae9c61ca4dfd067a76e48f9cb6e37768b12aedb5cfb7f50R20)

TODO:

  • requires test: test helpers for metrics opentelemetry-ruby#1804
  • FIXME should instruments not declared in advance return a valid instrument anyway?
  • ensure instrument opts are forwarded correctly, or validate them when they are declared
  • dependency load order is very important here; if the Metrics API isn't loaded before Instrumentation::Base, the conditional definitions are not run. We either need to hook into Kernel.require and detect when Metrics is loaded (probably too perilous to really consider, as any instrumentations with conditional metrics will need to be re-evaluated at this time), or eagerly attempt to require the metrics-api gem when Instrumentation::Base is loaded.

@zvkemp zvkemp force-pushed the base-metrics branch 2 times, most recently from 7def994 to f060a57 Compare January 14, 2025 16:46
@zvkemp zvkemp force-pushed the base-metrics branch 3 times, most recently from bccd9f5 to 5f393f8 Compare January 24, 2025 18:55
@zvkemp zvkemp mentioned this pull request Jan 29, 2025
3 tasks
@zvkemp zvkemp force-pushed the base-metrics branch 3 times, most recently from ef747e7 to 8a538f8 Compare January 31, 2025 15:13
@zvkemp zvkemp changed the title gradually add metrics capabilities to Instrumentation::Base feat: gradually add metrics capabilities to Instrumentation::Base Jan 31, 2025
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.

1 participant