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

Add metrics implementation #750

Merged
merged 47 commits into from
Aug 10, 2022

Conversation

Nevay
Copy link
Contributor

@Nevay Nevay commented Jul 5, 2022

Replaces the current implementation as it does not conform to the (current version of) the spec.

See examples/metrics/basic.php on how to use/create a meter provider.


(Incomplete) todo list:

  • more tests
  • resolve phan issues
  • remove _bridge.php
  • add error handling (view conflicts, non-monotonic value provided to counter, ...) (may be done in follow-up PR)
  • add exponential bucket histogram aggregation (may be done in follow-up PR)

@codecov
Copy link

codecov bot commented Jul 5, 2022

Codecov Report

Merging #750 (62765bc) into main (ae6b620) will increase coverage by 1.13%.
The diff coverage is 83.54%.

❗ Current head 62765bc differs from pull request most recent head feae135. Consider uploading reports for the commit feae135 to get more accurate results

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #750      +/-   ##
============================================
+ Coverage     78.43%   79.56%   +1.13%     
- Complexity     1331     1679     +348     
============================================
  Files           153      213      +60     
  Lines          3278     4296    +1018     
============================================
+ Hits           2571     3418     +847     
- Misses          707      878     +171     
Flag Coverage Δ
7.4 79.55% <83.51%> (+1.12%) ⬆️
8.0 79.59% <83.46%> (+1.09%) ⬆️
8.1 79.59% <83.46%> (+1.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...PI/Common/Instrumentation/InstrumentationTrait.php 100.00% <ø> (ø)
src/API/Metrics/Noop/NoopMeter.php 0.00% <0.00%> (ø)
src/API/Metrics/Noop/NoopMeterProvider.php 0.00% <0.00%> (ø)
src/API/Metrics/Noop/NoopObservableCounter.php 0.00% <0.00%> (ø)
src/API/Metrics/Noop/NoopObservableGauge.php 0.00% <0.00%> (ø)
...c/API/Metrics/Noop/NoopObservableUpDownCounter.php 0.00% <0.00%> (ø)
src/Contrib/Otlp/AttributesConverter.php 0.00% <0.00%> (ø)
src/Contrib/OtlpHttp/MetricExporter.php 0.00% <0.00%> (ø)
src/SDK/Metrics/Data/Exemplar.php 0.00% <0.00%> (ø)
src/SDK/Metrics/Data/Gauge.php 0.00% <0.00%> (ø)
... and 66 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae6b620...feae135. Read the comment docs.

Copy link
Collaborator

@brettmc brettmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review done, this looks great. I need to go over the spec in more detail, but so far this seems to be following the spec very closely.
To be discussed: naming of interfaces :)

src/API/Metrics/Counter.php Outdated Show resolved Hide resolved
src/Contrib/Otlp/MetricConverter.php Outdated Show resolved Hide resolved
src/SDK/Metrics/Aggregation/Sum.php Outdated Show resolved Hide resolved
src/SDK/Metrics/Aggregation/Sum.php Outdated Show resolved Hide resolved
src/SDK/Metrics/SdkCounter.php Outdated Show resolved Hide resolved
src/SDK/Metrics/Stream/Delta.php Outdated Show resolved Hide resolved
src/SDK/Metrics/Stream/DeltaStorage.php Show resolved Hide resolved
src/SDK/Metrics/MeterProvider.php Outdated Show resolved Hide resolved
src/SDK/Metrics/MeterProvider.php Outdated Show resolved Hide resolved
@Nevay Nevay marked this pull request as ready for review July 11, 2022 14:02

namespace OpenTelemetry\SDK\Metrics;

interface DefaultAggregationProvider
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interface DefaultAggregationProvider
interface DefaultAggregationProviderInterface

@brettmc
Copy link
Collaborator

brettmc commented Jul 13, 2022

I think I've reviewed this as well as I can. I'm happy to approve, and then it can get some real-world testing. Perhaps a first step might be to create an example that exports to the otel collector (when we do have a metrics exporter, I'm not sure that we do yet)

if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 500 && $response->getStatusCode() !== 408) {
return false;
}
} catch (RequestExceptionInterface $e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot to log an error or warning, as we get close to beta

Nevay added 13 commits July 16, 2022 11:21
Was mainly a side-effect of using `spl_object_id()`; lead to inconsistent behavior between providing same and identical callbacks; reverting back to incrementing index, keyspace is large enough.
- move default aggregation handling to metric reader / metric exporter
- move view registration to meter provider constructor
- move exemplar reservoir creation to aggregation to support user implementations
- remove `AttributeProcessor` from view as baggage access was dropped from spec
- deduplicate metric streams
- add missing `Interface` suffix
- move callback destructors to metric observer to not detach if meter and meter provider are out of scope
- simplify `::viewRegistrationRequests()` by readding fallback view
- rename `MetricObserver::weakMap()` to `::destructors()` to better reflect usage`
- move `ReferenceCounter::acquire()` call to corresponding `MetricObserver::observe()` call for consistency
- cache instrumentation scope id in `Meter` to avoid repeated calls to `serialize()`
- remove obsolete instrument type check from `ViewProjection`, leftover from supporting aggregation per type
@bobstrecansky bobstrecansky merged commit 3ac64f6 into open-telemetry:main Aug 10, 2022
This was referenced Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants