Skip to content

Add support to finish instrument recording#7792

Draft
atoulme wants to merge 7 commits intoopen-telemetry:mainfrom
atoulme:remove_support
Draft

Add support to finish instrument recording#7792
atoulme wants to merge 7 commits intoopen-telemetry:mainfrom
atoulme:remove_support

Conversation

@atoulme
Copy link
Copy Markdown

@atoulme atoulme commented Oct 25, 2025

This is a POC implementation to support open-telemetry/opentelemetry-specification#2232

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 28, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.26%. Comparing base (2421d67) to head (2a82801).
⚠️ Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
...nternal/state/DefaultSynchronousMetricStorage.java 80.00% 1 Missing and 1 partial ⚠️
...va/io/opentelemetry/api/metrics/DoubleCounter.java 66.66% 1 Missing ⚠️
...java/io/opentelemetry/api/metrics/DoubleGauge.java 66.66% 1 Missing ⚠️
.../io/opentelemetry/api/metrics/DoubleHistogram.java 66.66% 1 Missing ⚠️
...opentelemetry/api/metrics/DoubleUpDownCounter.java 66.66% 1 Missing ⚠️
...java/io/opentelemetry/api/metrics/LongCounter.java 66.66% 1 Missing ⚠️
...n/java/io/opentelemetry/api/metrics/LongGauge.java 66.66% 1 Missing ⚠️
...va/io/opentelemetry/api/metrics/LongHistogram.java 66.66% 1 Missing ⚠️
...o/opentelemetry/api/metrics/LongUpDownCounter.java 66.66% 1 Missing ⚠️
...metrics/internal/state/WriteableMetricStorage.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7792      +/-   ##
============================================
- Coverage     90.29%   90.26%   -0.03%     
- Complexity     7652     7668      +16     
============================================
  Files           843      852       +9     
  Lines         23066    23121      +55     
  Branches       2310     2313       +3     
============================================
+ Hits          20827    20871      +44     
- Misses         1520     1530      +10     
- Partials        719      720       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@atoulme atoulme changed the title Add support to remove instruments Add support to finish instrument recording Mar 16, 2026
Copy link
Copy Markdown
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

Just as the spec was blocked on resolving the series start time tracking issue, we'll want this to incorporate the java implementation of series start time tracking (#8180).

With those changes and with the more detailed mechanics about what calling finish actually means for implementations, this is likely to get a bit tricky from an implementation standpoint.

I'm happy to collaborate with you on this if you don't mind me pushing commits to your branch (or alternatively I can create my own branch based off yours).

}
AggregatorHolder<T> holderForRecord = getHolderForRecord();
try {
holderForRecord.aggregatorHandles.remove(attributes);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As @dashpole points out, this is too naive as it removes series without a final report of their data.

* @param context The explicit context to associate with this measurement.
* @since 1.56.0
*/
default void finish(Attributes attributes, Context context) {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since there is no SDK functionality that depends on context, we don't need it as an argument.

* Finish the instrument record.
*
* @param attributes A set of attributes to identify the instrument.
* @since 1.56.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#nit: we manaully add since annotations as part of the release process. This ensures that they accurately reflect the version changes were first published in. So just omit the annotation here.

* @param attributes A set of attributes to identify the instrument.
* @since 1.56.0
*/
default void finish(Attributes attributes) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This really needs to be Predicate<Attributes> to be useful. As @dashpole points out, with this API, you effectively have to independently track the attributes you may want to later remove, which significantly reduces the usefulness.

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.

2 participants