open-telemetry / open-telemetry/opentelemetry-ruby

Ability to find metrics instruments after they are created

Open
#1,896 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

keep metrics
Dominant language
Ruby
Stars
606
Forks
301
Avg merge
3d 19h
Merged PRs (30d)
42

Description

Currently the SDK supports create methods like create_counter and create_observable_gauge.

Once created however, it seems there is no way to retrieve them. You must keep a reference to the instrument if you want to call add or record on it from other places in your application.

Assuming I do not want to use global variables, this results in having to manage my own instrument registry. Example:
https://github.com/wsmoak/rails-otel-demo/blob/2c72d4538e5bb314a860b9b512fd4d3c6b32eabe/lib/rails_otel_demo/metrics.rb#L1-L13

module RailsOTelDemo
  class Metrics

    OTEL_METER = OpenTelemetry.meter_provider.meter('rails-otel-demo-meter')

    def self.instrument_registry
      @instrument_registry ||= {}
    end

    def self.find_instrument(instrument_name)
      instrument_registry[instrument_name] || raise("Instrument '#{instrument_name}' not found")
    end

The Meter already has its own instrument registry, it would be nice to have a find method in addition to create.

Related: it really should be possible to remove instruments as well. This is being discussed in https://github.com/open-telemetry/opentelemetry-specification/issues/2232 .

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the Meter implementation, its instrument registry, and the existing create_counter and create_observable_gauge methods. The issue is done when callers can retrieve an already-created instrument through a Meter find method without maintaining a separate registry; the related removal discussion is separate.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
observability
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.