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

LogPropertiesAttribute.Transitive + LogPropertiesAttribute.OmitReferenceName not working as expected. #10796

Open
noamshim opened this issue Dec 31, 2024 · 7 comments

Comments

@noamshim
Copy link

noamshim commented Dec 31, 2024

Type of issue

Code doesn't work

Description

Hi,
I'm using both LogPropertiesAttribute.Transitive = true and LogPropertiesAttribute.OmitReferenceName = true, but the log still contains the field name like _Metadata.RegionScope":"WW". I would expect the inner object to be printed like _Metadata: {RegionScope":"WW"}.

full example:

the log:

{"Timestamp":"2024-12-31T10:24:22.7589889Z","Message":"","LogLevel":"Information","@r":[""],"_Metadata.TimeGenerated":"2024-12-31T10:24:22.7035140Z","_Metadata.PartnerRing":"PartnerRingc255eda4-275a-473f-88a4-a65b3c380bd6","_Metadata.Zone":3,"_Metadata.RegionScope":"WW","FlowCorrelationId":"1dbb3e90-b14a-4b57-aa09-2263dcfce38a","PolicyAction":"54d3d054-6e64-4adb-81c6-5bf22a79882b","ServiceApp":"36722f0d-fdee-4c07-afc2-41b783b9fb36"}

in the logging extension:

        [LoggerMessage(
            Level = LogLevel.Information,
            EventId = EventConstants.GeneratingRoxyStreamOperationEventId,
            EventName = EventConstants.GeneratingRoxyStreamOperationEventName)]
        public static partial void LogRoxyStreamOperationEvent(
            this ILogger logger, [LogProperties(OmitReferenceName = true, Transitive = true)] in RoxyStreamOperationEvent roxyStreamOperationEvent);

Page URL

https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.logpropertiesattribute.omitreferencename?view=net-9.0-pp

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/Microsoft.Extensions.Logging/LogPropertiesAttribute.xml

Document Version Independent Id

f553155c-6c2c-7ba3-5c2c-b6741b79e46e

Article author

@dotnet-bot

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 31, 2024
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

1 similar comment
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 31, 2024
@eiriktsarpalis eiriktsarpalis added area-Extensions-Logging and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 7, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-logging

@tarekgh tarekgh added this to the Backlog milestone Jan 7, 2025
@tarekgh tarekgh removed the untriaged New issue has not been triaged by the area owner label Jan 7, 2025
@tarekgh
Copy link
Member

tarekgh commented Jan 7, 2025

CC @geeknoid @joperezr

@geeknoid
Copy link
Member

geeknoid commented Jan 7, 2025

OmitReferenceName is not transitive in nature. In general [LogProperties] stuff only applies to the current context. To strip out field names like _Metadata, you would need to put a [LogProperties] attribute definition on the _Metadata field and set OmitReferenceName=true there. I think that should give you the shape of log output you're looking for.

@tarekgh
Copy link
Member

tarekgh commented Jan 7, 2025

@geeknoid is there anything in the doc need to update to clarify that? This issue is about the doc improvement.

@geeknoid
Copy link
Member

geeknoid commented Jan 7, 2025

Oh, then sure, the docs could definitely be expanded to be more explicit about what's going on there. This blog post has some good details: https://andrewlock.net/behind-logproperties-and-the-new-telemetry-logging-source-generator/. The reference docs can use a bit more details, but ideally this would get captured in some examples and higher-level docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants