-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into next-main-2024-02-23
- Loading branch information
Showing
15 changed files
with
24,604 additions
and
15,073 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...try-instrumentation/test/node/node_modules/@opentelemetry/scoped-test-module/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...try-instrumentation/test/node/node_modules/@opentelemetry/scoped-test-module/src/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...-instrumentation/test/node/node_modules/@opentelemetry/scoped-test-module/src/internal.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
...l/packages/opentelemetry-instrumentation/test/node/scoped-package-instrumentation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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, | ||
InstrumentationConfig, | ||
InstrumentationNodeModuleDefinition, | ||
InstrumentationNodeModuleFile, | ||
} from '../../src'; | ||
|
||
class TestInstrumentationSimple extends InstrumentationBase { | ||
constructor(config: InstrumentationConfig) { | ||
super('test-scoped-package-instrumentation', '0.0.1', config); | ||
} | ||
init() { | ||
return new InstrumentationNodeModuleDefinition( | ||
'@opentelemetry/scoped-test-module', | ||
['*'], | ||
moduleExports => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
moduleExports.propertyOnMainModule = 'modified string in main module'; | ||
return moduleExports; | ||
}, | ||
moduleExports => { | ||
return moduleExports; | ||
}, | ||
[ | ||
new InstrumentationNodeModuleFile( | ||
'@opentelemetry/scoped-test-module/src/internal.js', | ||
['*'], | ||
moduleExports => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore no types | ||
moduleExports.testString = 'modified internal string'; | ||
return moduleExports; | ||
}, | ||
moduleExports => { | ||
return moduleExports; | ||
} | ||
), | ||
] | ||
); | ||
} | ||
} | ||
|
||
describe('instrumenting a scoped package', function () { | ||
/** | ||
* On Windows, instrumentation would fail on internal files of scoped packages. | ||
* The reason: the path would include a '/' separator in the package name: | ||
* - actual: @opentelemetry/scoped-test-module\src\internal.js | ||
* - expected: @opentelemetry\scoped-test-module\src\internal.js | ||
* This resulted in internal files of scoped packages not being instrumented. | ||
* | ||
* See https://github.com/open-telemetry/opentelemetry-js/issues/4436 | ||
*/ | ||
it('should patch internal file and main module', function () { | ||
const instrumentation = new TestInstrumentationSimple({ | ||
enabled: false, | ||
}); | ||
instrumentation.enable(); | ||
|
||
const { getString } = require('@opentelemetry/scoped-test-module'); | ||
|
||
assert.strictEqual(getString(), 'from index.js: modified internal string'); | ||
}); | ||
|
||
/** | ||
* Normalizing everything passed to onRequire() from RequireInTheMiddleSingleton would cause main modules from a | ||
* scoped package not to be instrumented. | ||
* The reason: we'd check: | ||
* '@opentelemetry\scoped-test-module' === '@opentelemetry/scoped-test-module' | ||
* | ||
* then determine that since this evaluates to false, this is not the main module, and we'd never instrument it. | ||
* | ||
* Therefore, the fix to the above test (internal files) is not to normalize everything passed to onRequire() | ||
*/ | ||
it('should patch main module', function () { | ||
const instrumentation = new TestInstrumentationSimple({ | ||
enabled: false, | ||
}); | ||
instrumentation.enable(); | ||
|
||
const { | ||
propertyOnMainModule, | ||
} = require('@opentelemetry/scoped-test-module'); | ||
|
||
assert.strictEqual(propertyOnMainModule, 'modified string in main module'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.