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
GoogleStackdriverTarget for NLog - Added SendJsonPayload property #2256
Conversation
@chrisdunelm Thought that NLog should also support your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR :)
Mostly looks good, just a few minor comments; and one question.
}, includeEventProperties: true); | ||
Assert.Single(uploadedEntries); | ||
var entry0 = uploadedEntries[0]; | ||
Assert.Equal(string.Empty, entry0.TextPayload?.Trim() ?? string.Empty); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
InternalLogger.Warn(ex, "GoogleStackdriver(Name={0}): Exception at BuildLogEntry with Key={1}", Name, combinedProperty.Key); | ||
logEntry.Labels[combinedProperty.Key] = "null"; | ||
if (string.IsNullOrEmpty(combinedProperty.Key)) | ||
continue; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
logEntry.Labels[combinedProperty.Key] = combinedProperty.Value?.ToString() ?? "null"; | ||
if (string.IsNullOrEmpty(combinedProperty.Key)) | ||
continue; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
catch (Exception ex) | ||
|
||
logEntry.JsonPayload = jsonStruct; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -33,6 +33,7 @@ When using default options, logs will appear under these filter settings in the | |||
* **IncludeCallSiteStackTrace** - Include LogEntrySourceLocation extracted from NLog callsite (Also include filename and linenumber) | |||
* **IncludeEventProperties** - Includes structured logging properties from NLog LogEventInfo.Properties | |||
* **IncludeMdlc** - Include async thread context properties from NLog MappedDiagnosticsLogicalContext | |||
* **SendJsonPayload** - Instead of sending properties as custom labels, then they are sent as Json-Properties |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Any ETA on this? Exactly what I was waiting for. |
@manxjason Do you have any preference on having the Labels filled when using JsonPayload ? |
@snakefoot No preference at this point - perhaps in the future but use of Stackdriver is new to us |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the extra collection support :)
Just a few changes requested...
} | ||
|
||
[Fact] | ||
public async Task SingleLogEntryWithJsonCollectionProperties() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
return Value.ForStruct(dictionaryStruct); | ||
} | ||
else if (objectValue is System.Collections.ICollection collection) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
if (objectValue is System.Collections.IDictionary dictionary) | ||
{ | ||
var dictionaryStruct = new Struct(); | ||
var itemEnumerator = dictionary.GetEnumerator(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
var itemTypeCode = Convert.GetTypeCode(itemEnumerator.Value); | ||
dictionaryStruct.Fields.Add(dictionaryKey, BuildSimpleJsonValue(itemTypeCode, itemEnumerator.Value)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@snakefoot From your point of view is this now ready for merging and release? |
@chrisdunelm Yes it looks good to me. |
Great. I'll wait for all CI to go green, then merge. I expect we'll do another beta release of this next week. Thanks very much :) |
Nuget package is now available: https://www.nuget.org/packages/Google.Cloud.Logging.NLog/2.0.0-beta02 |
@snakefoot this is more an Issue but as this PR is fresh and you made it, perhaps you don't mind discussing the following?
Hmm i'm starting to think I should have said 'Yes'. Right now we're finding that the labels are being filled, but not with the actual values, but with the type instead for some reason.
Results in looking like this: https://imgur.com/Olav4qc. Note the message format and the Property's value is the name of the type. Our setup looks like:
And our layout:
|
@manxjason Not sure I understand why you are using the JsonLayout (It doesn't help when using SendJsonPayload). I would instead put the values you have added with each of the JsonAttributes into the I first implemented the NLog-GoogleStackdriverTarget to have the same features as for log4net. And then I added the support for JsonPayload so it would have the same features as for Serilog. I don't have much experience with the Google Logging Framework to know what works best for you. Are you missing an |
@manxjason Discovered your use of POCO-objects, so created #2300 to support this. |
Allows you to do this: