OpenTelemetry issues; timestamp drift, and LOGGING_SAMPLED_KEY is not treated as boolean #802
Labels
api: logging
Issues related to the googleapis/nodejs-logging-winston API.
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Environment details
@google-cloud/logging-winston
version: 5.3.0Steps to reproduce
This has a big impact when using OpenTelemetry since the link to "View Logs" relies on the log entries having a timestamp that lies within the timespan of a span during a trace. There is often a drift of a few 100ms in Cloud Logging vs the timespans in Cloud Trace.
By investigating the code I found that
info.timestamp
is intended to be aDate
instance inLoggingCommon#log
. So to remedy I had to do this:The code that expects
timestamp
to be a Date is withinLoggingCommon
:An additional issue is that the key
LoggingWinston.LOGGING_SAMPLED_KEY
should be expected to be a boolean, but theLoggingCommon
class expects it to be a string like"1"
. In OpenTelemetry this is stored in the traceFlags of the span context as a number, not a string. And typically we can convert to boolean viaspan.spanContext().traceFlags === OpenTelemetry.TraceFlags.SAMPLED
. It's really odd to have this documented as needing to be a boolean but in the code it expects a string.As a remedy I had to set this key to
String(span.spanContext().traceFlags)
.The text was updated successfully, but these errors were encountered: