Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid circular require in plugins #1551

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.