Skip to content

Add low memory temporality for metrics - #6648

Merged
rajkumar-rangaraj merged 8 commits into
open-telemetry:mainfrom
hannahhaering:add-low-memory-aggregation-temporality
Nov 19, 2025
Merged

Add low memory temporality for metrics#6648
rajkumar-rangaraj merged 8 commits into
open-telemetry:mainfrom
hannahhaering:add-low-memory-aggregation-temporality

Conversation

@hannahhaering

@hannahhaering hannahhaering commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

Implements #4109

Changes

Added low memory temporality as an option in the OTLP metrics exporter, following the specification

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions Bot added pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package labels Oct 27, 2025
@codecov

codecov Bot commented Oct 27, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.82%. Comparing base (e3b1769) to head (fa4fca1).
⚠️ Report is 5 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/OpenTelemetry/Metrics/Reader/MetricReader.cs 93.33% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6648      +/-   ##
==========================================
+ Coverage   86.74%   86.82%   +0.07%     
==========================================
  Files         258      258              
  Lines       11958    11973      +15     
==========================================
+ Hits        10373    10395      +22     
+ Misses       1585     1578       -7     
Flag Coverage Δ
unittests-Project-Experimental 86.65% <93.33%> (-0.07%) ⬇️
unittests-Project-Stable 86.80% <93.33%> (+0.10%) ⬆️

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

Files with missing lines Coverage Δ
src/OpenTelemetry/Metrics/Reader/MetricReader.cs 89.39% <93.33%> (+1.35%) ⬆️

... and 3 files with indirect coverage changes

Comment on lines +40 to +53
private static readonly Func<Type, AggregationTemporality> LowMemoryTemporalityPreferenceFunc = (instrumentType) =>
{
return instrumentType.GetGenericTypeDefinition() switch
{
var type when type == typeof(Counter<>) => AggregationTemporality.Delta,
var type when type == typeof(Histogram<>) => AggregationTemporality.Delta,

var type when type == typeof(UpDownCounter<>) => AggregationTemporality.Cumulative,
var type when type == typeof(ObservableCounter<>) => AggregationTemporality.Cumulative,
var type when type == typeof(ObservableUpDownCounter<>) => AggregationTemporality.Cumulative,

_ => AggregationTemporality.Cumulative,
};
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if using TypeHandle property would be more performant here.

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.

Unless there's a huge benefit, I think it's better to make the code obvious by using ==. It's also not obvious from the source code what that property does differently as it just throws an exception.

@hannahhaering
hannahhaering marked this pull request as ready for review October 29, 2025 01:57
@hannahhaering
hannahhaering requested a review from a team as a code owner October 29, 2025 01:57
Comment thread test/OpenTelemetry.Tests/Metrics/MetricReaderTests.cs
/// ObservableUpDownCounter instruments. This mode reduces SDK memory usage by avoiding
/// the need to store both cumulative and delta states for temporality conversion.
/// </summary>
LowMemory = 3,

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.

Technically, all these 3 options are defined only for OTLP exporter https://github.com/open-telemetry/opentelemetry-specification/blob/7f6d35f758bb5d92e354460d040974665a29ba32/specification/metrics/sdk_exporters/otlp.md?plain=1#L55 and it shouldn't be part of the SDK.

Based on current design, I do not see any better option to put in the current class design.
@alanwest, do you remember any historical reasons for keeping it here?

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.

Given the existence of delta/cumulative already in SDK, I think it is okay to add LowMemory enum setting in the SDK itself.
If we are adding ENV variable support, then it should only be in the OTLP package.

@open-telemetry open-telemetry locked and limited conversation to collaborators Nov 6, 2025
@open-telemetry open-telemetry unlocked this conversation Nov 6, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions Bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Nov 14, 2025
@Kielek Kielek removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Nov 14, 2025

@Kielek Kielek left a comment

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.

LGTM, especially considering @cijothomas comment

@rajkumar-rangaraj rajkumar-rangaraj left a comment

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.

LGTM

@rajkumar-rangaraj
rajkumar-rangaraj added this pull request to the merge queue Nov 19, 2025
Merged via the queue into open-telemetry:main with commit 3a96380 Nov 19, 2025
62 of 63 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution @hannahhaering! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants