Skip to content

Conversation

@logaretm
Copy link

@logaretm logaretm commented Nov 6, 2025

Adds Node.js tracing channels for all storage operations, enabling observability and performance monitoring.

Channel Naming Convention

All channels use the unstorage.${operation} convention which when coupled with tracing channels produce the following diagnostic channels:

  • tracing:unstorage.${operation}:start
  • tracing:unstorage.${operation}:end
  • tracing:unstorage.${operation}:asyncStart
  • tracing:unstorage.${operation}:asyncEnd
  • tracing:unstorage.${operation}:error

Which matches nicely with fastify but there isn't a lot of convention for them other than the Node.js recommendation.

Traced operations

  • Item operations: hasItem, getItem, setItem, setItems, removeItem
  • Raw operations: getItemRaw, setItemRaw
  • Meta operations: getMeta (uses getItem channel with meta: true)
  • Batch operations: getItems, setItems
  • Utility operations: getKeys, clear

Tracing context includes

  • keys[] - keys involved in the operation
  • base - mount point handling the operation
  • driver - driver name and options (single-key operations only)
  • meta - flag for metadata operations

We can probably add more, in the Nuxt unstorage instrumentation we only use those.

Example

import { tracingChannel } from 'node:diagnostics_channel';

const channel = tracingChannel('unstorage.getItem');

channel.subscribe({
  start: (data) => {
    // start timing, or spans or whatever...
  },
  asyncEnd: (data) => {
    console.log(`${data.driver?.name} fetched ${data.keys[0]} in ${duration}ms`);
  },
  error: (data) => {
    console.error(`Error in ${data.driver?.name}:`, data.error);
  }
});

All operations emit standard tracing events: start, end, asyncStart, asyncEnd, and error.


⚠️ Current Blocker: unstorage can be used in browser, so we need to shim it in this case, or perhaps provide an alternative.

@logaretm logaretm force-pushed the awad/unstorage-tracing-events branch from f6d665f to f39e20b Compare November 7, 2025 00:02
@logaretm logaretm marked this pull request as ready for review November 7, 2025 08:54
Copilot AI review requested due to automatic review settings December 15, 2025 16:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@logaretm logaretm force-pushed the awad/unstorage-tracing-events branch from b3622f3 to b59a383 Compare December 15, 2025 17:27
@logaretm
Copy link
Author

@pi0 I refactored the logic here to use process.getBuiltIn..., separated the tracing into its own subpath export, and reduced the logic size by generalizing a trace wrapper.

@logaretm logaretm requested a review from pi0 December 24, 2025 13:13
@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

❌ Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.60%. Comparing base (a52bf75) to head (50dded0).

Files with missing lines Patch % Lines
src/tracing.ts 95.55% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #707      +/-   ##
==========================================
+ Coverage   91.77%   92.60%   +0.83%     
==========================================
  Files           5        6       +1     
  Lines         401      446      +45     
  Branches      126      143      +17     
==========================================
+ Hits          368      413      +45     
  Misses         33       33              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants