@opencensus/instrumentation-https
Advanced tools
Comparing version
@@ -1,16 +0,1 @@ | ||
/** | ||
* Copyright 2018, OpenCensus Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { HttpPlugin } from '@opencensus/instrumentation-http'; | ||
@@ -25,2 +10,4 @@ /** Https instrumentation plugin for Opencensus */ | ||
protected applyPatch(): any; | ||
/** Patches HTTPS outgoing requests */ | ||
private getPatchHttpsOutgoingRequest(); | ||
/** Unpatches all HTTPS patched function. */ | ||
@@ -27,0 +14,0 @@ protected applyUnpatch(): void; |
@@ -19,2 +19,4 @@ "use strict"; | ||
const instrumentation_http_1 = require("@opencensus/instrumentation-http"); | ||
const https = require("https"); | ||
const semver = require("semver"); | ||
const shimmer = require("shimmer"); | ||
@@ -40,6 +42,23 @@ /** Https instrumentation plugin for Opencensus */ | ||
} | ||
// TODO: review the need to patch 'request' | ||
shimmer.wrap(this.moduleExports, 'get', this.getPatchOutgoingRequestFunction()); | ||
shimmer.wrap(this.moduleExports, 'request', this.getPatchHttpsOutgoingRequest()); | ||
if (semver.satisfies(this.version, '>=8.0.0')) { | ||
shimmer.wrap(this.moduleExports, 'get', this.getPatchHttpsOutgoingRequest()); | ||
} | ||
return this.moduleExports; | ||
} | ||
/** Patches HTTPS outgoing requests */ | ||
getPatchHttpsOutgoingRequest() { | ||
return (original) => { | ||
const plugin = this; | ||
return function httpsOutgoingRequest(options, callback) { | ||
// Makes sure options will have default HTTPS parameters | ||
if (typeof (options) !== 'string') { | ||
options.protocol = options.protocol || 'https:'; | ||
options.port = options.port || 443; | ||
options.agent = options.agent || https.globalAgent; | ||
} | ||
return (plugin.getPatchOutgoingRequestFunction())(original)(options, callback); | ||
}; | ||
}; | ||
} | ||
/** Unpatches all HTTPS patched function. */ | ||
@@ -52,3 +71,6 @@ applyUnpatch() { | ||
} | ||
shimmer.unwrap(this.moduleExports, 'get'); | ||
shimmer.unwrap(this.moduleExports, 'request'); | ||
if (semver.satisfies(this.version, '>=8.0.0')) { | ||
shimmer.unwrap(this.moduleExports, 'get'); | ||
} | ||
} | ||
@@ -55,0 +77,0 @@ } |
{ | ||
"name": "@opencensus/instrumentation-https", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Opencensus https automatic instrumentation package.", | ||
@@ -59,4 +59,4 @@ "main": "build/src/index.js", | ||
"dependencies": { | ||
"@opencensus/instrumentation-http": "^0.0.2", | ||
"@opencensus/opencensus-core": "^0.0.2", | ||
"@opencensus/core": "^0.0.3", | ||
"@opencensus/instrumentation-http": "^0.0.3", | ||
"semver": "^5.5.0", | ||
@@ -63,0 +63,0 @@ "shimmer": "^1.2.0" |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
19291
2.4%130
7.44%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed