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

[shared] Add TagWriter implementation #5476

Merged
merged 6 commits into from
Apr 9, 2024

Conversation

CodeBlanch
Copy link
Member

Relates to #5455
Relates to #5475

Changes

  • Adds TagWriter implementation which will be used to replace TagTransformer. Nothing uses TagWriter as of this PR.

Details

I spun up #5475 to track issues I found while working on #5455. What I want to do is replace TagTransformer completely with TagWriter as a precursor to improving the performance of the OtlpExporter (#5450). What TagWriter primarily achieves is the ability to write directly onto something instead of returning something which must then be written.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)

@rajkumar-rangaraj
Copy link
Contributor

I took a glance at this PR. The overall structure is good. However, it is very difficult to review it in this format. Could you please add some examples of consumption in the PR description or tests?

@CodeBlanch
Copy link
Member Author

@rajkumar-rangaraj Here are a few implementations of TagWriter you can check out from my PoC...

https://github.com/CodeBlanch/opentelemetry-dotnet/blob/poc/tagwriter/src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinTagWriter.cs

https://github.com/CodeBlanch/opentelemetry-dotnet/blob/poc/tagwriter/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/OtlpTagWriter.cs

https://github.com/CodeBlanch/opentelemetry-dotnet/blob/poc/tagwriter/src/OpenTelemetry.Exporter.Console/Implementation/ConsoleTagWriter.cs

Zipkin case is the best. It writes directly onto the stream. That is ideally what we would do in OtlpExporter.

threadWriter = new Utf8JsonWriter(threadStream);
return new(threadStream, threadWriter);
}
else
Copy link
Contributor

Choose a reason for hiding this comment

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

When is this else clause executed, if the tags collection contains more than one array type? I'm trying to understand the scope of a thread and this struct allocation on the stack.

Copy link
Member Author

Choose a reason for hiding this comment

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

The first time something is serialized with a tag value containing an array we create the storage. We use [ThreadStatic] so it will happen per thread. For exporters using the batch export processor there is a dedicated thread so that will happen once. For exporters using simple or something like reentrant, each thread can potentially have the storage. The else clause happens for all the calls after the first one. For that case we reset the state of storage so that it can be reused.

case sbyte[] sbyteArray: this.WriteToArray(arrayState, sbyteArray); break;
case short[] shortArray: this.WriteToArray(arrayState, shortArray); break;
case ushort[] ushortArray: this.WriteToArray(arrayState, ushortArray); break;
#if NETFRAMEWORK
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of repeating #if NETFRAMEWORK we could get int[], unint[], long[] under one block.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

Copy link
Member

Choose a reason for hiding this comment

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

@CodeBlanch - Was this change reverted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Woops yes sorry about that I just put it back.

Copy link
Contributor

@rajkumar-rangaraj rajkumar-rangaraj left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

github-actions bot commented Apr 5, 2024

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 label Apr 5, 2024
Copy link

codecov bot commented Apr 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.51%. Comparing base (6250307) to head (b9a69c2).
Report is 174 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5476      +/-   ##
==========================================
+ Coverage   83.38%   85.51%   +2.12%     
==========================================
  Files         297      289       -8     
  Lines       12531    12583      +52     
==========================================
+ Hits        10449    10760     +311     
+ Misses       2082     1823     -259     
Flag Coverage Δ
unittests ?
unittests-Instrumentation-Experimental 24.10% <ø> (?)
unittests-Instrumentation-Stable 24.13% <ø> (?)
unittests-Solution-Experimental 85.49% <ø> (?)
unittests-Solution-Stable 85.49% <ø> (?)

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

see 63 files with indirect coverage changes

Copy link
Member

@vishweshbankwar vishweshbankwar left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot removed the Stale label Apr 9, 2024
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.

None yet

3 participants