Skip to content
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

feat: mark @rspack/tracing as peer dependency #9008

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
chenjiahan marked this conversation as resolved.
Show resolved Hide resolved
},
"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.

Loading