Skip to content

Conversation

@trentm
Copy link
Contributor

@trentm trentm commented Oct 6, 2025

Collection of some host-metrics metrics can be costly. Using a Metrics View can be used
to drop metrics, but there will still be the cost of having collected them in the
first place. This adds a config option to select which groups of metrics should
be collected.

Checklist

  • tests

trentm added 2 commits October 6, 2025 14:02
… which metrics are collected

Collection of some host-metrics metrics can be costly. Using a Metrics View can be used
to drop metrics, but there will still be the cost of having collected them in the
first place. This adds a config option to select which groups of metrics should
be collected.
@trentm trentm changed the title feat(host-metrics): add 'metricsGroups' configuration option to limit which metrics are collected feat(host-metrics): add 'metricGroups' configuration option to limit which metrics are collected Oct 6, 2025
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me!

@trentm trentm marked this pull request as ready for review October 15, 2025 23:08
@trentm trentm requested a review from a team as a code owner October 15, 2025 23:08
@trentm trentm requested a review from legendecas October 16, 2025 00:18
@trentm
Copy link
Contributor Author

trentm commented Oct 21, 2025

@legendecas Are you able to review this again, now that I've added some tests? Thanks.

@pichlermarc
Copy link
Member

Non-blocking: I wonder if the intention of the spec was to actually NOT to invoke async observable callbacks in the first place if a Drop aggregation is specified for a given instrument (via View or MetricReader).

Considering that the main use-case for Observable instruments is to allow expensive operations to only run when the MetricReader triggers a collect operation, it would make sense to just not invoke the callback to begin with if a Drop aggregation is configured. AFAIK we don't do it like that in the metrics SDK right now, but technically not observing it at all wouldn't make a difference and would solve this for every observable instrument that suffers from the same issues.

@pichlermarc
Copy link
Member

anyway - non-blocking: making such a change is likely a huge undertaking. I just checked our implementation and it would be really difficult to make that change happen the way things are implemented today.

@legendecas
Copy link
Member

@pichlermarc there might be multiple views configured on a single metric instrument like an observable.

I think it could be considered as an optimization rather than a requirement that if there is only one metric view of drop aggregation configured for an observable, the callback of the observerble could be skipped.

However, on https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#observations-inside-asynchronous-callbacks:

Callback functions MUST be invoked for the specific MetricReader performing collection.

@pichlermarc
Copy link
Member

@pichlermarc there might be multiple views configured on a single metric instrument like an observable.

I think it could be considered as an optimization rather than a requirement that if there is only one metric view of drop aggregation configured for an observable, the callback of the observerble could be skipped.

Yep, agree.

However, on https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#observations-inside-asynchronous-callbacks:

Callback functions MUST be invoked for the specific MetricReader performing collection.

Mhm, looking at the whole paragraph:

Callback functions MUST be invoked for the specific MetricReader
performing collection, such that observations made or produced by
executing callbacks only apply to the intended MetricReader during
collection.

It seems like it mostly concerns itself with observations not cross-polluting other MetricReaders collection cycle. I'm not sure I could make a good argument why applying the optimization would be spec-compliant.

Digging for precedent in Java, there's this:

Unfortunately there was no discussion on that specific behavior in the PR that added it.

Since our implementation is similar, I now wonder if there's a chance that we could do something similar

Views would then be able to prevent callbacks from being invoked - we'd have to change the BatchObservable to a per-instrument Observable here though.

@legendecas
Copy link
Member

I think a dedicated issue is worthwhile for this in the core repo. Would you like to open an issue in the core repo?

@pichlermarc
Copy link
Member

I think a dedicated issue is worthwhile for this in the core repo. Would you like to open an issue in the core repo?

done open-telemetry/opentelemetry-js#6039

@trentm trentm enabled auto-merge (squash) October 28, 2025 22:41
@trentm trentm merged commit 6fbbd6c into open-telemetry:main Oct 28, 2025
21 checks passed
@trentm trentm deleted the trentm-host-metrics-config branch October 28, 2025 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants