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
Doesn't work as described in README: log.logSync(logName).write(log.entry(metadata, payload))
#1266
Comments
I also encountered the same issue. |
Thanks @chriscalo for opening this issue! It seems that there are multiple issues here, feel free to correct me if I am wrong:
Please let me know if my observations make sense and please comment if you have more questions. |
@losalex With With This is the output of {
"timestamp": "2022-07-20T08:23:26.143Z",
"logging.googleapis.com/labels": {
"deviceID": "device-1234567890123456"
},
"logging.googleapis.com/insertId": "..........trV63Y01O.1fQXCoha3S2w",
"message": {
"some": "thing"
},
"logName": "projects/{{projectId}}/logs/hyperloop-telemetry"
} This is how that log would look over at Cloud Logging console: {
insertId: 'SOME ID'
jsonPayload: {
logName: 'projects/{{projectId}}/logs/hyperloop-telemetry'
message: {
some: "thing"
}
resource: {}
timestamp: '2022-07-20T08:31:05.121Z'
}
labels: {
deviceID: 'device-1234567890123456'
execution_id: 'SOME ID'
instance_id: 'SOME ID'
}
logName: 'projects/{{projectId}}/logs/cloudfunctions.googleapis.com%2Fcloud-functions'
receiveTimestamp: '2022-07-20T08:31:05.265952769Z'
timestamp: '2022-07-20T08:31:05.121123Z'
trace: 'SOME TRACE'
} Here is an example of using const metadata = {
labels: {
deviceID: 'device-1234567890123456'
}
}
const message = {
some: 'thing'
}
const entry = entry(metadata, message)
log.write(entry)
Note that
EditOh, I've just realized that #1301 is not a part of the latest release (10.1.1), so maybe it does indeed alleviate the problem. |
Actually, my bad on that edit: the mentioned change (#1301) was released, so I've tried setting It's still not behaving the same way as async
As you can see from the above: |
Thanks @NeverwinterMoon for providing more context! Below are some points with respect of your observations:
|
Downgrading priority for now until we clarify this issue with product teams |
@chriscalo and @NeverwinterMoon , I was thinking to close this issue - the timestamp issue was fixed and as for |
I might be misunderstanding something, but I think the original problem still stands that the docs and the behavior don't align. This would suggest that we shouldn't close this issue unless (a) there's a flaw in my original interpretation, (b) the behavior is fixed to match the docs, or (c) the docs are updated to match the behavior.
|
Hi @chriscalo, when the logging agent pick up the logs from stdout written by LogSync, it is expected that the Logging agent then sends the structured logs to Cloud Logging as the
In your case, entry.metadata is actually still being extracted in LogEntry.resource into an extended fashion: Since by default the logging agent will rename LogName when sending to Cloud Logging API, we will still want to keep I understand this is causing confusions since the logging behavior is inconsistent with log async. I will update the document to explain the expected behavior. Thank you! |
I am nearly certain that the original issue as I stated it is incorrect behavior. We might be talking past each other. Where do we think the disconnect is coming from? What more can I provide to convince the team that this behavior (or the README) is wrong? Shouldn't the following be true for the
|
@chriscalo The default behaviour of the logging object returned by logSynch is non-sensical and doesn't work in practice afaik. The logging object must be instantiated with the i.e const log = logging.logSync('test', process.stdout, {useMessageField: false})
const messageEntry = log.entry({ name: 'jordan', lastname: 'belanger', message: 'test' })
log.info(messageEntry) this outputs:
which will be parsed correctly and let you attach metadata along with your log message under cloudrun, other managed environments and when using the logging agent manually. |
The behavior of
log.logSync(logName).write(log.entry(metadata, payload))
doesn't match what's described in the README.Environment details
@google-cloud/logging
version: 9.8.3I've created a reproduction at https://github.com/chriscalo/logsync-bug and copied the full details here:
Steps:
Expected:
Here are the first two calls to
log.write()
inindex.js
:The expected output is something like: (irrelevant details removed)
Actual:
The actual output looks like the following: (irrelevant details removed)
The full output can be seen in downloaded-logs-20220506-191603.json
Fix
I've followed the instructions from the README, copied below. Notice that it says to create an entry, passing metadata and a payload and then call
log.write(entry)
:However, in calls to
log.write(entry)
, it appears the final payload is being populated with the entireentry
object passed tolog.write()
and therefore theentry.metadata
isn't being applied at all.So either the README is wrong or there's a bug here. To fix this it seems would require either:
log.logSync()
, orThe text was updated successfully, but these errors were encountered: