From 02bfc6ef168b663aebcc968e75d5f958ded0a4ff Mon Sep 17 00:00:00 2001 From: Myrotvorets Date: Sat, 30 Sep 2023 18:59:56 +0300 Subject: [PATCH] Bug fixes --- .eslintignore | 3 ++- package-lock.json | 2 ++ package.json | 2 ++ src/lib/tracing.mts | 2 ++ src/server.mts | 9 +++++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.eslintignore b/.eslintignore index fd94fd4a..0ce1b5b8 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ dist/** node_modules/** -*.js +*.cjs +*.mjs diff --git a/package-lock.json b/package-lock.json index 56c1cfb7..0c118ca0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,8 +16,10 @@ "@myrotvorets/express-microservice-middlewares": "^1.5.7", "@myrotvorets/oav-installer": "^4.0.1", "@myrotvorets/opentelemetry-configurator": "^5.0.0", + "@opentelemetry/api-logs": "^0.43.0", "@opentelemetry/instrumentation-express": "^0.33.0", "@opentelemetry/instrumentation-http": "^0.43.0", + "@opentelemetry/sdk-logs": "^0.43.0", "@wwa/statvfs": "^1.1.13", "envalid": "^8.0.0", "express": "^4.17.1", diff --git a/package.json b/package.json index a57c3532..5f8ca335 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,10 @@ "@myrotvorets/express-microservice-middlewares": "^1.5.7", "@myrotvorets/oav-installer": "^4.0.1", "@myrotvorets/opentelemetry-configurator": "^5.0.0", + "@opentelemetry/api-logs": "^0.43.0", "@opentelemetry/instrumentation-express": "^0.33.0", "@opentelemetry/instrumentation-http": "^0.43.0", + "@opentelemetry/sdk-logs": "^0.43.0", "@wwa/statvfs": "^1.1.13", "envalid": "^8.0.0", "express": "^4.17.1", diff --git a/src/lib/tracing.mts b/src/lib/tracing.mts index 9ebdb9cb..a68f27d8 100644 --- a/src/lib/tracing.mts +++ b/src/lib/tracing.mts @@ -2,6 +2,7 @@ import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; import { OpenTelemetryConfigurator } from '@myrotvorets/opentelemetry-configurator'; +import { BatchLogRecordProcessor, ConsoleLogRecordExporter } from '@opentelemetry/sdk-logs'; if (!+(process.env.ENABLE_TRACING || 0)) { process.env.OTEL_SDK_DISABLED = 'true'; @@ -10,6 +11,7 @@ if (!+(process.env.ENABLE_TRACING || 0)) { const configurator = new OpenTelemetryConfigurator({ serviceName: 'psb-api-identigraf-uploader', instrumentations: [new ExpressInstrumentation(), new HttpInstrumentation()], + logRecordProcessor: new BatchLogRecordProcessor(new ConsoleLogRecordExporter()), }); configurator.start(); diff --git a/src/server.mts b/src/server.mts index e7f6f3b1..6f0ff5f3 100644 --- a/src/server.mts +++ b/src/server.mts @@ -7,6 +7,7 @@ import { cleanUploadedFilesMiddleware } from '@myrotvorets/clean-up-after-multer import { createServer } from '@myrotvorets/create-server'; import morgan from 'morgan'; import { memoryStorage } from 'multer'; +import { logs } from '@opentelemetry/api-logs'; import { environment } from './lib/environment.mjs'; @@ -71,6 +72,14 @@ export function setupApp(): Express { ), ); + app.use((req, res, next) => { + const logger = logs.getLogger('default'); + logger.emit({ + body: `${req.method} ${req.url} ${req.ip}`, + }); + next(); + }); + return app; }