Skip to content

Commit 0c268e1

Browse files
authored
chore: add instrument tracing (#118)
1 parent cda05bc commit 0c268e1

File tree

7 files changed

+29
-1
lines changed

7 files changed

+29
-1
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ jobs:
5151
- name: Build cache by Cargo Check and Cargo Test
5252
if: ${{ github.ref_name == 'main' }}
5353
run: cargo test --all-features --no-run
54+
env:
55+
RUST_MIN_STACK: 8388608
5456
- name: Prettier Check
5557
if: ${{ matrix.os != 'windows-latest' }}
5658
run: |
@@ -201,6 +203,8 @@ jobs:
201203
cache-key: warm
202204
- run: cargo test --doc
203205
- run: cargo test --all-features
206+
env:
207+
RUST_MIN_STACK: 8388608
204208
- name: Test Node Bindings
205209
run: |
206210
npm run build:binding:debug

.github/workflows/codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
components: llvm-tools-preview
3535

3636
- run: cargo llvm-cov --lcov --output-path lcov.info
37+
env:
38+
RUST_MIN_STACK: 8388608
3739

3840
- name: Upload Artifact
3941
uses: actions/upload-artifact@v4

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ package_json_raw_json_api = []
114114
## [Yarn Plug'n'Play](https://yarnpkg.com/features/pnp)
115115
yarn_pnp = ["pnp"]
116116
# For codspeed benchmark
117-
codspeed = ["criterion2/codspeed"]
117+
codspeed = ["criterion2/codspeed" ]
118+
# For remove tracing calls in release build
119+
enable_instrument=[]
118120

119121
[package.metadata.docs.rs]
120122
all-features = true

src/cache.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ impl CachedPathImpl {
268268
/// # Errors
269269
///
270270
/// * [ResolveError::JSON]
271+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %self.path.display())))]
271272
pub async fn find_package_json<Fs: FileSystem + Send + Sync>(
272273
&self,
273274
fs: &Fs,
@@ -298,6 +299,7 @@ impl CachedPathImpl {
298299
/// # Errors
299300
///
300301
/// * [ResolveError::JSON]
302+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %self.path.display())))]
301303
pub async fn package_json<Fs: FileSystem + Send + Sync>(
302304
&self,
303305
fs: &Fs,

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
234234
}
235235

236236
/// Wrap `resolve_impl` with `tracing` information
237+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %directory.to_string_lossy(), specifier = specifier)))]
237238
async fn resolve_tracing(
238239
&self,
239240
directory: &Path,
@@ -430,6 +431,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
430431
}
431432

432433
// 3. If X begins with './' or '/' or '../'
434+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = specifier, path = %cached_path.path().to_string_lossy())))]
433435
async fn require_relative(
434436
&self,
435437
cached_path: &CachedPath,
@@ -477,6 +479,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
477479
.await
478480
}
479481

482+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = specifier)))]
480483
async fn require_bare(
481484
&self,
482485
cached_path: &CachedPath,
@@ -528,6 +531,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
528531
Ok((parsed, None))
529532
}
530533

534+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = specifier, path = %cached_path.path().to_string_lossy())))]
531535
async fn load_package_self_or_node_modules(
532536
&self,
533537
cached_path: &CachedPath,
@@ -577,6 +581,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
577581
Ok(None)
578582
}
579583

584+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %cached_path.path().to_string_lossy())))]
580585
async fn load_as_file(&self, cached_path: &CachedPath, ctx: &mut Ctx) -> ResolveResult {
581586
// enhanced-resolve feature: extension_alias
582587
if let Some(path) = self.load_extension_alias(cached_path, ctx).await? {
@@ -639,6 +644,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
639644
self.load_index(cached_path, ctx).await
640645
}
641646

647+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = specifier, path = %cached_path.path().to_string_lossy())))]
642648
async fn load_as_file_or_directory(
643649
&self,
644650
cached_path: &CachedPath,
@@ -666,6 +672,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
666672
Ok(None)
667673
}
668674

675+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %path.path().to_string_lossy())))]
669676
async fn load_extensions(
670677
&self,
671678
path: &CachedPath,
@@ -688,6 +695,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
688695
Ok(None)
689696
}
690697

698+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %cached_path.path().to_string_lossy())))]
691699
async fn load_realpath(
692700
&self,
693701
cached_path: &CachedPath,
@@ -737,6 +745,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
737745
true
738746
}
739747

748+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %cached_path.path().to_string_lossy())))]
740749
async fn load_index(&self, cached_path: &CachedPath, ctx: &mut Ctx) -> ResolveResult {
741750
for main_file in &self.options.main_files {
742751
let main_path = cached_path.path().normalize_with(main_file);
@@ -790,6 +799,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
790799
Ok(None)
791800
}
792801

802+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = specifier, path = %cached_path.path().to_string_lossy())))]
793803
async fn load_node_modules(
794804
&self,
795805
cached_path: &CachedPath,
@@ -871,6 +881,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
871881
}
872882

873883
#[cfg(feature = "yarn_pnp")]
884+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %cached_path.path().to_string_lossy())))]
874885
fn find_pnp_manifest(
875886
&self,
876887
cached_path: &CachedPath,
@@ -897,6 +908,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
897908
}
898909

899910
#[cfg(feature = "yarn_pnp")]
911+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = specifier, path = %cached_path.path().to_string_lossy())))]
900912
async fn load_pnp(
901913
&self,
902914
cached_path: &CachedPath,
@@ -1000,6 +1012,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
10001012
Ok(None)
10011013
}
10021014

1015+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = specifier, path = %cached_path.path().to_string_lossy())))]
10031016
async fn load_package_self(
10041017
&self,
10051018
cached_path: &CachedPath,
@@ -1043,6 +1056,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
10431056
}
10441057

10451058
/// RESOLVE_ESM_MATCH(MATCH)
1059+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = specifier, path = %cached_path.path().to_string_lossy())))]
10461060
async fn resolve_esm_match(
10471061
&self,
10481062
specifier: &str,
@@ -1082,6 +1096,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
10821096
}
10831097

10841098
/// enhanced-resolve: AliasFieldPlugin for [ResolveOptions::alias_fields]
1099+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(specifier = module_specifier, path = %cached_path.path().to_string_lossy())))]
10851100
async fn load_browser_field(
10861101
&self,
10871102
cached_path: &CachedPath,
@@ -1346,6 +1361,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
13461361
Ok(None)
13471362
}
13481363

1364+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip(self), fields(path = path.display().to_string())))]
13491365
fn load_tsconfig<'a>(
13501366
&'a self,
13511367
root: bool,

src/package_json.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct PackageJson {
4040
impl PackageJson {
4141
/// # Panics
4242
/// # Errors
43+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, name="pkgjson_parse", skip_all, fields(path = %realpath.display())))]
4344
pub(crate) fn parse(
4445
path: PathBuf,
4546
realpath: PathBuf,

src/tsconfig.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub struct ProjectReference {
7575
}
7676

7777
impl TsConfig {
78+
#[cfg_attr(feature="enable_instrument", tracing::instrument(level=tracing::Level::DEBUG, skip_all, fields(path = %path.to_string_lossy())))]
7879
pub fn parse(root: bool, path: &Path, json: &mut str) -> Result<Self, serde_json::Error> {
7980
_ = json_strip_comments::strip(json);
8081
if json.trim().is_empty() {

0 commit comments

Comments
 (0)