-
Notifications
You must be signed in to change notification settings - Fork 227
/
https.js
68 lines (59 loc) · 1.97 KB
/
https.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright Elasticsearch B.V. and other contributors where applicable.
* Licensed under the BSD 2-Clause License; you may not use this file except in
* compliance with the BSD 2-Clause License.
*/
'use strict';
var semver = require('semver');
var httpShared = require('../http-shared');
var shimmer = require('../shimmer');
module.exports = function (
modExports,
agent,
{ version, enabled, isImportMod },
) {
if (agent._conf.instrumentIncomingHTTPRequests) {
agent.logger.debug('shimming https.Server.prototype.emit function');
shimmer.wrap(
modExports && modExports.Server && modExports.Server.prototype,
'emit',
httpShared.instrumentRequest(agent, 'https'),
);
}
if (!enabled) {
return modExports;
}
// From Node.js v9.0.0 and onwards, https requests no longer just call the
// http.request function. So to correctly instrument outgoing HTTPS requests
// in all supported Node.js versions, we'll only only instrument the
// https.request function if the Node version is v9.0.0 or above.
//
// This change was introduced in:
// https://github.com/nodejs/node/commit/5118f3146643dc55e7e7bd3082d1de4d0e7d5426
if (semver.lt(version, '9.0.0')) {
// We must ensure that the `http` module is instrumented to intercept
// `http.{request,get}` that `https.{request,get}` are using.
require('http');
return modExports;
}
agent.logger.debug('shimming https.request function');
let wrapped = shimmer.wrap(
modExports,
'request',
httpShared.traceOutgoingRequest(agent, 'https', 'request'),
);
if (isImportMod && wrapped) {
// Handle `import https from 'https'`. See comment in "http.js".
modExports.default.request = wrapped;
}
agent.logger.debug('shimming https.get function');
wrapped = shimmer.wrap(
modExports,
'get',
httpShared.traceOutgoingRequest(agent, 'https', 'get'),
);
if (isImportMod && wrapped) {
modExports.default.get = wrapped;
}
return modExports;
};