Skip to content

Commit 013a1e4

Browse files
OlivierAlbertinimayurkale22
authored andcommitted
fix: change options to config based on BasePlugin (open-telemetry#314)
closes open-telemetry#313 Signed-off-by: Olivier Albertini <[email protected]>
1 parent 0024d0a commit 013a1e4

File tree

7 files changed

+24
-26
lines changed

7 files changed

+24
-26
lines changed

Diff for: packages/opentelemetry-plugin-grpc/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"node-pre-gyp": "^0.12.0",
5050
"rimraf": "^3.0.0",
5151
"tslint-microsoft-contrib": "^6.2.0",
52-
"tslint-consistent-codestyle":"^1.15.1",
52+
"tslint-consistent-codestyle": "^1.15.1",
5353
"ts-mocha": "^6.0.0",
5454
"ts-node": "^8.3.0",
5555
"typescript": "^3.5.3"

Diff for: packages/opentelemetry-plugin-grpc/src/grpc.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ let grpcClientModule: object;
5151
export class GrpcPlugin extends BasePlugin<grpc> {
5252
static readonly component = 'grpc';
5353

54-
options!: GrpcPluginOptions;
54+
protected _config!: GrpcPluginOptions;
5555

5656
constructor(readonly moduleName: string, readonly version: string) {
5757
super();
58-
// TODO: remove this once options will be passed
59-
// see https://github.com/open-telemetry/opentelemetry-js/issues/210
60-
this.options = {};
58+
this._config = {};
6159
}
6260

6361
protected readonly _internalFilesList: ModuleExportsMapping = {

Diff for: packages/opentelemetry-plugin-grpc/test/grpc.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,10 @@ describe('GrpcPlugin', () => {
514514
});
515515

516516
before(() => {
517-
plugin.enable(grpc, tracer, logger);
518-
plugin.options = {
517+
const config = {
519518
// TODO: add plugin options here once supported
520519
};
520+
plugin.enable(grpc, tracer, logger, config);
521521

522522
const proto = grpc.load(PROTO_PATH).pkg_test;
523523
server = startServer(grpc, proto);

Diff for: packages/opentelemetry-plugin-http/src/http.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ import { Utils } from './utils';
4343
*/
4444
export class HttpPlugin extends BasePlugin<Http> {
4545
static readonly component = 'http';
46-
options!: HttpPluginConfig;
46+
protected _config!: HttpPluginConfig;
4747

4848
constructor(readonly moduleName: string, readonly version: string) {
4949
super();
50-
// TODO: remove this once options will be passed
51-
// see https://github.com/open-telemetry/opentelemetry-js/issues/210
52-
this.options = {};
50+
this._config = {};
5351
}
5452

5553
/** Patches HTTP incoming and outcoming request functions. */
@@ -208,8 +206,8 @@ export class HttpPlugin extends BasePlugin<Http> {
208206

209207
span.setAttributes(attributes);
210208

211-
if (this.options.applyCustomAttributesOnSpan) {
212-
this.options.applyCustomAttributesOnSpan(span, request, response);
209+
if (this._config.applyCustomAttributesOnSpan) {
210+
this._config.applyCustomAttributesOnSpan(span, request, response);
213211
}
214212

215213
span.end();
@@ -248,7 +246,7 @@ export class HttpPlugin extends BasePlugin<Http> {
248246

249247
plugin._logger.debug('%s plugin incomingRequest', plugin.moduleName);
250248

251-
if (Utils.isIgnored(pathname, plugin.options.ignoreIncomingPaths)) {
249+
if (Utils.isIgnored(pathname, plugin._config.ignoreIncomingPaths)) {
252250
return original.apply(this, [event, ...args]);
253251
}
254252

@@ -314,8 +312,8 @@ export class HttpPlugin extends BasePlugin<Http> {
314312
.setAttributes(attributes)
315313
.setStatus(Utils.parseResponseStatus(response.statusCode));
316314

317-
if (plugin.options.applyCustomAttributesOnSpan) {
318-
plugin.options.applyCustomAttributesOnSpan(span, request, response);
315+
if (plugin._config.applyCustomAttributesOnSpan) {
316+
plugin._config.applyCustomAttributesOnSpan(span, request, response);
319317
}
320318

321319
span.end();
@@ -351,7 +349,7 @@ export class HttpPlugin extends BasePlugin<Http> {
351349
options = optionsParsed;
352350

353351
if (
354-
Utils.isIgnored(origin + pathname, plugin.options.ignoreOutgoingUrls)
352+
Utils.isIgnored(origin + pathname, plugin._config.ignoreOutgoingUrls)
355353
) {
356354
return original.apply(this, [options, ...args]);
357355
}

Diff for: packages/opentelemetry-plugin-http/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Span } from '@opentelemetry/types';
17+
import { Span, PluginConfig } from '@opentelemetry/types';
1818
import * as url from 'url';
1919
import {
2020
ClientRequest,
@@ -57,7 +57,7 @@ export interface HttpCustomAttributeFunction {
5757
): void;
5858
}
5959

60-
export interface HttpPluginConfig {
60+
export interface HttpPluginConfig extends PluginConfig {
6161
ignoreIncomingPaths?: IgnoreMatcher[];
6262
ignoreOutgoingUrls?: IgnoreMatcher[];
6363
applyCustomAttributesOnSpan?: HttpCustomAttributeFunction;

Diff for: packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
InMemorySpanExporter,
2929
SimpleSpanProcessor,
3030
} from '@opentelemetry/basic-tracer';
31+
import { HttpPluginConfig } from '../../src';
3132

3233
let server: http.Server;
3334
const serverPort = 22345;
@@ -80,17 +81,17 @@ describe('HttpPlugin', () => {
8081
});
8182

8283
before(() => {
83-
plugin.enable(http, tracer, tracer.logger);
8484
const ignoreConfig = [
8585
`http://${hostname}/ignored/string`,
8686
/\/ignored\/regexp$/i,
8787
(url: string) => url.endsWith(`/ignored/function`),
8888
];
89-
plugin.options = {
89+
const config: HttpPluginConfig = {
9090
ignoreIncomingPaths: ignoreConfig,
9191
ignoreOutgoingUrls: ignoreConfig,
9292
applyCustomAttributesOnSpan: customAttributeFunction,
9393
};
94+
plugin.enable(http, tracer, tracer.logger, config);
9495

9596
server = http.createServer((request, response) => {
9697
response.end('Test Server Response');

Diff for: packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
InMemorySpanExporter,
3030
SimpleSpanProcessor,
3131
} from '@opentelemetry/basic-tracer';
32+
import { HttpPluginConfig } from '../../src/types';
3233

3334
const serverPort = 32345;
3435
const hostname = 'localhost';
@@ -68,20 +69,20 @@ describe('HttpPlugin Integration tests', () => {
6869
});
6970

7071
before(() => {
71-
try {
72-
plugin.disable();
73-
} catch (e) {}
74-
plugin.enable(http, tracer, tracer.logger);
7572
const ignoreConfig = [
7673
`http://${hostname}:${serverPort}/ignored/string`,
7774
/\/ignored\/regexp$/i,
7875
(url: string) => url.endsWith(`/ignored/function`),
7976
];
80-
plugin.options = {
77+
const config: HttpPluginConfig = {
8178
ignoreIncomingPaths: ignoreConfig,
8279
ignoreOutgoingUrls: ignoreConfig,
8380
applyCustomAttributesOnSpan: customAttributeFunction,
8481
};
82+
try {
83+
plugin.disable();
84+
} catch (e) {}
85+
plugin.enable(http, tracer, tracer.logger, config);
8586
});
8687

8788
after(() => {

0 commit comments

Comments
 (0)