@felloh-org/lambda-wrapper 1.10.8 → 1.10.9

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.
@@ -21,6 +21,7 @@ class DependencyInjection {
21
21
  constructor(configuration, event, context) {
22
22
  this.event = event;
23
23
  this.context = context;
24
+ this.lumigo = null;
24
25
  this.dependencies = {};
25
26
  this.configuration = configuration;
26
27
 
@@ -129,6 +130,33 @@ class DependencyInjection {
129
130
  get definitions() {
130
131
  return this.configuration.DEFINITIONS;
131
132
  }
133
+ /**
134
+ * Set Lumigo
135
+ * @param lumigo
136
+ */
137
+
138
+
139
+ setLumigo(lumigo) {
140
+ this.lumigo = lumigo;
141
+ }
142
+ /**
143
+ * Get Lumigo
144
+ * @return {null}
145
+ */
146
+
147
+
148
+ getLumigo() {
149
+ return this.lumigo;
150
+ }
151
+ /**
152
+ * Check to see whether lumigo is enabled
153
+ * @return {boolean}
154
+ */
155
+
156
+
157
+ lumigoIsEnabled() {
158
+ return this.lumigo !== null;
159
+ }
132
160
 
133
161
  }
134
162
 
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _epsagon = _interopRequireDefault(require("epsagon"));
9
-
10
8
  var _winston = _interopRequireDefault(require("winston"));
11
9
 
12
10
  var _dependencyAware = _interopRequireDefault(require("../dependency-injection/dependency-aware"));
@@ -19,6 +17,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
17
  class Logger extends _dependencyAware.default {
20
18
  constructor(di) {
21
19
  super(di);
20
+ this.lumigo = di.getLumigo();
21
+ this.lumigoIsEnabled = di.lumigoIsEnabled();
22
22
  this.winston = null;
23
23
  }
24
24
  /**
@@ -136,8 +136,10 @@ class Logger extends _dependencyAware.default {
136
136
 
137
137
 
138
138
  error(error, message = '') {
139
- if (typeof process.env.EPSAGON_TOKEN === 'string' && process.env.EPSAGON_TOKEN !== 'undefined' && typeof process.env.EPSAGON_SERVICE_NAME === 'string' && process.env.EPSAGON_SERVICE_NAME !== 'undefined' && error instanceof Error) {
140
- _epsagon.default.setError(error);
139
+ if (this.lumigoIsEnabled) {
140
+ this.lumigo.error('error', {
141
+ err: error
142
+ });
141
143
  }
142
144
 
143
145
  this.logger.log('error', message, {
@@ -154,6 +156,10 @@ class Logger extends _dependencyAware.default {
154
156
 
155
157
 
156
158
  info(message) {
159
+ if (this.lumigoIsEnabled) {
160
+ this.lumigo.info(message);
161
+ }
162
+
157
163
  this.logger.log('info', this.processMessage(message));
158
164
  }
159
165
  /**
@@ -172,6 +178,12 @@ class Logger extends _dependencyAware.default {
172
178
  warning(error) {
173
179
  const softWarningValues = ['true', '1'];
174
180
 
181
+ if (this.lumigoIsEnabled) {
182
+ this.lumigo.info('warning', {
183
+ err: error
184
+ });
185
+ }
186
+
175
187
  if (softWarningValues.includes(process.env.LOGGER_SOFT_WARNING)) {
176
188
  return this.info(error);
177
189
  }
@@ -187,8 +199,8 @@ class Logger extends _dependencyAware.default {
187
199
 
188
200
 
189
201
  label(descriptor, silent = false) {
190
- if (typeof process.env.EPSAGON_TOKEN === 'string' && process.env.EPSAGON_TOKEN !== 'undefined' && typeof process.env.EPSAGON_SERVICE_NAME === 'string' && process.env.EPSAGON_SERVICE_NAME !== 'undefined') {
191
- _epsagon.default.label(descriptor);
202
+ if (this.lumigoIsEnabled) {
203
+ this.lumigo.addExecutionTag(descriptor);
192
204
  }
193
205
 
194
206
  if (silent === false) {
@@ -205,8 +217,8 @@ class Logger extends _dependencyAware.default {
205
217
 
206
218
 
207
219
  metric(descriptor, stat, silent = false) {
208
- if (typeof process.env.EPSAGON_TOKEN === 'string' && process.env.EPSAGON_TOKEN !== 'undefined' && typeof process.env.EPSAGON_SERVICE_NAME === 'string' && process.env.EPSAGON_SERVICE_NAME !== 'undefined') {
209
- _epsagon.default.label(descriptor, stat);
220
+ if (this.lumigoIsEnabled) {
221
+ this.lumigo.addExecutionTag(descriptor, stat);
210
222
  }
211
223
 
212
224
  if (silent === false) {
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.handleSuccess = exports.handleError = exports.default = void 0;
7
7
 
8
- var _epsagon = _interopRequireDefault(require("epsagon"));
8
+ var _tracer = _interopRequireDefault(require("@lumigo/tracer"));
9
9
 
10
10
  var _dependencies = require("../config/dependencies");
11
11
 
@@ -38,19 +38,7 @@ const handleSuccess = (di, outcome) => {
38
38
  return outcome;
39
39
  };
40
40
  /**
41
- * Gracefully handles an error
42
- * logging in Epsagon and generating
43
- * a response reflecting the `code`
44
- * of the error, if defined.
45
- *
46
- * Note about Epsagon:
47
- * Epsagon generates alerts for logs on level ERROR.
48
- * This means that logger.error will produce an alert.
49
- * To avoid not meaningful notifications, most likely
50
- * coming from tests, we log INFO unless either:
51
- *
52
- * 1. `error.raiseOnEpsagon` is defined & truthy
53
- * 2. `error.code` is defined and `error.code >= 500`.
41
+ * Handle an error
54
42
  *
55
43
  * @param {DependencyInjection} di
56
44
  * @param {Error} error
@@ -97,8 +85,17 @@ const handleError = (di, error) => {
97
85
  exports.handleError = handleError;
98
86
 
99
87
  const wrapper = (configuration, handler, throwError = false) => {
88
+ let lumigo = null;
89
+
90
+ if (typeof process.env.LUMIGO_TOKEN === 'string' && process.env.LUMIGO_TOKEN !== 'undefined') {
91
+ lumigo = (0, _tracer.default)({
92
+ token: process.env.LUMIGO_TOKEN
93
+ });
94
+ }
95
+
100
96
  let instance = (event, context, callback) => {
101
97
  const di = new _dependencyInjection.default(configuration, event, context);
98
+ di.setLumigo(lumigo);
102
99
  const request = di.get(_dependencies.DEFINITIONS.REQUEST);
103
100
  const logger = di.get(_dependencies.DEFINITIONS.LOGGER);
104
101
  context.callbackWaitsForEmptyEventLoop = false; // If the event is to trigger a warm up, then don't bother returning the function.
@@ -146,16 +143,11 @@ const wrapper = (configuration, handler, throwError = false) => {
146
143
  }
147
144
 
148
145
  return outcome;
149
- }; // If the Epsagon token is enabled, then wrap the instance in the Epsagon wrapper
146
+ }; // If the Lumigo token is enabled, then wrap the instance in the Lumigo wrapper
150
147
 
151
148
 
152
- if (typeof process.env.EPSAGON_TOKEN === 'string' && process.env.EPSAGON_TOKEN !== 'undefined' && typeof process.env.EPSAGON_SERVICE_NAME === 'string' && process.env.EPSAGON_SERVICE_NAME !== 'undefined') {
153
- _epsagon.default.init({
154
- token: process.env.EPSAGON_TOKEN,
155
- appName: process.env.EPSAGON_SERVICE_NAME
156
- });
157
-
158
- instance = _epsagon.default.lambdaWrapper(instance);
149
+ if (lumigo !== null) {
150
+ instance = lumigo.trace(instance);
159
151
  }
160
152
 
161
153
  return instance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@felloh-org/lambda-wrapper",
3
- "version": "1.10.8",
3
+ "version": "1.10.9",
4
4
  "description": "Lambda wrapper for all Felloh Serverless Projects",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -54,6 +54,7 @@
54
54
  "aws-sdk": ">=2.831.0"
55
55
  },
56
56
  "dependencies": {
57
+ "@lumigo/tracer": "^1.83.0",
57
58
  "alai": "^1.0.3",
58
59
  "async": "^3.2.3",
59
60
  "axios": "^0.26.1",