[Experimental] Meter
API: make instrument builders generic, extend metrics API
#433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem
There are several issues this PR tries to address:
Counter[F, Double]
,UpDownCounter[F, Double]
,Histogram[F, Long]
,Gauge[F, Long]
Histogram
builder API (e.g.withExplicitBucketBoundaries(...)
is missing)Proposals
1) Make
Meter
API genericWhile it's not mentioned explicitly in the spec, according to the proto models, the measurement can be either
Long
orDouble
.Since the set of allowed types is finite and known, we can improve the ergonomics of the
Meter
API:And the
MeasurementValue
can be defined as:Before:
After:
2) Merge observable and sync builders
The implementation depends on the language. For example, C# offers a separate API to create
Counter
orObservableCounter
:On the other hand, Open Telemetry Java SDK offers separate methods within the instrument builder:
As an experiment, I followed the Java SDK approach.
Before:
After:
Benefits
1) The API is more similar to OpenTelemetry Java SDK
2) The API feels more intuitive (well, it's subjective)
OpenTelemetry Java SDK:
Otel4s:
Drawbacks
1) The instrument type must be provided explicitly
Calling an instrument builder without an explicit param type will lead to the 'ambiguous implicits' error.
The error itself can be frustrating for newcomers. However, it can be somewhat mitigated with the
@implicitAmbiguous
annotation.For example, the following error message will be raised when the type param is missing:
2) That's a lot of breaking changes
Even though we are still in the 'active development' zone, the changes may frustrate users. This issue can be partially mitigated by the scalafix migration rules (e.g. #426).
The questions
sync
andobservable
instruments? (e.g..counter(...)
vs.observableCounter(...)
)