Zimmergren/LogAnalytics.Client

DateTime values saved without miliseconds

jmazurpl opened this issue ยท 8 comments

When I save DateTime values to Log Analitics its being saved without miliseconds.

image

Hey @jmazurpl,

I noticed a similar behavior recently.

The headers for the Data Collector API require the RFC 7234 format, which is what we're using right now.

See this: https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api#request-headers

I will try to reach out to someone at MSFT about this, and see if we can learn about other formats that are accepted (and supported).

Hi @Zimmergren

I don't think thats the case. You generate the header values fine. Problem is with DateTime values saved inside the log entry. I took the code example from: https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api and it saves the miliseconds. Maybe the problem is with Json serialization. I didn't have time to check it but its next on my list.

@jmazurpl, I just ran through a set of E2E tests, and they all are delivered with milliseconds on my end.

image

The ones where the milliseconds are the same, I suspect are the batch inserts. However, none of my tests have a .000 timestamp. The actual TimeGenerated here does indeed have the correct stamp.

I noticed you have two other fields in your screenshot, though. You're not referring to the TimeGenerated.
Is the startTime_t and endTime_t custom fields in your entity that you're sending?

Yes exactly this is what I was trying to say :). I checked the sample code from https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api and this code saves miliseconds in my case. I'm still looking for differences in the implementation.

What I'm doing is more or less:

var logEntry = new {
   StartDate = DateTime.UtcNow
};

_ = _logAnalytics.SendLogEntry(logEntry, "MyLoggedRequests");

@Zimmergren
Finally the problem was at my side. I had in my project global configuration for Newtonsoft Json that was serializing DateTime without miliseconds. Issue can be closed. Thank you for the support.

Thank you for confirming.

Thanks for helping out @Zimmergren. So looks like nothing to change in our docs?

Correct @rboucher - all clear ๐Ÿ‘๐Ÿ™‚