-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instead of patching the
tracer.js
file to throw on `@opentelemetry/…
…api` imports, delete the `@opentelemetry/api` dependency itself
- Loading branch information
1 parent
e6078b5
commit 13a5f89
Showing
5 changed files
with
41 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@opennextjs/cloudflare": patch | ||
--- | ||
|
||
instead of patching the `tracer.js` file to throw on `@opentelemetry/api` imports, delete the `@opentelemetry/api` dependency itself | ||
|
||
the problem that this addresses is that the `@opentelemetry/api` package is not only imported by the `tracer.js` file | ||
we patch, so just deleting the library itself makes sure that all files requiring it get the same throwing behavior | ||
(besides decreasing the overall worker size) |
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
23 changes: 23 additions & 0 deletions
23
packages/cloudflare/src/cli/build/patches/investigated/delete-open-telemetry-dep.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,23 @@ | ||
import { rmSync } from "node:fs"; | ||
import { join } from "node:path"; | ||
|
||
/** | ||
* Given a directory path, it deletes a `node_modules/@opentelemetry` subdirectory if present. | ||
* | ||
* Explanation: | ||
* The standard `@opentelemetry/api` library doesn't work in workerd since there are paths that it can't resolve (without a | ||
* compilation step), fortunately Next.js has a try-catch statement that replaces, when failing, `require('@opentelemetry/api')` | ||
* calls with a precompiled version of the library ('next/dist/compiled/@opentelemetry/api') which does properly in our runtime | ||
* (source code: https://github.com/vercel/next.js/blob/9e8266a7/packages/next/src/server/lib/trace/tracer.ts#L27-L31) | ||
* | ||
* So this function is used to delete the `@opentelemetry` dependency entirely so to guarantee that | ||
* `require('@opentelemetry/api')` fail ensuring that the precompiled version is used | ||
*/ | ||
export async function deleteOpenTelemetryDep(path: string): Promise<void> { | ||
const nodeModulesDirPath = join(path, "node_modules"); | ||
|
||
rmSync(join(nodeModulesDirPath, "@opentelemetry"), { | ||
recursive: true, | ||
force: true, | ||
}); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/cloudflare/src/cli/build/patches/investigated/index.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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from "./copy-package-cli-files.js"; | ||
export * from "./delete-open-telemetry-dep.js"; | ||
export * from "./patch-cache.js"; | ||
export * from "./patch-require.js"; | ||
export * from "./update-webpack-chunks-file/index.js"; |
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
13a5f89
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.
@dario-piotrowicz, Is this dev branch for this issue something possible to use at the moment. Would need to find a solution for our project which is standing still at the moment. Have an package depending on opentelemetry 1.9.0 and our "solution" at the moment has been to delete the dependencies from the lockfile. Does this commit handle it better you think?