Skip to content

Commit

Permalink
feat: mark @rspack/tracing as peer dependency (#9008)
Browse files Browse the repository at this point in the history
* feat: mark `@rspack/tracing` as peer dependency

* Update packages/rspack/src/exports.ts

Co-authored-by: neverland <[email protected]>

* chore: update

---------

Co-authored-by: neverland <[email protected]>
  • Loading branch information
h-a-n-a and chenjiahan authored Jan 14, 2025
1 parent 4b50686 commit ded9fc0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
10 changes: 8 additions & 2 deletions packages/rspack-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"dependencies": {
"@discoveryjs/json-ext": "^0.5.7",
"@rspack/dev-server": "1.0.10",
"@rspack/tracing": "workspace:*",
"colorette": "2.0.19",
"exit-hook": "^4.0.0",
"interpret": "^3.1.1",
Expand All @@ -46,6 +45,7 @@
"devDependencies": {
"@rslib/core": "0.2.2",
"@rspack/core": "workspace:*",
"@rspack/tracing": "workspace:*",
"@types/interpret": "^1.1.3",
"@types/rechoir": "^0.6.1",
"@types/webpack-bundle-analyzer": "^4.6.0",
Expand All @@ -57,7 +57,13 @@
"typescript": "^5.7.2"
},
"peerDependencies": {
"@rspack/core": "^1.0.0-alpha || ^1.x"
"@rspack/core": "^1.0.0-alpha || ^1.x",
"@rspack/tracing": "^1.x"
},
"peerDependenciesMeta": {
"@rspack/tracing": {
"optional": true
}
},
"publishConfig": {
"access": "public",
Expand Down
7 changes: 5 additions & 2 deletions packages/rspack-tracing/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@rspack/tracing",
"version": "1.0.12",
"private": true,
"version": "1.2.0-beta.0",
"type": "module",
"description": "Internal tracing package for rspack",
"homepage": "https://rspack.dev",
Expand All @@ -11,6 +10,10 @@
"url": "https://github.com/web-infra-dev/rspack",
"directory": "packages/rspack-tracing"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"license": "MIT",
"main": "./index.js",
"types": "./index.d.ts",
Expand Down
10 changes: 7 additions & 3 deletions packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,25 @@
"webpack-dev-server": "5.0.4",
"webpack-sources": "3.2.3",
"zod": "^3.23.8",
"zod-validation-error": "3.4.0"
"zod-validation-error": "3.4.0",
"@rspack/tracing": "workspace:*"
},
"dependencies": {
"@module-federation/runtime-tools": "0.8.4",
"@rspack/binding": "workspace:*",
"@rspack/tracing": "workspace:*",
"@rspack/lite-tapable": "1.0.1",
"caniuse-lite": "^1.0.30001616"
},
"peerDependencies": {
"@swc/helpers": ">=0.5.1"
"@swc/helpers": ">=0.5.1",
"@rspack/tracing": "^1.x"
},
"peerDependenciesMeta": {
"@swc/helpers": {
"optional": true
},
"@rspack/tracing": {
"optional": true
}
}
}
19 changes: 15 additions & 4 deletions packages/rspack/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,25 @@ export const experiments: Experiments = {
async register(filter, layer, output) {
registerGlobalTrace(filter, layer, output);
if (layer === "otel") {
const { initOpenTelemetry } = await import("@rspack/tracing");
await initOpenTelemetry();
try {
const { initOpenTelemetry } = await import("@rspack/tracing");
await initOpenTelemetry();
} catch (error) {
console.error(
"Failed to import `@rspack/tracing` package. Please install `@rspack/tracing` to enable OpenTelemetry tracing.",
error
);
}
}
},
async cleanup() {
cleanupGlobalTrace();
const { shutdownOpenTelemetry } = await import("@rspack/tracing");
await shutdownOpenTelemetry();
try {
const { shutdownOpenTelemetry } = await import("@rspack/tracing");
await shutdownOpenTelemetry();
} catch (error) {
// ignore cleanup tracing error
}
}
},
RemoveDuplicateModulesPlugin
Expand Down
37 changes: 23 additions & 14 deletions packages/rspack/src/loader-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,29 @@ function getCurrentLoader(
return null;
}

async function tryTrace(context: JsLoaderContext) {
try {
const {
trace,
propagation,
context: tracingContext
} = await import("@rspack/tracing");
const tracer = trace.getTracer("rspack-loader-runner");
const activeContext = propagation.extract(
tracingContext.active(),
context.__internal__tracingCarrier
);
return { tracer, activeContext };
} catch (error) {
return { tracer: null, activeContext: null };
}
}

export async function runLoaders(
compiler: Compiler,
context: JsLoaderContext
): Promise<JsLoaderContext> {
const {
trace,
propagation,
context: tracingContext
} = await import("@rspack/tracing");
const tracer = trace.getTracer("rspack-loader-runner");
const activeContext = propagation.extract(
tracingContext.active(),
context.__internal__tracingCarrier
);
const { tracer, activeContext } = await tryTrace(context);

const loaderState = context.loaderState;

Expand Down Expand Up @@ -822,7 +831,7 @@ export async function runLoaders(
currentLoaderObject.pitchExecuted = true;
if (!fn) continue;

const span = tracer.startSpan(
const span = tracer?.startSpan(
"LoaderRunner:pitch",
{
attributes: {
Expand All @@ -837,7 +846,7 @@ export async function runLoaders(
loaderContext.previousRequest,
currentLoaderObject.data
])) || [];
span.end();
span?.end();

const hasArg = args.some(value => value !== undefined);

Expand Down Expand Up @@ -874,7 +883,7 @@ export async function runLoaders(
const args = [content, sourceMap, additionalData];
convertArgs(args, !!currentLoaderObject.raw);

const span = tracer.startSpan(
const span = tracer?.startSpan(
"LoaderRunner:normal",
{
attributes: {
Expand All @@ -885,7 +894,7 @@ export async function runLoaders(
);
[content, sourceMap, additionalData] =
(await runSyncOrAsync(fn, loaderContext, args)) || [];
span.end();
span?.end();
}

context.content = isNil(content) ? null : toBuffer(content);
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

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

2 comments on commit ded9fc0

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on ded9fc0 Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ecosystem CI detail: Open

suite result
modernjs ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
rsdoctor ✅ success
examples ✅ success
devserver ✅ success
nuxt ✅ success

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on ded9fc0 Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2025-01-14 737e028) Current Change
10000_big_production-mode_disable-minimize + exec 37.5 s ± 781 ms 38.6 s ± 323 ms +2.91 %
10000_development-mode + exec 1.85 s ± 87 ms 1.88 s ± 147 ms +1.73 %
10000_development-mode_hmr + exec 686 ms ± 22 ms 688 ms ± 39 ms +0.26 %
10000_production-mode + exec 2.48 s ± 210 ms 2.41 s ± 150 ms -2.71 %
10000_production-mode_persistent-cold + exec 2.59 s ± 65 ms 2.55 s ± 77 ms -1.35 %
10000_production-mode_persistent-hot + exec 2.07 s ± 191 ms 1.95 s ± 21 ms -5.59 %
arco-pro_development-mode + exec 1.8 s ± 92 ms 1.72 s ± 51 ms -4.56 %
arco-pro_development-mode_hmr + exec 388 ms ± 4.8 ms 387 ms ± 4.5 ms -0.30 %
arco-pro_production-mode + exec 3.74 s ± 178 ms 3.7 s ± 116 ms -1.03 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.75 s ± 127 ms 3.7 s ± 145 ms -1.32 %
arco-pro_production-mode_persistent-cold + exec 3.95 s ± 159 ms 3.85 s ± 148 ms -2.46 %
arco-pro_production-mode_persistent-hot + exec 2.63 s ± 176 ms 2.67 s ± 98 ms +1.26 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.78 s ± 126 ms 3.68 s ± 246 ms -2.71 %
large-dyn-imports_development-mode + exec 2.12 s ± 118 ms 2.13 s ± 144 ms +0.52 %
large-dyn-imports_production-mode + exec 2.18 s ± 65 ms 2.15 s ± 28 ms -1.27 %
threejs_development-mode_10x + exec 1.63 s ± 20 ms 1.62 s ± 25 ms -0.64 %
threejs_development-mode_10x_hmr + exec 788 ms ± 18 ms 774 ms ± 24 ms -1.77 %
threejs_production-mode_10x + exec 5.49 s ± 147 ms 5.45 s ± 65 ms -0.68 %
threejs_production-mode_10x_persistent-cold + exec 5.59 s ± 112 ms 5.52 s ± 95 ms -1.27 %
threejs_production-mode_10x_persistent-hot + exec 4.83 s ± 364 ms 4.85 s ± 313 ms +0.32 %
10000_big_production-mode_disable-minimize + rss memory 9516 MiB ± 315 MiB 9544 MiB ± 35.1 MiB +0.29 %
10000_development-mode + rss memory 656 MiB ± 12.3 MiB 684 MiB ± 32.8 MiB +4.34 %
10000_development-mode_hmr + rss memory 1386 MiB ± 275 MiB 1506 MiB ± 132 MiB +8.67 %
10000_production-mode + rss memory 663 MiB ± 45.3 MiB 690 MiB ± 45.3 MiB +4.00 %
10000_production-mode_persistent-cold + rss memory 750 MiB ± 41.6 MiB 808 MiB ± 32.7 MiB +7.73 %
10000_production-mode_persistent-hot + rss memory 740 MiB ± 30.6 MiB 742 MiB ± 22 MiB +0.30 %
arco-pro_development-mode + rss memory 561 MiB ± 55.2 MiB 572 MiB ± 64.6 MiB +1.88 %
arco-pro_development-mode_hmr + rss memory 601 MiB ± 85.9 MiB 626 MiB ± 49.7 MiB +4.04 %
arco-pro_production-mode + rss memory 698 MiB ± 67.6 MiB 746 MiB ± 90.2 MiB +6.76 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 742 MiB ± 57.7 MiB 730 MiB ± 129 MiB -1.62 %
arco-pro_production-mode_persistent-cold + rss memory 824 MiB ± 55.7 MiB 816 MiB ± 57.2 MiB -0.92 %
arco-pro_production-mode_persistent-hot + rss memory 674 MiB ± 60.6 MiB 704 MiB ± 57.3 MiB +4.53 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 743 MiB ± 116 MiB 749 MiB ± 82.4 MiB +0.84 %
large-dyn-imports_development-mode + rss memory 633 MiB ± 2.28 MiB 661 MiB ± 11.6 MiB +4.48 %
large-dyn-imports_production-mode + rss memory 528 MiB ± 3.55 MiB 548 MiB ± 4.17 MiB +3.78 %
threejs_development-mode_10x + rss memory 561 MiB ± 15.2 MiB 577 MiB ± 37.4 MiB +2.77 %
threejs_development-mode_10x_hmr + rss memory 1113 MiB ± 137 MiB 1166 MiB ± 184 MiB +4.78 %
threejs_production-mode_10x + rss memory 861 MiB ± 64.6 MiB 900 MiB ± 68.8 MiB +4.50 %
threejs_production-mode_10x_persistent-cold + rss memory 992 MiB ± 84.4 MiB 997 MiB ± 56.4 MiB +0.50 %
threejs_production-mode_10x_persistent-hot + rss memory 902 MiB ± 61.5 MiB 919 MiB ± 54.7 MiB +1.85 %

Please sign in to comment.