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

MetricsProcessor #1810

Closed
as-polyakov opened this issue Oct 15, 2020 · 5 comments
Closed

MetricsProcessor #1810

as-polyakov opened this issue Oct 15, 2020 · 5 comments
Labels
Feature Request Suggest an idea for this project SDK

Comments

@as-polyakov
Copy link
Contributor

as-polyakov commented Oct 15, 2020

Is your feature request related to a problem? Please describe.
Similar to SpanProcessor, we need a hook for metrics which would allow users to intercept metrics lifecycle eventы with their own logic.

Describe the solution you'd like

public interface MetricsProcessor {

  /**
   * Called when bind() method is called. Allows to manipulate labels which this
   * instrument is bound to. Particular use case includes enriching lables and/or adding more labels
   * depending on the Context
   * @param ctx context of the operation
   * @param descriptor instrument descriptor
   * @param labels immutable labels. When processors are chained output labels of the previous one is passed as
   * an input to the next one. Last labels returned by a chain of processors are used for bind() operation.
   * @return labels to be used as an input to the next processor in chain or bind() operation if this is the last processor
   */
    Labels onLabelsBound(Context ctx, InstrumentDescriptor descriptor, Labels labels);

  /**
   *  Called when .record() method is called. Allows to manipulate recorded value. When chained input of the next
   *  call is the output of the previous call. Final output is recorded
   * @param ctx context of the operation
   * @param descriptor instrument descriptor
   * @param labels immutable labels. When processors are chained output labels of the previous one is passed as
   * @param value recorded value
   * @return value to be used as an input to the next processor in chain or record() operation if this is the last processor
   */

    long onLongMeasurement(Context ctx, InstrumentDescriptor descriptor, Labels labels, long value);

    double onDoubleMeasurement(Context ctx, InstrumentDescriptor descriptor, Labels labels, double value);
}

Describe alternatives you've considered
Main problem I am trying to address - is to be able to add certain labels to metrics depending on Context (i.e. dynamically). One alternative can be to just do that and make it a standalone feature aka "sticky labels". Had a simple PR for this here. However MetricsProcessor is a more generic solution which can address other use cases.
As for the implementation, instead of using immutable Labels we can pass ReadWriteLables object, this would make it follow the same patter as in SpanProcessor

Additional context
There's a problem with this approach - statically bound instruments will not be able to dynamically add labels during record operation. Since we only intercept onLabelsBound() in case one statically binds an instrument and then uses that to record multiple measurements with different contexts, only first bind call will be intercepted

@as-polyakov as-polyakov added the Feature Request Suggest an idea for this project label Oct 15, 2020
@jkwatson
Copy link
Contributor

jkwatson commented Oct 15, 2020

Hi @parallelstream . Thanks for this suggestion. I think it is an interesting one, but I think that this is something that should be specified cross-language. Can you open up an issue in the specs to start the discussion there? Just as a heads-up, the specs folks might ask for an OTEP to track this, since it's a significant change to the standard metrics SDK implementation.

In addition, we generally like to see draft PRs in several languages with a rough implementation to go along with the spec issue. Would you be willing to do that prototyping work, as well?

Thanks!

@jkwatson jkwatson added the SDK label Oct 15, 2020
@as-polyakov
Copy link
Contributor Author

sure, will do both, @jkwatson

@as-polyakov
Copy link
Contributor Author

Opened the one together with PR here open-telemetry/opentelemetry-specification#1116

@jkwatson
Copy link
Contributor

jkwatson commented Mar 5, 2021

@as-polyakov can we close this issue now that we have the ability to deal with labels in views?

@as-polyakov
Copy link
Contributor Author

resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Suggest an idea for this project SDK
Projects
None yet
Development

No branches or pull requests

2 participants