diff --git a/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts b/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts index a370a56a165..cdb6567ebd1 100644 --- a/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts +++ b/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts @@ -14,73 +14,86 @@ * limitations under the License. */ -import { - InstrumentationBase, - InstrumentationConfig, -} from '@opentelemetry/instrumentation'; +import { InstrumentationConfig } from '@opentelemetry/instrumentation'; import { GrpcInstrumentationConfig } from './types'; import { VERSION } from './version'; -import { getGrpcPatches } from './grpc'; -import { getGrpcJsPatches } from './grpc-js'; +import { GrpcNativeInstrumentation } from './grpc'; +import { GrpcJsInstrumentation } from './grpc-js'; +import * as api from '@opentelemetry/api'; /** The metadata key under which span context is stored as a binary value. */ export const GRPC_TRACE_KEY = 'grpc-trace-bin'; -export class GrpcInstrumentation extends InstrumentationBase { +export class GrpcInstrumentation { + private _grpcNativeInstrumentation: GrpcNativeInstrumentation; + private _grpcJsInstrumentation: GrpcJsInstrumentation; + + public readonly instrumentationName: string = + '@opentelemetry/instrumentation-grpc'; + public readonly instrumentationVersion: string = VERSION; + constructor( protected _config: GrpcInstrumentationConfig & InstrumentationConfig = {} ) { - super('@opentelemetry/instrumentation-grpc', VERSION, _config); + this._grpcJsInstrumentation = new GrpcJsInstrumentation( + _config, + this.instrumentationName, + this.instrumentationVersion + ); + this._grpcNativeInstrumentation = new GrpcNativeInstrumentation( + _config, + this.instrumentationName, + this.instrumentationVersion + ); } public setConfig( config: GrpcInstrumentationConfig & InstrumentationConfig = {} ) { this._config = Object.assign({}, config); + this._grpcJsInstrumentation.setConfig(this._config); + this._grpcNativeInstrumentation.setConfig(this._config); } /** * @internal - * Public reference to the protected BaseInstrumentation shimmer utils to be used by this + * Public reference to the protected BaseInstrumentation `_config` instance to be used by this * plugin's external helper functions */ - public getShimmer() { - return { - wrap: this._wrap, - unwrap: this._unwrap, - massWrap: this._massWrap, - massUnwrap: this._massUnwrap, - }; + public getConfig() { + return this._config; } - /** - * @internal - * Public reference to the protected BaseInstrumentation `_logger` instance to be used by this - * plugin's external helper functions - */ - public getLogger() { - return this._logger; + init() { + // sub instrumentations will already be init when constructing them + return; } - /** - * @internal - * Public reference to the protected BaseInstrumentation `tracer` instance to be used by this - * plugin's external helper functions - */ - public getTracer() { - return this.tracer; + enable() { + this._grpcJsInstrumentation.enable(); + this._grpcNativeInstrumentation.enable(); + } + + disable() { + this._grpcJsInstrumentation.disable(); + this._grpcNativeInstrumentation.disable(); } /** - * @internal - * Public reference to the protected BaseInstrumentation `_config` instance to be used by this - * plugin's external helper functions + * Sets MeterProvider to this plugin + * @param meterProvider */ - public getConfig() { - return this._config; + public setMeterProvider(meterProvider: api.MeterProvider) { + this._grpcJsInstrumentation.setMeterProvider(meterProvider); + this._grpcNativeInstrumentation.setMeterProvider(meterProvider); } - init() { - return [...getGrpcJsPatches.call(this), ...getGrpcPatches.call(this)]; + /** + * Sets TraceProvider to this plugin + * @param tracerProvider + */ + public setTracerProvider(tracerProvider: api.TracerProvider) { + this._grpcJsInstrumentation.setTracerProvider(tracerProvider); + this._grpcNativeInstrumentation.setTracerProvider(tracerProvider); } }