I would like to request the ability to attach datetime to the log method in ddlogs.
Feature description
- Use case
DatadogLogger.log(
LogLevel level,
String message, {
String? errorMessage,
String? errorKind,
StackTrace? errorStackTrace,
Map<String, Object?> attributes = const {},
})
- Currently deliversIn iOS and Android libraries, you can directly set the date information of the log explorer by attaching a Date object with the "date" key to the attribute, but this is not possible in the flutter library.
void handleLog(LogRecord record) {
if (record.level.value >= level.level.value) {
logger.log(
record.level.ddLevel, record.message,
errorKind: record.error?.runtimeType.toString(),
errorMessage:
record.error != null ? Error.safeToString(record.error) : null,
errorStackTrace: record.stackTrace,
attributes: {
"date": record.time,
});
}
}
this code returns next error
[Datadog 🐶⚠️ ] ArgumentError when calling logs._internalLog: parameter null. It looks like date is of type DateTime, which is not supported.
and with i tried various string formatting with datetime but it does not affect to log explorer.
- I want set datetime of log explorer.
Proposed solution
Modify the internalLog method of the DatadogLogsPlugin.kt file to perform Date parse for strings with the "date" key in the context.
or
accept date string on back end.
Other relevant information
No response
Hi @rouddy,
There are multiple issues that this is surfacing, some we'll look into and others we probably won't fix.
First up, the inability to send dates is a limitation in Flutter's PlatformChannel, which is what we use to send data down to the iOS and Android SDKs. The supported types are listed in Flutter's documentation. We likely won't support sending DateTime, but changing it to a String should work.
Second, iOS and Android do something slightly different here. The attribute date is not listed as reserved, but it actually is. iOS incorrectly replaces the date on the Log, but Android discards it as a reserved attribute, so the example you gave doesn't actually work in the Android SDK as is.
But, the backend does support parsing dates.
To get what you want, change the name of the attribute, something like timestamp or recordDate. You can then modify your log pipeline to set that attribute as the official log date using a date remapper. This also contains documentation on what date formats are supported. Note, the default Flutter Logs pipeline already has a Date Remapper set, so you will need to create a new pipeline to add the Date Remapper.
One last thing to be aware of is that the SDKs do some additional work to account for clock drift on the device. By supplying a custom timestamp in this way, you will lose out on this adjustment.
Hi @rouddy,
Did this help you? Do you need any more assistance or can I close this issue?
Closing from lack of response.