diff --git a/packages/opentelemetry-plugin-grpc/package.json b/packages/opentelemetry-plugin-grpc/package.json index 0b23c459b06..7842e165855 100644 --- a/packages/opentelemetry-plugin-grpc/package.json +++ b/packages/opentelemetry-plugin-grpc/package.json @@ -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" diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index eda6b30d6e6..0819fd6718a 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-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index d3603ca9ab7..9ce71eb280b 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. */ @@ -204,8 +202,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(); @@ -244,7 +242,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]); } @@ -309,8 +307,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(); @@ -346,7 +344,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 831d4ba7fdb..05fe0338630 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 5dbf00c842e..c5cf9e1e349 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');