I want to read BigQuery log entries to do some analysis. But I can't seem to get the protoPayload.value
decoded. I've tried messing around with the google-proto-files
and protocol-buffers
packages, but I think I'm missing something really obvious here...
const Logging = require('@google-cloud/logging');
const protobuf = require('protocol-buffers');
const protoFiles = require('google-proto-files');
const protoPath = './node_modules/google-proto-files/google/cloud/audit/audit_log.proto';
const root = protoFiles.loadSync(protoPath)
const AuditLog = root.lookup('google.cloud.audit.AuditLog');
const client = new Logging.v2.LoggingServiceV2Client({ projectId });
client.listLogEntriesStream({resourceNames, filter, pageSize})
.on('data', entry => {
console.log(entry); // Entry is of type AuditLog
console.log(AuditLog.decode(entry.protoPayload.value.buffer));
process.exit(1)
})
.on('error', e => console.error(e))
.on('end', () => console.info('END RECEIVED', arguments))
I do receive messages with protoPayloads, but the error I receive when attempting to decode the message is this:
Error: no such Type or Enum 'google.rpc.Status' in Type .google.cloud.audit.AuditLog
The actual question: What is the proper way to decode the protoPayload
field in a LogEntry
?
Thanks!