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

Add asserts for event body fields #6509

Merged
merged 7 commits into from
Sep 5, 2024

Conversation

breedx-splk
Copy link
Contributor

I couldn't find a great way (without casting to AnyValueBody) for users to do assertions around LogRecordData bodies, specifically for writing tests involving Events. This seemed like a pretty low-impact way to add some testability.

@breedx-splk breedx-splk requested a review from a team June 7, 2024 19:24
@breedx-splk breedx-splk force-pushed the event_body_asserts branch from fb74949 to 4fd6513 Compare June 7, 2024 21:31
Copy link

codecov bot commented Jun 7, 2024

Codecov Report

Attention: Patch coverage is 95.65217% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.01%. Comparing base (ee7fd27) to head (16bd9d2).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...metry/sdk/testing/assertj/LogRecordDataAssert.java 95.65% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6509      +/-   ##
============================================
+ Coverage     89.98%   90.01%   +0.03%     
- Complexity     6314     6353      +39     
============================================
  Files           703      703              
  Lines         19062    19138      +76     
  Branches       1875     1887      +12     
============================================
+ Hits          17152    17228      +76     
  Misses         1333     1333              
  Partials        577      577              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@breedx-splk
Copy link
Contributor Author

I hid the formerly public method that used AnyValue. Ready for another look.

private void bodyIsAnyValue() {
// Actually, we can't do these two checks because the body is still STRING type
// assertThat(actual.getBody().getType()).isNotSameAs(Body.Type.EMPTY);
// assertThat(actual.getBody().getType()).isNotSameAs(Body.Type.STRING);
Copy link
Member

Choose a reason for hiding this comment

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

I think we can make this assertion now.. See how LogMarshaler checks if body instanceof AnyValueBody.

I might be misunderstanding though. Definitely need to be careful to not expose AnyValue as part of the public API until its stable.

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're slightly mixing up two things here....but the point was this assert will ALWAYS fail right now, because the body is always still STRING type.

Copy link
Member

Choose a reason for hiding this comment

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

I think its time we stabilized the AnyValue portions of the log API. Opened #6581 to track.

Its strange to have stable APIs asserting the contents of a log record body which are impossible to produce with using an experimental API. As a part of stabilizing we should fix the Body.Type enum, either by including all the possible value types of AnyValue OR by extending it with a single AnyValue type.

Copy link
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

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

Just a few nits, but should be able to get it in for Friday's release.

@jack-berg jack-berg merged commit e063b34 into open-telemetry:main Sep 5, 2024
17 of 18 checks passed
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.

3 participants