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

Remove Observable Instrument Observe Method #3590

Closed
MrAlias opened this issue Jan 13, 2023 · 1 comment · Fixed by #3586
Closed

Remove Observable Instrument Observe Method #3590

MrAlias opened this issue Jan 13, 2023 · 1 comment · Fixed by #3586
Assignees
Labels
area:metrics Part of OpenTelemetry Metrics

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Jan 13, 2023

The asynchronous Gauges, UpDownCounters, and Counters all currently export an Observe method. This is unneeded once #3584 is merged.

This method should be removed for the following reasons...

  1. It is not used by an OTel user for any valid operation
  2. If an OTel user calls this method it will only ever error
  3. The specification does not specify this method

It is not used by an OTel user for any valid operation

For a single instrument callback, the appropriate *Observer type is used to record a measurement.

// Float64Callback is a function registered with a Meter that makes
// observations for a Float64Observer it is registered with.
//
// The function needs to complete in a finite amount of time and the deadline
// of the passed context is expected to be honored.
//
// The function needs to make unique observations across all registered
// Float64Callbacks. Meaning, it should not report measurements with the same
// attributes as another Float64Callbacks also registered for the same
// instrument.
//
// The function needs to be concurrent safe.
type Float64Callback func(context.Context, Float64Observer) error

// Int64Callback is a function registered with a Meter that makes
// observations for an Int64Observer it is registered with.
//
// The function needs to complete in a finite amount of time and the deadline
// of the passed context is expected to be honored.
//
// The function needs to make unique observations across all registered
// Int64Callback. Meaning, it should not report measurements with the same
// attributes as another Int64Callbacks also registered for the same
// instrument.
//
// The function needs to be concurrent safe.
type Int64Callback func(context.Context, Int64Observer) error

And for a multi-instrument measurement, the Observer type is used once #3584 is merged.

// Callback is a function registered with a Meter that makes observations for
// the set of instruments it is registered with. The Observer parameter is used
// to record measurment observations for these instruments.
//
// The function needs to complete in a finite amount of time and the deadline
// of the passed context is expected to be honored.
//
// The function needs to make unique observations across all registered
// Callbacks. Meaning, it should not report measurements for an instrument with
// the same attributes as another Callback will report.
//
// The function needs to be concurrent safe.
type Callback func(context.Context, Observer) error

If an OTel user calls this method it will only ever error

// Observe logs an error.
func (o *observable[N]) Observe(ctx context.Context, val N, attrs ...attribute.KeyValue) {
var zero N
err := errors.New("invalid observation recording")
global.Error(err, "dropping measurement",
"name", o.name,
"description", o.description,
"unit", o.unit,
"number", fmt.Sprintf("%T", zero),
)
}

The specification does not specify this method

As stated in the metric API specification:

Asynchronous instruments have associated callback functions which are responsible for reporting Measurements.

Other than this statement, which is repeated in a few places, the only normative statements made about a recording API for these instruments is in how these callbacks care associated with the instruments

The API MUST support creation of asynchronous instruments by passing zero or more callback functions to be permanently registered to the newly created instrument.

The API SHOULD support registration of callback functions associated with asynchronous instruments after they are created.

Callbacks registered at the time of instrument creation MUST apply to the single instruments which is under construction.

Callbacks registered after the time of instrument creation MAY be associated with multiple instruments.

Multiple-instrument Callbacks MUST be associated at the time of registration with a declared set of asynchronous instruments from the same Meter instance.

There is no mention of a direct way to record an observation with an Observer method.

The metric API specification goes further to say how these Callbacks should be defined:

It is RECOMMENDED that the API authors use one of the following forms for the callback function:

  • The list (or tuple, etc.) returned by the callback function contains (Instrument, Measurement) pairs.
  • the Observable Result parameter receives an additional (Instrument, Measurement) pairs

Additionally...

Idiomatic APIs for multiple-instrument Callbacks MUST distinguish the instrument associated with each observed Measurement value.

Specifically here, the specification is requiring explicit association of a registered instrument to a Measurement and it makes a recommendation on how to achieve this with a returned list or result parameter. It specifically does not say that even within a callback an Observe method must, should, or even may be called.

@MrAlias MrAlias added the area:metrics Part of OpenTelemetry Metrics label Jan 13, 2023
@MrAlias MrAlias added this to the Metric v0.35.0 milestone Jan 13, 2023
@MrAlias
Copy link
Contributor Author

MrAlias commented Jan 13, 2023

PoC #3586

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics
Projects
No open projects
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant