@companieshouse/structured-logging-node 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
28
+ const api = __importStar(require("@opentelemetry/api-logs"));
29
+ const sdk_logs_1 = require("@opentelemetry/sdk-logs");
30
+ const resources_1 = require("@opentelemetry/resources");
5
31
  const HumanFormatFactory_1 = __importDefault(require("./formatting/HumanFormatFactory"));
6
32
  const JsonFormatFactory_1 = __importDefault(require("./formatting/JsonFormatFactory"));
33
+ const exporter_logs_otlp_http_1 = require("@opentelemetry/exporter-logs-otlp-http");
34
+ const winston_transport_1 = require("@opentelemetry/winston-transport");
7
35
  const config_1 = __importDefault(require("./config"));
8
36
  const levelConfig_1 = __importDefault(require("./levelConfig"));
9
37
  const winston_1 = __importDefault(require("winston"));
@@ -18,10 +46,24 @@ class LoggerFactory {
18
46
  }
19
47
  static create(options) {
20
48
  winston_1.default.addColors(levelConfig_1.default.colours);
49
+ if (config_1.default.otelLogEnabled) {
50
+ const loggerProvider = new sdk_logs_1.LoggerProvider({
51
+ // Service.name, service.version correlated with logs
52
+ resource: (0, resources_1.detectResources)({
53
+ detectors: [resources_1.envDetector, resources_1.processDetector, resources_1.hostDetector]
54
+ })
55
+ });
56
+ loggerProvider.addLogRecordProcessor(new sdk_logs_1.BatchLogRecordProcessor(new exporter_logs_otlp_http_1.OTLPLogExporter()));
57
+ api.logs.setGlobalLoggerProvider(loggerProvider);
58
+ }
59
+ const transports = [
60
+ new winston_1.default.transports.Console(this.createTransportOptions(options.namespace)),
61
+ ...config_1.default.otelLogEnabled ? [new winston_transport_1.OpenTelemetryTransportV3()] : []
62
+ ];
21
63
  return winston_1.default.createLogger({
22
64
  level: config_1.default.level,
23
65
  levels: levelConfig_1.default.levels,
24
- transports: [new winston_1.default.transports.Console(this.createTransportOptions(options.namespace))],
66
+ transports: transports,
25
67
  exitOnError: false
26
68
  });
27
69
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LoggerFactory.js","sourceRoot":"","sources":["../src/LoggerFactory.ts"],"names":[],"mappings":";;;;AAAA,yFAAiE;AACjE,uFAA+D;AAG/D,sDAA8B;AAC9B,gEAAsC;AACtC,sDAA8B;AAE9B,MAAM,aAAa;IAEP,MAAM,CAAC,sBAAsB,CAAC,SAAiB;QACnD,OAAO;YACH,gBAAgB,EAAE,IAAI;YACtB,MAAM,EAAE,gBAAM,CAAC,aAAa,CAAC,CAAC;gBAC1B,4BAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;gBACtC,2BAAiB,CAAC,MAAM,CAAC,SAAS,CAAC;SAC1C,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,OAAsB;QAEvC,iBAAO,CAAC,SAAS,CAAC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EH,cAAc,CAAC,qBAAqB,CAChC,IAAI,kCAAuB,CAAC,IAAI,yCAAe,EAAE,CAAC,CACrD,CAAC;YACF,GAAG,CAAC,IAAI,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC;SACpD;QAED,MAAM,UAAU,GAAG;YACf,IAAI,iBAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAC9E,GAAG,gBAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,4CAAwB,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;SACnE,CAAC;QAEF,OAAO,iBAAO,CAAC,YAAY,CAAC;YACxB,KAAK,EAAE,gBAAM,CAAC,KAAK;YACnB,MAAM,EAAE,qBAAS,CAAC,MAAM;YACxB,UAAU,EAAE,UAAU;YACtB,WAAW,EAAE,KAAK;SACrB,CAAqB,CAAC;IAC3B,CAAC;CACJ;AAED,iBAAS,aAAa,CAAC"}
package/lib/config.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  declare const config: {
2
2
  level: string;
3
3
  humanReadable: boolean;
4
+ otelLogEnabled: boolean;
4
5
  };
5
6
  export = config;
package/lib/config.js CHANGED
@@ -3,7 +3,8 @@ const config = {
3
3
  level: process.env.LOG_LEVEL === undefined ? "info" : process.env.LOG_LEVEL.toLowerCase(),
4
4
  humanReadable: process.env.HUMAN_LOG === undefined ?
5
5
  false :
6
- process.env.HUMAN_LOG === "1"
6
+ process.env.HUMAN_LOG === "1",
7
+ otelLogEnabled: process.env.OTEL_LOG_ENABLED === "true"
7
8
  };
8
9
  module.exports = config;
9
10
  //# sourceMappingURL=config.js.map
package/lib/config.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,GAAG;IACX,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE;IACzF,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;QAChD,KAAK,CAAC,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,GAAG;CACpC,CAAC;AAEF,iBAAS,MAAM,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA,MAAM,MAAM,GAAG;IACX,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE;IACzF,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;QAChD,KAAK,CAAC,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,GAAG;IACjC,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,MAAM;CAC1D,CAAC;AAEF,iBAAS,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@companieshouse/structured-logging-node",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "A logging solution for CHS structured logging in node apps.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "scripts": {
8
8
  "lint": "eslint 'src/*.ts' 'src/**/*.ts' 'test/**/*.ts'",
9
9
  "lint:fix": "eslint 'src/*.ts' 'src/**/*.ts' 'test/**/*.ts' --fix",
10
- "test": "mocha -r ts-node/register --recursive --reporter nyan test --extension ts",
10
+ "test": "mocha -r ts-node/register --recursive test --extension ts",
11
11
  "test:watch": "mocha -r ts-node/register --recursive --reporter nyan test --extension ts --watch",
12
+ "test:coverage": "nyc --reporter=lcov --reporter=text-summary npm test",
12
13
  "build": "tsc",
13
14
  "sonarqube": "sonar-scanner",
14
15
  "prepublishOnly": "[ ! -d node_modules ] && npm install; tsc",
@@ -21,6 +22,11 @@
21
22
  "author": "",
22
23
  "license": "MIT",
23
24
  "dependencies": {
25
+ "@opentelemetry/api": "^1.9.0",
26
+ "@opentelemetry/api-logs": "^0.200.0",
27
+ "@opentelemetry/auto-instrumentations-node": "^0.56.1",
28
+ "@opentelemetry/sdk-logs": "^0.200.0",
29
+ "@opentelemetry/winston-transport": "^0.11.0",
24
30
  "moment": "^2.29.4",
25
31
  "on-finished": "~2.3.0",
26
32
  "winston": "~3.3.3"
@@ -36,17 +42,18 @@
36
42
  "chai": "~4.2.0",
37
43
  "eslint": "^7.32.0",
38
44
  "eslint-config-standard": "14.1.1",
45
+ "eslint-plugin-chai-friendly": "~0.6.0",
39
46
  "eslint-plugin-import": "2.23.0",
40
47
  "eslint-plugin-node": "11.1.0",
41
48
  "eslint-plugin-promise": "6.0.0",
42
49
  "eslint-plugin-standard": "5.0.0",
43
- "eslint-plugin-chai-friendly": "~0.6.0",
44
- "mocha": "^9.2.2",
50
+ "mocha": "^11.1.0",
45
51
  "mockdate": "~3.0.2",
46
52
  "proxyquire": "~2.1.3",
47
53
  "sonarqube-scanner": "^2.9.1",
48
54
  "ts-node": "^10.8.1",
49
- "typescript": "^4.1.6"
55
+ "typescript": "^4.1.6",
56
+ "nyc": "^15.1.0"
50
57
  },
51
58
  "files": [
52
59
  "lib/**/*"