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

sdk/log: Add TestRecord #5200

Closed
wants to merge 7 commits into from
Closed

Conversation

pellared
Copy link
Member

@pellared pellared commented Apr 12, 2024

Towards #5192

While I do not think it is great I think it might be good enough for now as it can unblock exporter unit tests.

The benefit of this approach is that it is simple and someone who would want to alter record's scope or resource in a Processor (which is not allowed by the specification) would need to explicitly use a TestRecord and even the name should resonate that it should not be used in production code.

Maybe it would be better to have such functionality under sdk/log/logtest. I believe that @MrAlias also mentioned this idea during the SIG meeting. I think we could do this by copying record.go and record_test.go to logtest and adding SetResource and SetInstrumentationScope (and tests) in seperate files (e.g. testrecord.go and testrecord_test.go). It is possible to convert between types that have exactly same fields. See: https://go.dev/play/p/rMq8vtYDx5O. I can try making a PR like this on Tuesday.

Still, maybe this PR is "good-enough" for now for unblocking the testing of exporter. But we can decide that it is not GA-ready. This is why I decided why this PR is "towards" fixing the issue (so that we are not closing yet). And we can try a better solution in a separate PR.

@pellared
Copy link
Member Author

@XSAM, I noticed that stdoutlog does not serialize Resource. I added it as a TODO item in #5055.

Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.3%. Comparing base (1ff2e71) to head (5abb3d0).

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #5200   +/-   ##
=====================================
  Coverage   84.3%   84.3%           
=====================================
  Files        258     258           
  Lines      16974   16978    +4     
=====================================
+ Hits       14313   14317    +4     
  Misses      2362    2362           
  Partials     299     299           
Files Coverage Δ
sdk/log/record.go 100.0% <100.0%> (ø)

@pellared pellared marked this pull request as ready for review April 12, 2024 14:45
@pellared pellared added pkg:SDK Related to an SDK package area:logs Part of OpenTelemetry logs labels Apr 12, 2024
@pellared pellared self-assigned this Apr 12, 2024
Copy link
Member

@XSAM XSAM left a comment

Choose a reason for hiding this comment

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

👍

// TestRecord is a log record for testing.
// You can use it for unit testing [Processor] and [Exporter] implementations.
// Do not use TestRecord in production code.
type TestRecord struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

How do I get a Record from a TestRecord so I can use it for testing?

Copy link
Member Author

@pellared pellared Apr 13, 2024

Choose a reason for hiding this comment

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

.Record. it is used in stdoutlog test in this PR

// TestRecord is a log record for testing.
// You can use it for unit testing [Processor] and [Exporter] implementations.
// Do not use TestRecord in production code.
type TestRecord struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be polluting the API with testing types.

It also is trying to use a Test prefix here to prevent semantic API use. I would rather explore options that use the semantics of Go actually make the restriction by design.

Copy link
Member Author

Choose a reason for hiding this comment

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

I propose this as an intermediate solution as noted in the description.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather we work on an permanent and intentional solution instead of a stop gap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:logs Part of OpenTelemetry logs pkg:SDK Related to an SDK package
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants