Merge pull request #6926 from overleaf/jpa-clsi-bump-logger-metrics

[clsi] upgrade logger and metrics module

GitOrigin-RevId: 85c346b5eed683672a77d86d6a434dc313b7824b
This commit is contained in:
Jakob Ackermann
2022-03-02 09:02:50 +00:00
committed by Copybot
parent bc4be9ddad
commit 958216d578
29 changed files with 61 additions and 92 deletions
+23 -15
View File
@@ -1,6 +1,5 @@
const Stream = require('stream')
const bunyan = require('bunyan')
const yn = require('yn')
const GCPManager = require('./gcp-manager')
const SentryManager = require('./sentry-manager')
const Serializers = require('./serializers')
@@ -74,20 +73,29 @@ const LoggingManager = {
},
_getOutputStreamConfig() {
const gcpEnabled = yn(process.env.GCP_LOGGING)
if (gcpEnabled) {
const stream = new Stream.Writable({
objectMode: true,
write(entry, encoding, callback) {
const gcpEntry = GCPManager.convertLogEntry(entry)
// eslint-disable-next-line no-console
console.log(JSON.stringify(gcpEntry, bunyan.safeCycles()))
setImmediate(callback)
},
})
return { level: this.defaultLevel, type: 'raw', stream }
} else {
return { level: this.defaultLevel, stream: process.stdout }
switch (process.env.LOGGING_FORMAT) {
case 'gke': {
const stream = new Stream.Writable({
objectMode: true,
write(entry, encoding, callback) {
const gcpEntry = GCPManager.convertLogEntry(entry)
// eslint-disable-next-line no-console
console.log(JSON.stringify(gcpEntry, bunyan.safeCycles()))
setImmediate(callback)
},
})
return { level: this.defaultLevel, type: 'raw', stream }
}
case 'gce': {
const { LoggingBunyan } = require('@google-cloud/logging-bunyan')
return new LoggingBunyan({
logName: this.loggerName,
serviceContext: { service: this.loggerName },
}).stream(this.defaultLevel)
}
default: {
return { level: this.defaultLevel, stream: process.stdout }
}
}
},