-
Notifications
You must be signed in to change notification settings - Fork 515
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
chore: upstream mocha instrumentation testing plugin from ext-js #621
Conversation
Codecov Report
@@ Coverage Diff @@
## main #621 +/- ##
==========================================
- Coverage 96.68% 95.06% -1.63%
==========================================
Files 13 71 +58
Lines 634 5042 +4408
Branches 124 490 +366
==========================================
+ Hits 613 4793 +4180
- Misses 21 249 +228
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, just one concern towards the name for registerInstrumentation, other than that lgtm
packages/opentelemetry-test-utils/src/instrumentations/instrumentation-singelton.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Bartlomiej Obecny <[email protected]>
Fixed |
Did you mean to apply it to the mongodb instrumentation or was that just a test? |
I did, to demonstrate how to use it. |
Yes it's fine, just wanted to make sure it was intended |
Looks like node 16 is failing. Any idea why that's happening? |
After merging with the lerna hoisting PR, now mocha is hoisted to the root node_modules, but it depends on the Adding |
What's strange that this seems to be an issue with lerna hoisted modules, but it only fails with Node 16. Do we know why that is? Also, regarding the fix for adding mocha to the Alternatively, is there any way we could force the test-utils package to be hoisted? Perhaps adding it as a devDependency to the root package.json so it's always included with those root-level dependencies? |
Not actually. Tried to run it locally on node 14 and it also failed locally, so the mystery is even greater :/
Good question, I don't have the number on CI time, but in term of size, mocha is using 300 MB of node_modules out of the 1GB for non-hoisting setup, and hoisting reduced about 10 minutes from the CI time, so guess it will add about 30% of that back, about 3 minutes per run. If I don't find any other solution, we can consider that.
That's a great idea. On ext-js repo, we use lerna with yarn workspaces which hoist the intra-repo dependency to the root node_modules automatically as you suggested. |
Fixed the issues, now tests are green. If there are no additional comments after changes, this one is ready to get merged finally :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Ready to merge whenever possible @obecny @vmarchaud @dyladan
This reverts commit 7800e99.
This reverts commit 7800e99.
…mamir) #621 (#670) Co-Authored-By: Amir Blum [email protected]
Read more about it here.
Basically, it's a mocha plugin that implements many of the repeated boilerplate code needed for instrumentation testing, in a consistent, idiomatic fashion.
It makes writing instrumentation tests an easier task, with less code, and less room for doing things wrong, by ensuring that there is only a single instance of the instrumentation under test, and cleaning state between tests runs.
This PR is the first step for upstreaming Aspecto's opensource instrumentations from ext-js repo to the contrib. I upstream it first in order to create smaller, more reviewable PRs, with less changes in each.
The next step will be to upstream the
aws-sdk
instrumentation which relies on this mocha plugin for it's unit testsWhich problem is this PR solving?
For one
.spec
file this is relatively easy, but when instrumentation has multiple.spec.ts
files, each file has to set these up again and again, and due to the way mocha runs test files, it's very easy to mess it up and cause spans to be written to the wrong memory exporter, update the wrong instrumentation instance, use provider from other file etc.This PR is a suggestion for mocha plugin and documented workflow which aims to solve many of these issues by using singleton instances of these components, similar to how the SDK is expected to be setup and run in an instrumented application.
Short description of the changes
@opentelemetry/test-utils
from root tosrc
directory and adjustpackage.json
andtsconfig.json
accordingly, so the structure matches the rest of the packages in the repotest-utils
package which can be used in instrumentation tests, along with documentation on how to use in the package README.