-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[core-tracing] support sharing state between CJS and ESM #28631
Conversation
This is where I landed, would love any feedback. I will be looking at tests and working through any tracing test failures |
API change check API changes are not detected in this pull request. |
f8860fa
to
269871d
Compare
/azp run js - monitor-query - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
@@ -13,6 +14,9 @@ export default defineConfig({ | |||
toFake: ["setTimeout", "Date"], | |||
}, | |||
watch: false, | |||
alias: { | |||
"../commonjs/state.js": resolve("./src/state-cjs.cts"), |
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.
Not quite scalable IMO but I will be exploring alternatives in a follow-up PR
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 think that's fine for now since Node.js is really the only place it applies.
### Packages impacted by this PR @azure/core-client ### Issues associated with this PR N/A, follow up on #28631 ### Describe the problem that is addressed by this PR If you are exporting both CommonJS and ESM forms of a package, then it is possible for both versions to be loaded at run-time. However, the CommonJS build is a different module from the ESM build, and thus a different thing from the point of view of the JavaScript interpreter in Node.js. https://github.com/isaacs/tshy/blob/main/README.md#dual-package-hazards tshy handles this by building programs into separate folders and treats "dual module hazards" as a fact of life. One of the hazards of dual-modules is shared module-global state. In core-clientwe have a module-global operationRequestMap that is used for deserializing. In order to ensure it works in this dual-package world we must use one of multiple-recommended workarounds. In this case, the tshy documentation provides a solution to this with a well-documented path forward. This is what is implemented here. Please refer to https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for added context ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? The obvious alternative is to just not do anything since tests have not been failing; however, that seems risky. While _this_ particular issue has not come up in tests, a similar one came up for core-tracing. I am open to just _not_ doing anything of course - I love not adding code so just give me a reason!
### Packages impacted by this PR @azure/core-tracing ### Issues associated with this PR Resolves Azure#28619 ### Describe the problem that is addressed by this PR If you are exporting both CommonJS and ESM forms of a package, then it is possible for both versions to be loaded at run-time. However, the CommonJS build is a different module from the ESM build, and thus a different thing from the point of view of the JavaScript interpreter in Node.js. > https://github.com/isaacs/tshy/blob/main/README.md#dual-package-hazards tshy handles this by building programs into separate folders and treats "dual module hazards" as a fact of life. One of the hazards of dual-modules is shared module-global state. In core-tracing we have a module-global instrumenter that is used for hooking into and lighting up OpenTelemetry based instrumentation. In order to ensure it works in this dual-package world we must use one of multiple-recommended workarounds. In this case, the tshy documentation provides a solution to this with a well-documented path forward. This is what is implemented here. Please refer to https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for added context
Packages impacted by this PR
@azure/core-tracing
Issues associated with this PR
Resolves #28619
Describe the problem that is addressed by this PR
If you are exporting both CommonJS and ESM forms of a package, then it is possible for both versions to be loaded at run-time.
However, the CommonJS build is a different module from the ESM build, and thus a different thing from the point of view of the
JavaScript interpreter in Node.js.
tshy handles this by building programs into separate folders and treats "dual
module hazards" as a fact of life.
One of the hazards of dual-modules is shared module-global state.
In core-tracing we have a module-global instrumenter that is used for hooking
into and lighting up OpenTelemetry based instrumentation. In order to ensure it
works in this dual-package world we must use one of multiple-recommended
workarounds.
In this case, the tshy documentation provides a solution to this with a
well-documented path forward. This is what is implemented here.
Please refer to
https://github.com/isaacs/tshy/blob/main/README.md#module-local-state for added
//context.
What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?
Alternatively, I considered migrating test-utils to ESM and seeing if that
resolves the issue; however, I do believe that our tests are trying to tell us
something here and that we should resolve the issue so that customers who are
using OTel may not be impacted.
Are there test cases added in this PR? (If not, why?)
Honestly? Wasn't sure how to test this... tshy build breaks when you do things
incorrectly and provides some validation.
Provide a list of related PRs (if any)
Command used to generate this PR: (Applicable only to SDK release request PRs)
Checklists