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

[otlp] Expand array buffer / add tests to existing base buffer #6013

Conversation

rajkumar-rangaraj
Copy link
Contributor

Fixes Part of #5730
Design discussion issue #

Changes

Please provide a brief description of the changes here.

  • Expanded the array buffer when a limit is reached.
  • Set the upper limit for the array buffer to 2 MB. If a single tag with an array value exceeds 2 MB, it will be dropped, and the value will be updated to "TRUNCATED." While dropping the entire array value tag would be simpler, it would make it harder for customers to identify the issue.
  • Added additional test for base buffer increase
  • Identified a bug where ArgumentException could be thrown when using these calls
    • Buffer.BlockCopy(value.Buffer, 0, state.Buffer, state.WritePosition, value.WritePosition);
    • var bytesWritten = Utf8Encoding.GetBytes(value, buffer.AsSpan().Slice(writePosition));
  • Identified another bug where the buffer needs to be passed by reference, as it is being doubled in a different method.

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)

@rajkumar-rangaraj rajkumar-rangaraj requested a review from a team as a code owner December 6, 2024 23:59
@github-actions github-actions bot added the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label Dec 6, 2024
Copy link

codecov bot commented Dec 7, 2024

Codecov Report

Attention: Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.

Project coverage is 86.45%. Comparing base (145e7ad) to head (0218bd2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...Implementation/Serializer/ProtobufOtlpTagWriter.cs 75.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6013      +/-   ##
==========================================
+ Coverage   86.29%   86.45%   +0.15%     
==========================================
  Files         257      257              
  Lines       11685    11699      +14     
==========================================
+ Hits        10084    10114      +30     
+ Misses       1601     1585      -16     
Flag Coverage Δ
unittests-Project-Experimental 86.29% <89.28%> (+0.13%) ⬆️
unittests-Project-Stable 86.38% <89.28%> (+0.22%) ⬆️
unittests-Solution 86.08% <89.28%> (-0.16%) ⬇️
unittests-UnstableCoreLibraries-Experimental 85.78% <ø> (ø)

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

Files with missing lines Coverage Δ
...tation/OpenTelemetryProtocolExporterEventSource.cs 84.00% <100.00%> (-3.68%) ⬇️
...ementation/Serializer/ProtobufOtlpLogSerializer.cs 98.47% <100.00%> (+3.05%) ⬆️
...ntation/Serializer/ProtobufOtlpMetricSerializer.cs 98.77% <100.00%> (+1.63%) ⬆️
...entation/Serializer/ProtobufOtlpTraceSerializer.cs 94.98% <100.00%> (+1.54%) ⬆️
...ol/Implementation/Serializer/ProtobufSerializer.cs 93.18% <100.00%> (+5.48%) ⬆️
....Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs 100.00% <100.00%> (ø)
...porter.OpenTelemetryProtocol/OtlpMetricExporter.cs 80.76% <100.00%> (ø)
...xporter.OpenTelemetryProtocol/OtlpTraceExporter.cs 89.28% <100.00%> (ø)
...Implementation/Serializer/ProtobufOtlpTagWriter.cs 95.45% <75.00%> (-4.55%) ⬇️

... and 4 files with indirect coverage changes

{
[ThreadStatic]
private static byte[]? threadBuffer;
internal static byte[]? ThreadBuffer;
private const int MaxBufferSize = 2 * 1024 * 1024;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CodeBlanch Should we change this to readonly? With the current implementation, even if customers want to use a reflection hack to increase the size, const makes it impossible.

Copy link
Member

Choose a reason for hiding this comment

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

🤷

We do have this: https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs

You could define some experimental options to control the two buffer sizes. Users will be able to bind them to IConfiguration/envvars if needed. Better mechanism than reflection if you want to make it configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could consider post RC release.

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

@CodeBlanch CodeBlanch changed the title [otlp] Expand array buffer / add tests to existing base buffer. [otlp] Expand array buffer / add tests to existing base buffer Dec 10, 2024
@CodeBlanch CodeBlanch merged commit be82099 into open-telemetry:main Dec 10, 2024
49 checks passed
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants