Просмотр исходного кода

Merge pull request #5691 from overleaf/em-logger

More GCP logging improvements

GitOrigin-RevId: 6049567c5d713582551b58169c019596fc68493e
Eric Mc Sween 4 лет назад
Родитель
Сommit
7d8c1397be

+ 21 - 5
libraries/logger/gcp-manager.js

@@ -37,12 +37,23 @@ function convertLogEntry(entry) {
     }
     if (entry.err.stack) {
       gcpEntry.message = entry.err.stack
+    } else if (entry.err.message) {
+      gcpEntry.message = entry.err.message
     }
     if (entry.name) {
       gcpEntry.serviceContext = { service: entry.name }
     }
-  } else {
-    gcpEntry.message = entry.msg
+  }
+
+  // Log message
+  if (entry.msg) {
+    if (gcpEntry.message) {
+      // A message has already been extracted from the error. Keep the extra
+      // message in the msg property.
+      gcpEntry.msg = entry.msg
+    } else {
+      gcpEntry.message = entry.msg
+    }
   }
 
   // Severity
@@ -85,9 +96,14 @@ function convertLogEntry(entry) {
   }
 
   // Labels are indexed in GCP. We copy the project, doc and user ids to labels to enable fast filtering
-  const projectId = gcpEntry.projectId || gcpEntry.project_id
-  const userId = gcpEntry.userId || gcpEntry.user_id
-  const docId = gcpEntry.docId || gcpEntry.doc_id
+  const projectId =
+    gcpEntry.projectId ||
+    gcpEntry.project_id ||
+    (entry.req && entry.req.projectId)
+  const userId =
+    gcpEntry.userId || gcpEntry.user_id || (entry.req && entry.req.userId)
+  const docId =
+    gcpEntry.docId || gcpEntry.doc_id || (entry.req && entry.req.docId)
   if (projectId || userId || docId) {
     const labels = {}
     if (projectId) {

Разница между файлами не показана из-за своего большого размера
+ 636 - 30
libraries/logger/package-lock.json


+ 1 - 2
libraries/logger/package.json

@@ -7,7 +7,7 @@
     "url": "https://github.com/overleaf/overleaf"
   },
   "license": "AGPL-3.0-only",
-  "version": "3.0.0",
+  "version": "3.1.0",
   "scripts": {
     "test": "mocha --grep=$MOCHA_GREP test/**/*.js",
     "format": "prettier-eslint $PWD'/**/*.js' --list-different",
@@ -17,7 +17,6 @@
     "test:ci": "npm run test"
   },
   "dependencies": {
-    "@google-cloud/logging-bunyan": "^3.1.0",
     "@overleaf/o-error": "^3.0.0",
     "@sentry/node": "^6.13.2",
     "bunyan": "^1.8.14",

+ 16 - 2
libraries/logger/serializers.js

@@ -7,7 +7,7 @@ function errSerializer(err) {
   return {
     message: err.message,
     name: err.name,
-    stack: OError.getFullStack(err),
+    stack: err.stack && OError.getFullStack(err),
     info: OError.getFullInfo(err),
     code: err.code,
     signal: err.signal
@@ -19,7 +19,7 @@ function reqSerializer(req) {
     return req
   }
   const headers = req.headers || {}
-  return {
+  const entry = {
     method: req.method,
     url: req.originalUrl || req.url,
     remoteAddress: getRemoteIp(req),
@@ -29,6 +29,20 @@ function reqSerializer(req) {
       'content-length': headers['content-length']
     }
   }
+  const projectId =
+    req.params.projectId || req.params.project_id || req.params.Project_id
+  const userId = req.params.userId || req.params.user_id
+  const docId = req.params.docId || req.params.doc_id
+  if (projectId) {
+    entry.projectId = projectId
+  }
+  if (userId) {
+    entry.userId = userId
+  }
+  if (docId) {
+    entry.docId = docId
+  }
+  return entry
 }
 
 function resSerializer(res) {

+ 0 - 1
libraries/logger/test/unit/logging-manager-tests.js

@@ -50,7 +50,6 @@ describe('LoggingManager', function () {
     this.LoggingManager = SandboxedModule.require(MODULE_PATH, {
       requires: {
         bunyan: this.Bunyan,
-        '@google-cloud/logging-bunyan': this.GCPLogging,
         './log-level-checker': this.LogLevelChecker,
         './sentry-manager': sinon.stub().returns(this.SentryManager)
       }

Некоторые файлы не были показаны из-за большого количества измененных файлов