-
Notifications
You must be signed in to change notification settings - Fork 763
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
fix: [LogProperties] avoid early ToString of Nullable Properties #5416
Conversation
65e8911
to
f84cf4f
Compare
This comment was marked as outdated.
This comment was marked as outdated.
@dariusclay - I've updated this PR to address:
Reviewing the CI failures, they are expected at the moment (and I will resolve once you've done an initial review pass to let me know if this PR is headed in the correct direction):
A few questions/reservations about what I have so far:
|
src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Logging/FakeLogRecord.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Logging/FakeLogger.cs
Outdated
Show resolved
Hide resolved
test/Generators/Microsoft.Gen.Logging/Generated/LogPropertiesTests.cs
Outdated
Show resolved
Hide resolved
Thanks for the review pass @RussKie. I plan to address/update in the next 24 hours. |
@RussKie - I've addressed a few of the comments and errors. However, I'm a bit stuck:
Full disclosure: I'm reaching the end of my allocated time to work on this issue so depending on how much further work is required, I may not be able to finish this PR off. However, I'm happy for your team to take it over when you have time, or — if it's easier — close the PR, and then y'all can create a fresh one when it comes time (either re-using bits here or taking a fresh pass). |
You're adding a new public API, which is not allowed without an API proposal/review/etc.
You need to run the tests locally and accept the new snapshot (via the diff/merge tool or by manually renaming files).
Noted. @dariusclay please prioritise this review. |
OH, I didn't realize the
No, these bits don't need to be public. And if they do, I'm not a fan of the API I've introduced. It was simply a "bolt-on" to repro/test. Not intended to ship to production. If you or @dariusclay think we need to ship to production, then I'd like to brainstorm a cleaner API. Even if they are changed to be internal-implementation only, the implementation would need to be cleaned up from what I have it at this iteration. |
Yes, this is a public package that helps simplifying telemetry-related testing --> https://github.com/dotnet/extensions/tree/main/src/Libraries/Microsoft.Extensions.Diagnostics.Testing.
So, if those changes aren't required - please revert those and only keep the necessary changes. |
@rwoll thank you for starting this PR! |
8ea14fc
to
f05c8ea
Compare
@dariusclay / @RussKie - I've backed out the changed to the public API and added some more tests. CI is now green. Let me know once you've reviewed. I won't get to it, but I also recommend (either as a prereq for this to merge) or as a followup:
Thanks! |
@RussKie everything looks good here to me. We can follow up after this merge to include additional tests. |
Thank you @rwoll. Thank you @dariusclay. Could you please raise a tracking issue for follow up on the outstanding work? |
Fixes #5411.
Prior to this PR, when using the
[LogProperties]
on an object with nullable-typed properties (e.g.DateTime?
), the nullable-typed properties were being forced tostring
before being added to thestate.TagArray
while their non-nullable type (DateTime
) remainedDateTime
-typed in theTagArray
. In our environment, this manifested as timestamp columns having different formats in logs!Looking at the issue from a code perspective, given the following user-written code:
In the autogenerated code,
myEvent.TimeStamp
field got added to theTagArray
as aDateTime
(same type as it was in the event), butmyEvent.TimeStampNullable
is added to theTagArray
as astring
:This PR:
The root of the issue appears to have been in the determination of
ImplementsISpanFormattable
.In the
ShouldStringify*
methods,p
forSystem.Nullable<DateTime>
was not passing thep.ImplementsISpanFormattable
check:This was b/c the computation of that property was not being computed on the type wrapped by
Nullable
.Suggested Followup
While the original bug manifested as string formatting discrepancies, a test asserting the string result of the log is insufficient to robustly test. Asserting the generated output is helpful (as we've also added here), but may easily be incorrectly re-baselined.
To help create a more robust test in the future, I recommend:
Type
of each value instate.TagArray
TypeSymbolExtensions.{ImplementsIConvertible,ImplementsIFormattable,ImplementsISpanFormattable
and the newly introduced helper,TypeSymbolExtensions.GetPossiblyNullWrappedType
.