Skip to content

Commit

Permalink
Do not export node-specific names
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Nov 20, 2023
1 parent 343ca78 commit bf30779
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@
*/

export * from './autoLoader';
export {
InstrumentationBase,
InstrumentationModuleDefinition,
InstrumentationModuleFile,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
} from './platform/index';
export { InstrumentationBase } from './platform/index';
export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition';
export * from './types';
export * from './types_internal';
export * from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ import {
TracerProvider,
} from '@opentelemetry/api';
import * as shimmer from 'shimmer';
import { InstrumentationModuleDefinition } from './platform/node';
import * as types from './types';
import {
InstrumentationModuleDefinition,
Instrumentation,
InstrumentationConfig,
} from './types';

/**
* Base abstract internal class for instrumenting node and web plugins
*/
export abstract class InstrumentationAbstract<T = any>
implements types.Instrumentation
implements Instrumentation
{
protected _config: types.InstrumentationConfig;
protected _config: InstrumentationConfig;

private _tracer: Tracer;
private _meter: Meter;
Expand All @@ -43,7 +46,7 @@ export abstract class InstrumentationAbstract<T = any>
constructor(
public readonly instrumentationName: string,
public readonly instrumentationVersion: string,
config: types.InstrumentationConfig = {}
config: InstrumentationConfig = {}
) {
this._config = {
enabled: true,
Expand Down Expand Up @@ -95,15 +98,15 @@ export abstract class InstrumentationAbstract<T = any>
}

/* Returns InstrumentationConfig */
public getConfig(): types.InstrumentationConfig {
public getConfig(): InstrumentationConfig {
return this._config;
}

/**
* Sets InstrumentationConfig to this plugin
* @param InstrumentationConfig
*/
public setConfig(config: types.InstrumentationConfig = {}): void {
public setConfig(config: InstrumentationConfig = {}): void {
this._config = Object.assign({}, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './instrumentation';
export { InstrumentationBase } from './instrumentation';
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@
* limitations under the License.
*/

export {
InstrumentationBase,
InstrumentationModuleDefinition,
InstrumentationModuleFile,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
} from './node';
export { InstrumentationBase } from './node';
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@
* limitations under the License.
*/
export { InstrumentationBase } from './instrumentation';
export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition';
export { InstrumentationNodeModuleFile } from './instrumentationNodeModuleFile';
export {
InstrumentationModuleDefinition,
InstrumentationModuleFile,
} from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from './RequireInTheMiddleSingleton';
import type { HookFn } from 'import-in-the-middle';
import * as ImportInTheMiddle from 'import-in-the-middle';
import { InstrumentationModuleDefinition } from './types';
import { InstrumentationModuleDefinition } from '../../types';
import { diag } from '@opentelemetry/api';
import type { OnRequireFn } from 'require-in-the-middle';
import { Hook } from 'require-in-the-middle';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { InstrumentationModuleFile } from './types';
import { InstrumentationModuleFile } from '../../types';
import { normalize } from 'path';

export class InstrumentationNodeModuleFile<T>
Expand Down

This file was deleted.

44 changes: 44 additions & 0 deletions experimental/packages/opentelemetry-instrumentation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,47 @@ export interface ShimWrapped extends Function {
// eslint-disable-next-line @typescript-eslint/ban-types
__original: Function;
}

export interface InstrumentationModuleFile<T> {
/** Name of file to be patched with relative path */
name: string;

moduleExports?: T;

/** Supported version this file */
supportedVersions: string[];

/** Method to patch the instrumentation */
patch(moduleExports: T, moduleVersion?: string): T;

/** Method to patch the instrumentation */

/** Method to unpatch the instrumentation */
unpatch(moduleExports?: T, moduleVersion?: string): void;
}

export interface InstrumentationModuleDefinition<T> {
/** Module name or path */
name: string;

moduleExports?: T;

/** Instrumented module version */
moduleVersion?: string;

/** Supported version of module */
supportedVersions: string[];

/** Module internal files to be patched */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
files: InstrumentationModuleFile<any>[];

/** If set to true, the includePrerelease check will be included when calling semver.satisfies */
includePrerelease?: boolean;

/** Method to patch the instrumentation */
patch?: (moduleExports: T, moduleVersion?: string) => T;

/** Method to unpatch the instrumentation */
unpatch?: (moduleExports: T, moduleVersion?: string) => void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as path from 'path';
import {
InstrumentationBase,
InstrumentationModuleDefinition,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
} from '../../src';
import { InstrumentationBase } from '../../src';
import { InstrumentationNodeModuleDefinition } from '../../src/instrumentationNodeModuleDefinition';
import { InstrumentationNodeModuleFile } from '../../src/platform/node/instrumentationNodeModuleFile';
import { InstrumentationModuleDefinition } from '../../src/types';

const MODULE_NAME = 'test-module';
const MODULE_FILE_NAME = 'test-module-file';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as assert from 'assert';
import { normalize } from 'path';
import { InstrumentationNodeModuleFile } from '../../src';
import { InstrumentationNodeModuleFile } from '../../src/platform/node/instrumentationNodeModuleFile';

describe('InstrumentationNodeModuleFile', () => {
it('should convert path', () => {
Expand Down

0 comments on commit bf30779

Please sign in to comment.