Skip to content

[Geneva] Log error when buffer too small#4027

Open
martincostello wants to merge 2 commits intoopen-telemetry:mainfrom
martincostello:gh-1152
Open

[Geneva] Log error when buffer too small#4027
martincostello wants to merge 2 commits intoopen-telemetry:mainfrom
martincostello:gh-1152

Conversation

@martincostello
Copy link
Copy Markdown
Member

Fixes #1152

Changes

Log an error if a metric is too large for the buffer.

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)

Log an error if a metric is too large for the buffer.

Fixes open-telemetry#1152.
@github-actions github-actions bot added the comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva label Mar 27, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.97%. Comparing base (da86069) to head (431aba4).
⚠️ Report is 26 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4027      +/-   ##
==========================================
+ Coverage   71.94%   71.97%   +0.02%     
==========================================
  Files         458      448      -10     
  Lines       17872    17828      -44     
==========================================
- Hits        12858    12831      -27     
+ Misses       5014     4997      -17     
Flag Coverage Δ
unittests-Exporter.Geneva 54.76% <100.00%> (-0.36%) ⬇️
unittests-Instrumentation.Cassandra ?

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

Files with missing lines Coverage Δ
...ry.Exporter.Geneva/Internal/ExporterEventSource.cs 29.54% <100.00%> (-1.41%) ⬇️
...metry.Exporter.Geneva/Metrics/TlvMetricExporter.cs 81.79% <100.00%> (-6.09%) ⬇️

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@martincostello martincostello marked this pull request as ready for review March 27, 2026 16:15
@martincostello martincostello requested a review from a team as a code owner March 27, 2026 16:15
Copilot AI review requested due to automatic review settings March 27, 2026 16:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a dedicated error log path for Geneva metric TLV serialization buffer overflows, addressing #1152 by producing a clearer diagnostic event when a metric cannot fit into the fixed-size buffer.

Changes:

  • Catch buffer-exhaustion exceptions during TLV metric export and emit a dedicated EventSource error event.
  • Add a new ExporterEventSource event (ID 11) for “metric serialization buffer exceeded”.
  • Add a unit test validating the new buffer-overflow log behavior and update Geneva exporter changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs Adds a new test that forces a serialization buffer overflow and asserts the dedicated error event is emitted.
src/OpenTelemetry.Exporter.Geneva/Metrics/TlvMetricExporter.cs Adds targeted exception handling to detect buffer overflow and log the new event.
src/OpenTelemetry.Exporter.Geneva/Internal/ExporterEventSource.cs Introduces a new EventSource event (ID 11) with a clearer buffer-overflow message.
src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md Documents the new error logging behavior in Unreleased notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +247 to +259
catch (Exception ex) when (ex is IndexOutOfRangeException || ex is ArgumentException)
{
// The fixed-size serialization buffer's bounds were exceeded.
// Note: SerializeByte/SerializeUInt16/etc. throw IndexOutOfRangeException when
// the buffer index exceeds the array length; Encoding.UTF8.GetBytes throws
// ArgumentException on .NET 5+ when the destination span is too small.
if (ExporterEventSource.Log.IsEnabled(EventLevel.Error, EventKeywords.All))
{
ExporterEventSource.Log.MetricSerializationBufferFull(metric.Name, GenevaMetricExporter.BufferSize);
}

result = ExportResult.Failure;
}
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The exception filter catches all ArgumentException-derived exceptions, which includes ArgumentOutOfRangeException thrown by Socket.Send (and potentially other argument validation failures). That can misclassify transport/logic bugs as a "serialization buffer exceeded" condition and drops the original exception details. Consider narrowing this catch to only the specific encoding destination-too-small case (e.g., exclude ArgumentOutOfRangeException) or refactor serialization to throw a dedicated/consistent exception for buffer exhaustion and catch only that.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm open to changing this, but it needs a bunch of refactoring to make the call sites that get detected for this more specific.

Comment on lines +1419 to +1424
var capturedEvents = new List<EventWrittenEventArgs>();
var path = string.Empty;
Socket server = null;

using var listener = new BufferOverflowEventListener(capturedEvents);
try
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

EventListener callbacks can be raised on background threads while the test thread is asserting. Using a shared List here (and adding to it in OnEventWritten) is not thread-safe and can lead to intermittent failures (e.g., collection modified during enumeration). Use a thread-safe collection (ConcurrentQueue/ConcurrentBag) or protect accesses with a lock, and consider waiting until the expected event arrives before asserting.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 4, 2026
@martincostello martincostello added keep-open Prevents issues and pull requests being closed as stale and removed Stale labels Apr 4, 2026
@Kielek Kielek requested a review from rajkumar-rangaraj April 7, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:exporter.geneva Things related to OpenTelemetry.Exporter.Geneva keep-open Prevents issues and pull requests being closed as stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenevaExporter should log a helpful message when it runs out of buffer capacity to serialize data

2 participants