Skip to content

[instrumentation] hide shimmer types from the public API #4837

@pichlermarc

Description

@pichlermarc

Description:

@types/shimmer is currently part of the @opentelemetry/instrumentation package's public API. We should avoid having a third-party dependency be part of the public API of this package as breaking changes will affect the public interface of @opentelemetry/instrumentation

A solution to this can be changing InstrumentationAbstract#_wrap, InstrumentationAbstract#_unwrap, InstrumentationAbstract#massUnwrap, InstrumentationAbstract#massWrap to be custom functions that wrap shimmer functions and for which we fully control the types.

This issue is considered done when:

  • shimmer, @types/shimmer exports are hidden in a way so that they are not part of the public API anymore
  • @types/shimmer is moved to devDependenices or removed completely

Additional Details

Code sections of interest:

  • /* Api to wrap instrumented method */
    protected _wrap = shimmer.wrap;
    /* Api to unwrap instrumented methods */
    protected _unwrap = shimmer.unwrap;
    /* Api to mass wrap instrumented method */
    protected _massWrap = shimmer.massWrap;
    /* Api to mass unwrap instrumented methods */
    protected _massUnwrap = shimmer.massUnwrap;
  • protected override _wrap: typeof wrap = (moduleExports, name, wrapper) => {
    if (isWrapped(moduleExports[name])) {
    this._unwrap(moduleExports, name);
    }
    if (!utilTypes.isProxy(moduleExports)) {
    return wrap(moduleExports, name, wrapper);
    } else {
    const wrapped = wrap(Object.assign({}, moduleExports), name, wrapper);
    return Object.defineProperty(moduleExports, name, {
    value: wrapped,
    });
    }
    };
    protected override _unwrap: typeof unwrap = (moduleExports, name) => {
    if (!utilTypes.isProxy(moduleExports)) {
    return unwrap(moduleExports, name);
    } else {
    return Object.defineProperty(moduleExports, name, {
    value: moduleExports[name],
    });
    }
    };
    protected override _massWrap: typeof massWrap = (
    moduleExportsArray,
    names,
    wrapper
    ) => {
    if (!moduleExportsArray) {
    diag.error('must provide one or more modules to patch');
    return;
    } else if (!Array.isArray(moduleExportsArray)) {
    moduleExportsArray = [moduleExportsArray];
    }
    if (!(names && Array.isArray(names))) {
    diag.error('must provide one or more functions to wrap on modules');
    return;
    }
    moduleExportsArray.forEach(moduleExports => {
    names.forEach(name => {
    this._wrap(moduleExports, name, wrapper);
    });
    });
    };
    protected override _massUnwrap: typeof massUnwrap = (
    moduleExportsArray,
    names
    ) => {
    if (!moduleExportsArray) {
    diag.error('must provide one or more modules to patch');
    return;
    } else if (!Array.isArray(moduleExportsArray)) {
    moduleExportsArray = [moduleExportsArray];
    }
    if (!(names && Array.isArray(names))) {
    diag.error('must provide one or more functions to wrap on modules');
    return;
    }
    moduleExportsArray.forEach(moduleExports => {
    names.forEach(name => {
    this._unwrap(moduleExports, name);
    });
    });
    };

This issue is part of #4586

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions