Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
Tracked by #4586
pichlermarc opened this issue Jul 1, 2024 · 0 comments
Open
2 tasks
Tracked by #4586

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

pichlermarc opened this issue Jul 1, 2024 · 0 comments
Labels
needs:code-contribution This feature/bug is ready to implement never-stale pkg:instrumentation type:feature A feature with no sub-issues to address

Comments

@pichlermarc
Copy link
Member

pichlermarc commented Jul 1, 2024

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

@pichlermarc pichlermarc changed the title (TBD) issue to hide shimmer types from the public API [instrumentation] hide shimmer types from the public API Jul 1, 2024
@pichlermarc pichlermarc added pkg:instrumentation type:feature A feature with no sub-issues to address never-stale needs:refinement This issue needs to be refined/broken apart into sub-issues before implementation needs:code-contribution This feature/bug is ready to implement and removed needs:refinement This issue needs to be refined/broken apart into sub-issues before implementation labels Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:code-contribution This feature/bug is ready to implement never-stale pkg:instrumentation type:feature A feature with no sub-issues to address
Projects
None yet
Development

No branches or pull requests

1 participant