diff --git a/packages/opentelemetry-plugin-grpc/package.json b/packages/opentelemetry-plugin-grpc/package.json index 0d53cdc1e7..19325634d8 100644 --- a/packages/opentelemetry-plugin-grpc/package.json +++ b/packages/opentelemetry-plugin-grpc/package.json @@ -49,7 +49,7 @@ "node-pre-gyp": "^0.12.0", "rimraf": "^3.0.0", "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" diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index eda6b30d6e..0819fd6718 100644 --- a/packages/opentelemetry-plugin-grpc/src/grpc.ts +++ b/packages/opentelemetry-plugin-grpc/src/grpc.ts @@ -51,13 +51,11 @@ let grpcClientModule: object; export class GrpcPlugin extends BasePlugin { 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 = { diff --git a/packages/opentelemetry-plugin-grpc/test/grpc.test.ts b/packages/opentelemetry-plugin-grpc/test/grpc.test.ts index c4bc624e0f..3b641f7e4f 100644 --- a/packages/opentelemetry-plugin-grpc/test/grpc.test.ts +++ b/packages/opentelemetry-plugin-grpc/test/grpc.test.ts @@ -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); diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index 2eff3abd58..d75508066d 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -43,13 +43,11 @@ import { Utils } from './utils'; */ export class HttpPlugin extends BasePlugin { 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. */ @@ -208,8 +206,8 @@ export class HttpPlugin extends BasePlugin { 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(); @@ -248,7 +246,7 @@ export class HttpPlugin extends BasePlugin { 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]); } @@ -314,8 +312,8 @@ export class HttpPlugin extends BasePlugin { .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(); @@ -351,7 +349,7 @@ export class HttpPlugin extends BasePlugin { options = optionsParsed; if ( - Utils.isIgnored(origin + pathname, plugin.options.ignoreOutgoingUrls) + Utils.isIgnored(origin + pathname, plugin._config.ignoreOutgoingUrls) ) { return original.apply(this, [options, ...args]); } diff --git a/packages/opentelemetry-plugin-http/src/types.ts b/packages/opentelemetry-plugin-http/src/types.ts index 831d4ba7fd..05fe033863 100644 --- a/packages/opentelemetry-plugin-http/src/types.ts +++ b/packages/opentelemetry-plugin-http/src/types.ts @@ -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, @@ -57,7 +57,7 @@ export interface HttpCustomAttributeFunction { ): void; } -export interface HttpPluginConfig { +export interface HttpPluginConfig extends PluginConfig { ignoreIncomingPaths?: IgnoreMatcher[]; ignoreOutgoingUrls?: IgnoreMatcher[]; applyCustomAttributesOnSpan?: HttpCustomAttributeFunction; diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts index 5dbf00c842..c5cf9e1e34 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts @@ -28,6 +28,7 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/basic-tracer'; +import { HttpPluginConfig } from '../../src'; let server: http.Server; const serverPort = 22345; @@ -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'); diff --git a/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts index 7a612e6539..9bdc3a97a2 100644 --- a/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/integrations/http-enable.test.ts @@ -29,6 +29,7 @@ import { InMemorySpanExporter, SimpleSpanProcessor, } from '@opentelemetry/basic-tracer'; +import { HttpPluginConfig } from '../../src/types'; const serverPort = 32345; const hostname = 'localhost'; @@ -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(() => {