Skip to content

Commit

Permalink
fix: Update import-in-the-middle (#4806)
Browse files Browse the repository at this point in the history
* fix: Update `import-in-the-middle`

* add changelog entry

* linting is important
  • Loading branch information
timfish authored Jun 19, 2024
1 parent 3cbc9c7 commit c07aa53
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
3 changes: 2 additions & 1 deletion experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to experimental packages in this project will be documented
### :bug: (Bug Fix)

* fix(sdk-node): register context manager if no tracer options are provided [#4781](https://github.com/open-telemetry/opentelemetry-js/pull/4781) @pichlermarc
* fix(instrumentation): Update `import-in-the-middle` to fix [numerous bugs](https://github.com/DataDog/import-in-the-middle/releases/tag/v1.8.1) [#4806](https://github.com/open-telemetry/opentelemetry-js/pull/4806) @timfish

### :books: (Refine Doc)

Expand Down Expand Up @@ -61,7 +62,7 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(instrumentation): Update `import-in-the-middle` to fix [numerous bugs](https://github.com/DataDog/import-in-the-middle/pull/91) [#4745](https://github.com/open-telemetry/opentelemetry-js/pull/4745) @timfish
* fix(instrumentation): Update `import-in-the-middle` to fix [numerous bugs](https://github.com/DataDog/import-in-the-middle/releases/tag/v1.8.0) [#4745](https://github.com/open-telemetry/opentelemetry-js/pull/4745) @timfish

### :books: (Refine Doc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"dependencies": {
"@opentelemetry/api-logs": "0.52.0",
"@types/shimmer": "^1.0.2",
"import-in-the-middle": "1.8.0",
"import-in-the-middle": "1.8.1",
"require-in-the-middle": "^7.1.1",
"semver": "^7.5.2",
"shimmer": "^1.2.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import {
Hooked,
} from './RequireInTheMiddleSingleton';
import type { HookFn } from 'import-in-the-middle';
import * as ImportInTheMiddle from 'import-in-the-middle';
import { Hook as HookImport } from 'import-in-the-middle';
import {
InstrumentationConfig,
InstrumentationModuleDefinition,
} from '../../types';
import { diag } from '@opentelemetry/api';
import type { OnRequireFn } from 'require-in-the-middle';
import { Hook } from 'require-in-the-middle';
import { Hook as HookRequire } from 'require-in-the-middle';
import { readFileSync } from 'fs';
import { isWrapped } from '../../utils';

Expand All @@ -46,7 +46,7 @@ export abstract class InstrumentationBase<
implements types.Instrumentation<ConfigType>
{
private _modules: InstrumentationModuleDefinition[];
private _hooks: (Hooked | Hook)[] = [];
private _hooks: (Hooked | HookRequire)[] = [];
private _requireInTheMiddleSingleton: RequireInTheMiddleSingleton =
RequireInTheMiddleSingleton.getInstance();
private _enabled = false;
Expand Down Expand Up @@ -305,15 +305,15 @@ export abstract class InstrumentationBase<
// For an absolute paths, we must create a separate instance of the
// require-in-the-middle `Hook`.
const hook = path.isAbsolute(module.name)
? new Hook([module.name], { internals: true }, onRequire)
? new HookRequire([module.name], { internals: true }, onRequire)
: this._requireInTheMiddleSingleton.register(module.name, onRequire);

this._hooks.push(hook);
const esmHook = new (
ImportInTheMiddle as unknown as {
Hook: typeof ImportInTheMiddle.default;
}
).Hook([module.name], { internals: false }, <HookFn>hookFn);
const esmHook = new HookImport(
[module.name],
{ internals: false },
<HookFn>hookFn
);
this._hooks.push(esmHook);
}
}
Expand Down
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c07aa53

Please sign in to comment.