Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"dependencies": {
"@opentelemetry/api-logs": "0.210.0",
"import-in-the-middle": "^2.0.0",
"import-in-the-middle": "^2.0.1",
"require-in-the-middle": "^8.0.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ export abstract class InstrumentationBase<
}
return exports;
}
// internal file
// internal file or submodule export
const files = module.files ?? [];
const normalizedName = path.normalize(name);
const normalizedModuleName = path.normalize(module.name);
const supportedFileInstrumentations = files.filter(
f =>
f.name === normalizedName &&
(f.name === normalizedName || f.name === normalizedModuleName) &&
isSupported(f.supportedVersions, version, module.includePrerelease)
);
return supportedFileInstrumentations.reduce<T>((patchedExports, file) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as assert from 'assert';

import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
} from '../../build/src/index.js';

class TestInstrumentationSimple extends InstrumentationBase {
constructor(config) {
super('test-esm-submodule-exports', '0.0.1', config);
}
init() {
return [
new InstrumentationNodeModuleDefinition(
'@opentelemetry/esm-submodule-exports',
['*'],
moduleExports => {
moduleExports.propertyOnMainModule = 'modified string in main module';
return moduleExports;
},
moduleExports => {
return moduleExports;
},
[
new InstrumentationNodeModuleFile(
'@opentelemetry/esm-submodule-exports/src/index.js',
['*'],
moduleExports => {
moduleExports.propertyOnMainModule = 'modified string in main module';
return moduleExports;

},
moduleExports => {
return moduleExports;
}
),
]
),
new InstrumentationNodeModuleDefinition(
'@opentelemetry/esm-submodule-exports/sub',
['*'],
moduleExports => {
moduleExports.propertyOnSubModule = 'modified string in sub module';
return moduleExports;
},
moduleExports => {
return moduleExports;
},
[
new InstrumentationNodeModuleFile(
'@opentelemetry/esm-submodule-exports/sub',
['*'],
moduleExports => {
moduleExports.propertyOnSubModule = 'modified string in sub module';
return moduleExports;
},
moduleExports => {
return moduleExports;
}
),
]
)
];
}
}

describe('instrumenting an esm scoped submodule package', function () {
it('should patch main module', async function () {
const instrumentation = new TestInstrumentationSimple({
enabled: false,
});
instrumentation.enable();

const {
propertyOnMainModule,
} = await import('@opentelemetry/esm-submodule-exports');

assert.strictEqual(propertyOnMainModule, 'modified string in main module');
});

it('should patch sub module', async function () {
const instrumentation = new TestInstrumentationSimple({
enabled: false,
});
instrumentation.enable();

const {
propertyOnSubModule,
} = await import('@opentelemetry/esm-submodule-exports/sub');

assert.strictEqual(propertyOnSubModule, 'modified string in sub module');
});
});

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

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

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

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

2 changes: 1 addition & 1 deletion package-lock.json

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