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 4257164
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 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
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

0 comments on commit 4257164

Please sign in to comment.