Skip to content

Commit

Permalink
fix: change options to config based on BasePlugin
Browse files Browse the repository at this point in the history
closes #313

Signed-off-by: Olivier Albertini <[email protected]>
  • Loading branch information
OlivierAlbertini committed Sep 22, 2019
1 parent 48ccbf1 commit 66f33d7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"tslint-microsoft-contrib": "^6.2.0",
"tslint-consistent-codestyle":"^1.15.1",
"tslint-consistent-codestyle": "^1.15.1",
"ts-mocha": "^6.0.0",
"ts-node": "^8.3.0",
"typescript": "^3.5.3"
Expand Down
6 changes: 2 additions & 4 deletions packages/opentelemetry-plugin-grpc/src/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ let grpcClientModule: object;
export class GrpcPlugin extends BasePlugin<grpc> {
static readonly component = 'grpc';

options!: GrpcPluginOptions;
protected _config!: GrpcPluginOptions;

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

protected readonly _internalFilesList: ModuleExportsMapping = {
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-plugin-grpc/test/grpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,10 @@ describe('GrpcPlugin', () => {
});

before(() => {
plugin.enable(grpc, tracer, logger);
plugin.options = {
const config = {
// TODO: add plugin options here once supported
};
plugin.enable(grpc, tracer, logger, config);

const proto = grpc.load(PROTO_PATH).pkg_test;
server = startServer(grpc, proto);
Expand Down
18 changes: 8 additions & 10 deletions packages/opentelemetry-plugin-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ import { Utils } from './utils';
*/
export class HttpPlugin extends BasePlugin<Http> {
static readonly component = 'http';
options!: HttpPluginConfig;
protected _config!: HttpPluginConfig;

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

/** Patches HTTP incoming and outcoming request functions. */
Expand Down Expand Up @@ -204,8 +202,8 @@ export class HttpPlugin extends BasePlugin<Http> {

span.setAttributes(attributes);

if (this.options.applyCustomAttributesOnSpan) {
this.options.applyCustomAttributesOnSpan(span, request, response);
if (this._config.applyCustomAttributesOnSpan) {
this._config.applyCustomAttributesOnSpan(span, request, response);
}

span.end();
Expand Down Expand Up @@ -244,7 +242,7 @@ export class HttpPlugin extends BasePlugin<Http> {

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

if (Utils.isIgnored(pathname, plugin.options.ignoreIncomingPaths)) {
if (Utils.isIgnored(pathname, plugin._config.ignoreIncomingPaths)) {
return original.apply(this, [event, ...args]);
}

Expand Down Expand Up @@ -309,8 +307,8 @@ export class HttpPlugin extends BasePlugin<Http> {
.setAttributes(attributes)
.setStatus(Utils.parseResponseStatus(response.statusCode));

if (plugin.options.applyCustomAttributesOnSpan) {
plugin.options.applyCustomAttributesOnSpan(span, request, response);
if (plugin._config.applyCustomAttributesOnSpan) {
plugin._config.applyCustomAttributesOnSpan(span, request, response);
}

span.end();
Expand Down Expand Up @@ -346,7 +344,7 @@ export class HttpPlugin extends BasePlugin<Http> {
options = optionsParsed;

if (
Utils.isIgnored(origin + pathname, plugin.options.ignoreOutgoingUrls)
Utils.isIgnored(origin + pathname, plugin._config.ignoreOutgoingUrls)
) {
return original.apply(this, [options, ...args]);
}
Expand Down
4 changes: 2 additions & 2 deletions 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 { Span } from '@opentelemetry/types';
import { Span, PluginConfig } from '@opentelemetry/types';
import * as url from 'url';
import {
ClientRequest,
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface HttpCustomAttributeFunction {
): void;
}

export interface HttpPluginConfig {
export interface HttpPluginConfig extends PluginConfig {
ignoreIncomingPaths?: IgnoreMatcher[];
ignoreOutgoingUrls?: IgnoreMatcher[];
applyCustomAttributesOnSpan?: HttpCustomAttributeFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
InMemorySpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/basic-tracer';
import { HttpPluginConfig } from '../../src';

let server: http.Server;
const serverPort = 22345;
Expand Down Expand Up @@ -80,17 +81,17 @@ describe('HttpPlugin', () => {
});

before(() => {
plugin.enable(http, tracer, tracer.logger);
const ignoreConfig = [
`http://${hostname}/ignored/string`,
/\/ignored\/regexp$/i,
(url: string) => url.endsWith(`/ignored/function`),
];
plugin.options = {
const config: HttpPluginConfig = {
ignoreIncomingPaths: ignoreConfig,
ignoreOutgoingUrls: ignoreConfig,
applyCustomAttributesOnSpan: customAttributeFunction,
};
plugin.enable(http, tracer, tracer.logger, config);

server = http.createServer((request, response) => {
response.end('Test Server Response');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
InMemorySpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/basic-tracer';
import { HttpPluginConfig } from '../../src/types';

const serverPort = 32345;
const hostname = 'localhost';
Expand Down Expand Up @@ -68,20 +69,20 @@ describe('HttpPlugin Integration tests', () => {
});

before(() => {
try {
plugin.disable();
} catch (e) {}
plugin.enable(http, tracer, tracer.logger);
const ignoreConfig = [
`http://${hostname}:${serverPort}/ignored/string`,
/\/ignored\/regexp$/i,
(url: string) => url.endsWith(`/ignored/function`),
];
plugin.options = {
const config: HttpPluginConfig = {
ignoreIncomingPaths: ignoreConfig,
ignoreOutgoingUrls: ignoreConfig,
applyCustomAttributesOnSpan: customAttributeFunction,
};
try {
plugin.disable();
} catch (e) {}
plugin.enable(http, tracer, tracer.logger, config);
});

after(() => {
Expand Down

0 comments on commit 66f33d7

Please sign in to comment.