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 SDK: allow metric readers to filter Meters during Collect() #3617

Open
marcalff opened this issue Jul 24, 2023 · 6 comments
Open

Metrics SDK: allow metric readers to filter Meters during Collect() #3617

marcalff opened this issue Jul 24, 2023 · 6 comments
Assignees
Labels
spec:metrics Related to the specification/metrics directory triage:accepted:needs-sponsor Ready to be implemented, but does not yet have a specification sponsor

Comments

@marcalff
Copy link
Member

marcalff commented Jul 24, 2023

What are you trying to achieve?

For my application, I need to export metrics to an endpoint at different frequencies.

To do so, several PeriodicMetricReaders are defined, for example:

  • Reader A exports data every 15 seconds
  • Reader B exports data every 15 minutes

The meters to export should be different, as the main motivation to have different export frequencies is that:

  • some meters and metrics change rapidly, and/or are not expensive to evaluate (high frequency is desired)
  • other meters and metrics change slowly, and/or are expensive to evaluate (low frequency is desired)

When each reader collects data, every Meter associated with the global MeterProvider is considered.

This is an issue, because the desired behavior is to:

  • export one set of meters with reader A
  • export another set of meters with reader B

What did you expect to see?

When a reader invokes Collect() on a MeterProvider, I would like to be able to filter out which Meter is considered, instead of exporting every meter defined in the MeterProvider.

The filter should be evaluated as a MeterPredicate(), so the SDK can provide its own logic to select (or not) a Meter.

At the very minimum, the predicate should take the meter name as input, so that selecting meters based on a naming convention is possible.

A very desirable feature is to allow the instrumentation interface to add key/value pairs when creating a Meter, so that metadata associated with a meter is available to the filter predicate.

Work around.

Because this is currently not possible based on the existing spec, and the implementation used (opentelemetry-cpp), the work around currently used in the application is to:

  • define a MeterProvider A
  • define a MeterProvider B
  • have the instrumented code defines Meters on the proper MeterProvider (A or B)
  • have the SDK use MeterProvider A in Reader A
  • have the SDK use MeterProvider B in Reader B

so that each reader only sees a subset of meters.

This is highly undesirable, because:

  • This totally defeats the purpose of the MeterProvider singleton
  • The instrumentation is now coupled (by deciding which provider to use to create a meter) with the SDK configuration
  • This only works in monolithic applications, where the same vendor controls both the instrumentation and the SDK configuration
  • When the configuration changes, the instrumented code needs to change as well (to create a metric on the proper meter provider). This totally defeats the purpose of a yaml configuration.

This work around is the only solution I could come up with given the current behavior.

Additional context.

Add any other context about the problem here. If you followed an existing documentation, please share the link to it.

@marcalff marcalff added the spec:metrics Related to the specification/metrics directory label Jul 24, 2023
@marcalff
Copy link
Member Author

PS:

I am aware of this related issue:

which is not a duplicate.

#3617 is about adding predicates to filter out Meters as a whole,
while #3324 is about adding predicates to filter out Instruments individually.

I see the two as complementary.

The rationale for filtering a Meter is that,
for instrumentations that organize meter and metrics into coherent groups,
the filtering is more efficient.

For example, an instrumented library could:

  • expose meter(s) that defines several operating system related metrics
  • expose meter(s) that defines several business related metrics
  • etc

A reader may want to export all operating system metrics to one endpoint,
while a different reader may want to export all business related metrics to a different endpoint.

Filtering on a meter by meter basis is more efficient in terms of overhead,
because every instrument provided by a given meter does not need to be considered if the SDK decides a meter is to be filtered out.

Expressing the predicate (either by allowing only some meters by name, or by looking at meters metadata)
is expected to be easier compared to expressing predicates on instruments.

@asafm
Copy link
Contributor

asafm commented Dec 12, 2023

So you basically want to add an operation to MetricFilter called TestInstrumentationScope() ?

@svrnm svrnm added the triage:deciding:needs-info Not enough information. It is left open to provide the author with time to add more details label May 6, 2024
@svrnm
Copy link
Member

svrnm commented May 6, 2024

hey @marcalff, do you still want to pursue this issue?

@marcalff
Copy link
Member Author

hey @marcalff, do you still want to pursue this issue?

Yes, this is still relevant, and is still blocking in my application.

@marcalff
Copy link
Member Author

@svrnm svrnm added triage:deciding:tc-inbox Needs attention from the TC in order to move forward and removed triage:deciding:needs-info Not enough information. It is left open to provide the author with time to add more details labels Jul 8, 2024
@jack-berg jack-berg added triage:accepted:needs-sponsor Ready to be implemented, but does not yet have a specification sponsor and removed triage:deciding:tc-inbox Needs attention from the TC in order to move forward labels Jul 31, 2024
@jack-berg
Copy link
Member

Discussed in 7/31/24 TC meeting. We think its a useful thing to pursue and adjusted the status to triage:accepted:needs-sponsor accordingly. One implementation option is to extend views to be configurable at the reader level in addition to the meter provider level. We noted that this issue is related to but not necessarily dependent on #3616. Additionally, this may be a duplicate of #1432, and if so we should consolidate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec:metrics Related to the specification/metrics directory triage:accepted:needs-sponsor Ready to be implemented, but does not yet have a specification sponsor
Projects
Status: Spec - Accepted
Development

No branches or pull requests

5 participants