Skip to content

Commit

Permalink
fix: avoid circular require in plugins (#1551)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Sep 22, 2020
1 parent e8d69a2 commit 059aa83
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
5 changes: 2 additions & 3 deletions packages/opentelemetry-plugin-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import {
NoRecordingSpan,
getExtractedSpanContext,
} from '@opentelemetry/core';
import {
import type {
ClientRequest,
IncomingMessage,
request,
RequestOptions,
ServerResponse,
} from 'http';
Expand Down Expand Up @@ -95,7 +94,7 @@ export class HttpPlugin extends BasePlugin<Http> {
shimmer.wrap(
this._moduleExports,
'get',
this._getPatchOutgoingGetFunction(request)
this._getPatchOutgoingGetFunction(this._moduleExports.request)
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-http/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { PluginConfig, Span } from '@opentelemetry/api';
import * as http from 'http';
import type * as http from 'http';
import {
ClientRequest,
get,
Expand Down
15 changes: 10 additions & 5 deletions packages/opentelemetry-plugin-https/src/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
*/

import { HttpPlugin, Func, HttpRequestArgs } from '@opentelemetry/plugin-http';
import * as http from 'http';
import * as https from 'https';
import type * as http from 'http';
import type * as https from 'https';
import { URL } from 'url';
import * as semver from 'semver';
import * as shimmer from 'shimmer';
import * as utils from './utils';

/**
* Https instrumentation plugin for Opentelemetry
Expand Down Expand Up @@ -70,7 +69,7 @@ export class HttpsPlugin extends HttpPlugin {
shimmer.wrap(
this._moduleExports,
'get',
this._getPatchHttpsOutgoingGetFunction(https.request)
this._getPatchHttpsOutgoingGetFunction(this._moduleExports.request)
);
}

Expand All @@ -88,7 +87,7 @@ export class HttpsPlugin extends HttpPlugin {
// Makes sure options will have default HTTPS parameters
if (typeof options === 'object' && !(options instanceof URL)) {
options = Object.assign({}, options);
utils.setDefaultOptions(options as https.RequestOptions);
plugin._setDefaultOptions(options);
}
return plugin._getPatchOutgoingRequestFunction()(original)(
options,
Expand All @@ -98,6 +97,12 @@ export class HttpsPlugin extends HttpPlugin {
};
}

private _setDefaultOptions(options: https.RequestOptions) {
options.protocol = options.protocol || 'https:';
options.port = options.port || 443;
options.agent = options.agent || this._moduleExports.globalAgent;
}

/** Patches HTTPS outgoing get requests */
private _getPatchHttpsOutgoingGetFunction(
clientRequest: (
Expand Down
23 changes: 0 additions & 23 deletions packages/opentelemetry-plugin-https/src/utils.ts

This file was deleted.

0 comments on commit 059aa83

Please sign in to comment.