-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
log/logtest: Add log.Record
initializer
#5195
Comments
The functional options would introduce heap allocations. I do not support the proposal as we would then provide inefficient API that developers might use and then compliant that the API is not performant. More: https://github.com/open-telemetry/opentelemetry-go/blob/main/log/DESIGN.md#options-as-parameter-to-loggeremit. |
What if we add it to the |
That makes a lot of sense. I would also consider implementing it as a "builder" to not "spam" the package with options. So that the user could do something like: record := logtest.NewRecordBuilder().
SetBody(log.StringValue("message").
SetTimestamp(timestamp).
SetSeverity(severity).
AddAttributes(data).
Build() It might be possible that a builder would not make a heap allocation - however, I doubt it. |
log.Record
initializerlog.Record
initializer
Yes, definitely. I'll wait for your PR to be approved before I start doing something similar for the API record. |
Problem Statement
Right now, creating and filling data for a
log.Record
requires calling method independently, and cannot be chained.eg:
This is a bit tedious, especially in test environments, where we end up having to setup methods to build records such as this one in the logrus bridge PR:
Proposed Solution
Add a
NewRecord()
helper method with optional arguments to create a new record.The example above would become:
Alternative
I could change my
buildRecord
in logrus to use functional arguments, but that would have to be repeated across all bridges.The text was updated successfully, but these errors were encountered: