appdynamics 21.9.0 → 22.5.0
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.
- package/appdynamics_version.json +2 -2
- package/lib/core/agent.js +22 -0
- package/lib/core/appDProxy.js +12 -12
- package/lib/core/logger.js +27 -79
- package/lib/core/opentelemetry-tracer.js +97 -0
- package/lib/libagent/libagent-connector.js +24 -0
- package/lib/libagent/libagent.js +2 -1
- package/lib/libagent/transaction-sender.js +14 -13
- package/lib/probes/apollo-entry-probe.js +69 -0
- package/lib/probes/couchbase-probe.js +19 -0
- package/lib/probes/grpc-exit-probe.js +1 -1
- package/lib/probes/http-common.js +97 -0
- package/lib/probes/http-entry-probe.js +42 -116
- package/lib/probes/http-exit-probe.js +93 -31
- package/lib/probes/http-ot-utils.js +117 -0
- package/lib/probes/http-probe.js +14 -7
- package/lib/probes/mongodb-probe.js +200 -113
- package/lib/profiler/profiler.js +5 -1
- package/lib/secure_app/library_metadata.js +56 -0
- package/lib/secure_app/secure_app.js +276 -0
- package/lib/utility.js +20 -1
- package/package.json +13 -8
- package/packageBck.json +13 -8
package/lib/probes/http-probe.js
CHANGED
|
@@ -7,33 +7,36 @@ All Rights Reserved
|
|
|
7
7
|
|
|
8
8
|
var HttpEntryProbe = require('./http-entry-probe').HttpEntryProbe;
|
|
9
9
|
var HttpExitProbe = require('./http-exit-probe').HttpExitProbe;
|
|
10
|
+
var ApolloEntryProbe = require('./apollo-entry-probe').ApolloEntryProbe;
|
|
10
11
|
|
|
11
12
|
function HttpProbe(agent) {
|
|
12
13
|
this.agent = agent;
|
|
13
|
-
this.packages = ['http', 'https', 'express-graphql'];
|
|
14
|
+
this.packages = ['http', 'https', 'express-graphql', 'apollo-server'];
|
|
14
15
|
|
|
15
16
|
this.entryProbe = new HttpEntryProbe(agent);
|
|
16
17
|
this.exitProbe = new HttpExitProbe(agent);
|
|
18
|
+
this.apolloEntryProbe = new ApolloEntryProbe(agent);
|
|
17
19
|
|
|
18
20
|
this.init();
|
|
19
21
|
}
|
|
20
22
|
exports.HttpProbe = HttpProbe;
|
|
21
23
|
|
|
22
|
-
HttpProbe.prototype.init = function() {
|
|
24
|
+
HttpProbe.prototype.init = function () {
|
|
23
25
|
this.entryProbe.init();
|
|
24
26
|
this.exitProbe.init();
|
|
27
|
+
this.apolloEntryProbe.init();
|
|
25
28
|
};
|
|
26
29
|
|
|
27
|
-
HttpProbe.prototype.attach = function(obj, moduleName) {
|
|
30
|
+
HttpProbe.prototype.attach = function (obj, moduleName) {
|
|
28
31
|
var self = this;
|
|
29
32
|
var proxy = this.agent.proxy;
|
|
30
33
|
|
|
31
|
-
if(obj.__appdynamicsProbeAttached__) return;
|
|
34
|
+
if (obj.__appdynamicsProbeAttached__) return;
|
|
32
35
|
obj.__appdynamicsProbeAttached__ = true;
|
|
33
|
-
self.agent.on('destroy', function() {
|
|
34
|
-
if(obj.__appdynamicsProbeAttached__) {
|
|
36
|
+
self.agent.on('destroy', function () {
|
|
37
|
+
if (obj.__appdynamicsProbeAttached__) {
|
|
35
38
|
delete obj.__appdynamicsProbeAttached__;
|
|
36
|
-
if (moduleName !== 'express-graphql') {
|
|
39
|
+
if (moduleName !== 'express-graphql' && moduleName !== 'apollo-server') {
|
|
37
40
|
proxy.release(obj.Server.prototype.on);
|
|
38
41
|
proxy.release(obj.Server.prototype.addListener);
|
|
39
42
|
proxy.release(obj.request);
|
|
@@ -45,6 +48,10 @@ HttpProbe.prototype.attach = function(obj, moduleName) {
|
|
|
45
48
|
if (self.agent.opts.enableGraphQL) {
|
|
46
49
|
this.entryProbe.enableGraphQL(obj);
|
|
47
50
|
}
|
|
51
|
+
} else if (moduleName === 'apollo-server') {
|
|
52
|
+
if(self.agent.opts.enableGraphQL) {
|
|
53
|
+
this.apolloEntryProbe.attach(obj, moduleName);
|
|
54
|
+
}
|
|
48
55
|
} else {
|
|
49
56
|
this.entryProbe.attach(obj, moduleName);
|
|
50
57
|
this.exitProbe.attach(obj, moduleName);
|
|
@@ -43,18 +43,33 @@ MongodbProbe.prototype.attach = function (obj) {
|
|
|
43
43
|
if (obj.__appdynamicsProbeAttached__) {
|
|
44
44
|
delete obj.__appdynamicsProbeAttached__;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
46
|
proxy.release(obj.Db.prototype.createCollection);
|
|
48
47
|
proxy.release(obj.Db.prototype.dropCollection);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
if(obj.Server){
|
|
49
|
+
proxy.release(obj.Server.prototype.cursor);
|
|
50
|
+
proxy.release(obj.Server.prototype.insert);
|
|
51
|
+
proxy.release(obj.Server.prototype.update);
|
|
52
|
+
proxy.release(obj.Server.prototype.remove);
|
|
53
|
+
}
|
|
54
|
+
if(obj.ReplSet){
|
|
55
|
+
proxy.release(obj.ReplSet.prototype.cursor);
|
|
56
|
+
proxy.release(obj.ReplSet.prototype.insert);
|
|
57
|
+
proxy.release(obj.ReplSet.prototype.update);
|
|
58
|
+
proxy.release(obj.ReplSet.prototype.remove);
|
|
59
|
+
}
|
|
60
|
+
if(obj.Cursor){
|
|
61
|
+
proxy.release(obj.Cursor.prototype.next);
|
|
62
|
+
}
|
|
63
|
+
if(obj.Collection){
|
|
64
|
+
proxy.release(obj.Collection.prototype.find);
|
|
65
|
+
proxy.release(obj.Collection.prototype.insert);
|
|
66
|
+
proxy.release(obj.Collection.prototype.aggregate);
|
|
67
|
+
proxy.release(obj.Collection.prototype.remove);
|
|
68
|
+
proxy.release(obj.Collection.prototype.update);
|
|
69
|
+
}
|
|
70
|
+
if(obj.AbstractCursor){
|
|
71
|
+
proxy.release(obj.AbstractCursor.prototype.next);
|
|
72
|
+
}
|
|
58
73
|
});
|
|
59
74
|
|
|
60
75
|
if ('instrument' in obj) {
|
|
@@ -138,127 +153,200 @@ MongodbProbe.prototype.attach = function (obj) {
|
|
|
138
153
|
collectionCommands.forEach(function (command) {
|
|
139
154
|
proxy.before(obj.Db.prototype, command, withAPMBeforeHandler);
|
|
140
155
|
});
|
|
141
|
-
} else if (!('version' in obj)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
} else if (!('version' in obj)) {
|
|
157
|
+
if (obj.Cursor){
|
|
158
|
+
// driver 2.x w/out APM API
|
|
159
|
+
var commands = ['cursor', 'insert', 'update', 'remove'];
|
|
160
|
+
|
|
161
|
+
// queries via a cursor find command must be reported after they complete:
|
|
162
|
+
proxy.around(obj.Cursor.prototype, '_next', function (obj, args, locals) {
|
|
163
|
+
locals.methodHasCb = proxy.callback(args, -1, function (obj_, args) {
|
|
164
|
+
complete(args, obj);
|
|
165
|
+
});
|
|
166
|
+
}, after);
|
|
167
|
+
|
|
168
|
+
collectionCommands.forEach(function (command) {
|
|
169
|
+
function withoutAPMBeforeHandler(obj, args, locals) {
|
|
170
|
+
var commandDetails;
|
|
171
|
+
var category;
|
|
172
|
+
var commandName = command == 'cursor' ? 'find' : command;
|
|
173
|
+
|
|
174
|
+
if (command == 'cursor' && !args[1].find) return;
|
|
175
|
+
var serverPool = [];
|
|
176
|
+
if (obj.serverConfig instanceof mongoObj.ReplSet)
|
|
177
|
+
serverPool = self.getServerPool(obj.serverConfig.s, true);
|
|
178
|
+
else
|
|
179
|
+
serverPool = self.getServerPool(obj);
|
|
180
|
+
if (serverPool.length) {
|
|
181
|
+
commandDetails = {
|
|
182
|
+
command: commandName,
|
|
183
|
+
databaseName: obj.s.databaseName,
|
|
184
|
+
collectionName: args[0]
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (obj.auths && obj.auths.length > 0) {
|
|
188
|
+
commandDetails.auth = obj.auths[0];
|
|
189
|
+
}
|
|
151
190
|
|
|
152
|
-
|
|
153
|
-
function withoutAPMBeforeHandler(obj, args, locals) {
|
|
154
|
-
var commandDetails;
|
|
155
|
-
var category;
|
|
156
|
-
var commandName = command == 'cursor' ? 'find' : command;
|
|
191
|
+
category = "write";
|
|
157
192
|
|
|
158
|
-
|
|
159
|
-
var serverPool = [];
|
|
160
|
-
if (obj.serverConfig instanceof mongoObj.ReplSet)
|
|
161
|
-
serverPool = self.getServerPool(obj.serverConfig.s, true);
|
|
162
|
-
else
|
|
163
|
-
serverPool = self.getServerPool(obj);
|
|
164
|
-
if (serverPool.length) {
|
|
165
|
-
commandDetails = {
|
|
166
|
-
command: commandName,
|
|
167
|
-
databaseName: obj.s.databaseName,
|
|
168
|
-
collectionName: args[0]
|
|
169
|
-
};
|
|
193
|
+
locals.time = profiler.time();
|
|
170
194
|
|
|
171
|
-
|
|
172
|
-
|
|
195
|
+
locals.exitCall = self.createExitCall(locals.time, serverPool,
|
|
196
|
+
commandDetails, category, profiler.stackTrace());
|
|
173
197
|
}
|
|
174
198
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
locals.exitCall = self.createExitCall(locals.time, serverPool,
|
|
180
|
-
commandDetails, category, profiler.stackTrace());
|
|
199
|
+
locals.methodHasCb = proxy.callback(args, -1, function (obj, args) {
|
|
200
|
+
self.addExitCall(locals.time, locals.exitCall, args);
|
|
201
|
+
});
|
|
181
202
|
}
|
|
182
203
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
proxy.around(obj.Db.prototype, command, withoutAPMBeforeHandler, withoutAPMAfterHandler);
|
|
189
|
-
});
|
|
204
|
+
proxy.around(obj.Db.prototype, command, withoutAPMBeforeHandler, withoutAPMAfterHandler);
|
|
205
|
+
});
|
|
190
206
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
207
|
+
commands.forEach(function (command) {
|
|
208
|
+
var commandName = command == 'cursor' ? 'find' : command;
|
|
209
|
+
function withoutAPMBeforeHandler(obj, args, locals) {
|
|
210
|
+
var commandDetails;
|
|
211
|
+
var category;
|
|
212
|
+
var opts = {};
|
|
213
|
+
var query = '';
|
|
214
|
+
|
|
215
|
+
if (command == 'cursor' && !args[1].find) return;
|
|
216
|
+
|
|
217
|
+
var serverPool = [];
|
|
218
|
+
if (obj instanceof mongoObj.ReplSet)
|
|
219
|
+
serverPool = self.getServerPool(obj.s, true);
|
|
220
|
+
else
|
|
221
|
+
serverPool = self.getServerPool(obj.s);
|
|
222
|
+
if (serverPool.length) {
|
|
223
|
+
opts = {};
|
|
224
|
+
if (args[1] && args[1].query) {
|
|
225
|
+
query = args[1].query;
|
|
226
|
+
if (Object.prototype.toString.call(query) == "[object Object]") {
|
|
227
|
+
query = utility.filterSensitiveDataFromObject(Object.assign({}, args[1].query));
|
|
228
|
+
}
|
|
229
|
+
query = profiler.sanitize(JSON.stringify(query));
|
|
230
|
+
Object.keys(args[1]).forEach(function (key) {
|
|
231
|
+
if (key !== 'query') {
|
|
232
|
+
opts[key] = args[1][key];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
198
236
|
|
|
199
|
-
|
|
237
|
+
commandDetails = {
|
|
238
|
+
command: commandName,
|
|
239
|
+
databaseName: args[0].split('.')[0],
|
|
240
|
+
collectionName: args[0].split('.')[1],
|
|
241
|
+
query: query,
|
|
242
|
+
numberToSkip: opts.skip,
|
|
243
|
+
numberToReturn: opts.limit
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
if (obj.s.auths && obj.s.auths.length > 0) {
|
|
247
|
+
commandDetails.auth = obj.s.auths[0];
|
|
248
|
+
}
|
|
200
249
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
serverPool = self.getServerPool(obj.s);
|
|
206
|
-
if (serverPool.length) {
|
|
207
|
-
opts = {};
|
|
208
|
-
if (args[1] && args[1].query) {
|
|
209
|
-
query = args[1].query;
|
|
210
|
-
if (Object.prototype.toString.call(query) == "[object Object]") {
|
|
211
|
-
query = utility.filterSensitiveDataFromObject(Object.assign({}, args[1].query));
|
|
250
|
+
if (commandName == 'find') {
|
|
251
|
+
category = "read";
|
|
252
|
+
} else {
|
|
253
|
+
category = "write";
|
|
212
254
|
}
|
|
213
|
-
query = profiler.sanitize(JSON.stringify(query));
|
|
214
|
-
Object.keys(args[1]).forEach(function (key) {
|
|
215
|
-
if (key !== 'query') {
|
|
216
|
-
opts[key] = args[1][key];
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
255
|
|
|
221
|
-
|
|
222
|
-
command: commandName,
|
|
223
|
-
databaseName: args[0].split('.')[0],
|
|
224
|
-
collectionName: args[0].split('.')[1],
|
|
225
|
-
query: query,
|
|
226
|
-
numberToSkip: opts.skip,
|
|
227
|
-
numberToReturn: opts.limit
|
|
228
|
-
};
|
|
256
|
+
locals.time = profiler.time();
|
|
229
257
|
|
|
230
|
-
|
|
231
|
-
|
|
258
|
+
locals.exitCall = self.createExitCall(locals.time, serverPool,
|
|
259
|
+
commandDetails, category, profiler.stackTrace());
|
|
232
260
|
}
|
|
233
261
|
|
|
234
262
|
if (commandName == 'find') {
|
|
235
|
-
|
|
263
|
+
// stash exit call for later processing
|
|
264
|
+
args[1].__appd_exitcall_info = {
|
|
265
|
+
time: locals.time,
|
|
266
|
+
exitCall: locals.exitCall
|
|
267
|
+
};
|
|
268
|
+
locals.methodHasCb = true;
|
|
236
269
|
} else {
|
|
237
|
-
|
|
270
|
+
locals.methodHasCb = proxy.callback(args, -1, function (obj, args) {
|
|
271
|
+
self.addExitCall(locals.time, locals.exitCall, args);
|
|
272
|
+
}, null, self.agent.thread.current());
|
|
238
273
|
}
|
|
239
|
-
|
|
240
|
-
locals.time = profiler.time();
|
|
241
|
-
|
|
242
|
-
locals.exitCall = self.createExitCall(locals.time, serverPool,
|
|
243
|
-
commandDetails, category, profiler.stackTrace());
|
|
244
274
|
}
|
|
275
|
+
proxy.around(obj.Server.prototype, command, withoutAPMBeforeHandler, withoutAPMAfterHandler);
|
|
276
|
+
proxy.around(obj.ReplSet.prototype, command, withoutAPMBeforeHandler, withoutAPMAfterHandler);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
else{
|
|
280
|
+
proxy.before(obj.MongoClient.prototype, 'connect', function(obj){
|
|
281
|
+
obj.monitorCommands = true;
|
|
282
|
+
var newServerPool;
|
|
283
|
+
var newOpQueue = {};
|
|
284
|
+
var newApmCollectionEvents = ['create', 'drop'];
|
|
285
|
+
var newCollectionCommandMap = {
|
|
286
|
+
'create': 'createCollection',
|
|
287
|
+
'drop': 'dropCollection',
|
|
288
|
+
'find': 'find',
|
|
289
|
+
'cursor': 'cursor',
|
|
290
|
+
'insert': 'insert',
|
|
291
|
+
'update': 'update',
|
|
292
|
+
'remove': 'remove',
|
|
293
|
+
'aggregate': 'aggregate'
|
|
294
|
+
};
|
|
295
|
+
var newSupportedCommands = ['find', 'cursor', 'insert', 'update', 'remove', 'aggregate'].concat(newApmCollectionEvents);
|
|
296
|
+
|
|
297
|
+
// expose opQueue for integration testing
|
|
298
|
+
self.__opQueue = newOpQueue;
|
|
299
|
+
obj.on('commandStarted', (event) => {
|
|
300
|
+
var requestId = event.requestId, newRequest, newCommandQuery;
|
|
301
|
+
if (newSupportedCommands.indexOf(event.commandName) < 0) return;
|
|
302
|
+
if (event.address) {
|
|
303
|
+
newServerPool = [event.address];
|
|
304
|
+
}
|
|
305
|
+
if (newServerPool) {
|
|
306
|
+
if (!newOpQueue[requestId]) {
|
|
307
|
+
newOpQueue[requestId] = {
|
|
308
|
+
time: profiler.time(),
|
|
309
|
+
serverPool: newServerPool
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
newRequest = newOpQueue[requestId];
|
|
313
|
+
newCommandQuery = event.command.filter;
|
|
314
|
+
if (event.command.filter && Object.prototype.toString.call(event.command.filter) == "[object Object]") {
|
|
315
|
+
newCommandQuery = utility.filterSensitiveDataFromObject(utility.deepCopy(event.command.filter));
|
|
316
|
+
}
|
|
317
|
+
var commandDetails = {
|
|
318
|
+
command: newCollectionCommandMap[event.commandName],
|
|
319
|
+
databaseName: event.databaseName,
|
|
320
|
+
collectionName: event.command[event.commandName],
|
|
321
|
+
query: profiler.sanitize(JSON.stringify(newCommandQuery)),
|
|
322
|
+
numberToSkip: event.command.skip,
|
|
323
|
+
numberToReturn: event.command.limit
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
newRequest.exitCall = self.createExitCall(newRequest.time, newServerPool,
|
|
328
|
+
commandDetails, event.commandName == 'find' ? 'read' : 'write',
|
|
329
|
+
profiler.stackTrace());
|
|
330
|
+
}
|
|
331
|
+
});
|
|
245
332
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
time
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
333
|
+
obj.on('commandSucceeded', function (event) {
|
|
334
|
+
var requestId = event.requestId, newRequest = newOpQueue[requestId];
|
|
335
|
+
if (newRequest) {
|
|
336
|
+
self.addExitCall(newRequest.time, newRequest.exitCall);
|
|
337
|
+
newOpQueue[requestId] = undefined;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
obj.on('commandFailed', function (event) {
|
|
342
|
+
var requestId = event.requestId, newRequest = newOpQueue[requestId];
|
|
343
|
+
if (newRequest) {
|
|
344
|
+
self.addExitCall(event.time, event.exitCall, event.failure);
|
|
345
|
+
newOpQueue[requestId] = undefined;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
}
|
|
262
350
|
}
|
|
263
351
|
|
|
264
352
|
function complete(err, obj, driver) {
|
|
@@ -356,11 +444,10 @@ MongodbProbe.prototype.createExitCall = function (time, serverPool, commandDetai
|
|
|
356
444
|
MongodbProbe.prototype.addExitCall = function (time, exitCall, args) {
|
|
357
445
|
var self = this;
|
|
358
446
|
if (!time || !time.done()) return;
|
|
359
|
-
|
|
360
447
|
var error = self.agent.proxy.getErrorObject(args);
|
|
361
448
|
var profiler = self.agent.profiler;
|
|
362
449
|
|
|
363
450
|
if (exitCall) {
|
|
364
451
|
profiler.addExitCall(time, exitCall, error);
|
|
365
452
|
}
|
|
366
|
-
};
|
|
453
|
+
};
|
package/lib/profiler/profiler.js
CHANGED
|
@@ -84,7 +84,7 @@ Profiler.prototype.formatStackTrace = function (err) {
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
Profiler.prototype.startTransaction = function
|
|
87
|
+
Profiler.prototype.startTransaction = function(time, req, entryType, baggageCorrHeader) {
|
|
88
88
|
var self = this;
|
|
89
89
|
|
|
90
90
|
var transaction = new Transaction();
|
|
@@ -101,6 +101,10 @@ Profiler.prototype.startTransaction = function (time, req, entryType) {
|
|
|
101
101
|
parsedParameterString: req.url ? url.parse(req.url).query : ''
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
+
if(baggageCorrHeader) {
|
|
105
|
+
transaction.baggageCorrHeader = baggageCorrHeader;
|
|
106
|
+
}
|
|
107
|
+
|
|
104
108
|
self.transactions[time.threadId] = transaction;
|
|
105
109
|
|
|
106
110
|
var delayedCallbackAttached = false;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var path = require('path');
|
|
2
|
+
|
|
3
|
+
const MAX_ITEMS_PER_GROUP = 1024;
|
|
4
|
+
|
|
5
|
+
exports.LibraryMetadata = LibraryMetadata;
|
|
6
|
+
function LibraryMetadata(agent) {
|
|
7
|
+
var self = this;
|
|
8
|
+
self.agent = agent;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
LibraryMetadata.prototype.init = function() {
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
LibraryMetadata.prototype.getMetadata = function() {
|
|
15
|
+
var self = this;
|
|
16
|
+
if(!self.metadataCache) {
|
|
17
|
+
self.metadataCache = self._getMetadata();
|
|
18
|
+
}
|
|
19
|
+
return self.metadataCache;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
LibraryMetadata.prototype._getJson = function()
|
|
23
|
+
{
|
|
24
|
+
var rootPath = require('path').resolve('./');
|
|
25
|
+
return require(path.join(rootPath, './package-lock.json'));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
LibraryMetadata.prototype._getMetadata = function() {
|
|
29
|
+
var self = this;
|
|
30
|
+
try {
|
|
31
|
+
var pkjson = self._getJson();
|
|
32
|
+
var metadataCache = [];
|
|
33
|
+
var cacheGroup = [];
|
|
34
|
+
var itemCount = 0;
|
|
35
|
+
for (var pkg in pkjson.dependencies) {
|
|
36
|
+
if(itemCount == MAX_ITEMS_PER_GROUP) {
|
|
37
|
+
metadataCache.push(cacheGroup);
|
|
38
|
+
cacheGroup = [];
|
|
39
|
+
itemCount = 0;
|
|
40
|
+
}
|
|
41
|
+
cacheGroup.push({
|
|
42
|
+
name: pkg,
|
|
43
|
+
version: pkjson.dependencies[pkg].version
|
|
44
|
+
});
|
|
45
|
+
itemCount = itemCount + 1;
|
|
46
|
+
}
|
|
47
|
+
} catch(error) {
|
|
48
|
+
self.agent.logger.warn('Error reading package metadata ' + error);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if(cacheGroup.length) {
|
|
52
|
+
metadataCache.push(cacheGroup);
|
|
53
|
+
}
|
|
54
|
+
return metadataCache;
|
|
55
|
+
};
|
|
56
|
+
|