What is @sentry/utils?
The @sentry/utils package provides a collection of utility functions and classes that are used across the Sentry JavaScript SDK. These utilities help with various tasks such as data manipulation, browser and node environment checks, and integration with Sentry's error tracking and performance monitoring features.
What are @sentry/utils's main functionalities?
Data Manipulation
Provides utility functions for checking data types and manipulating data. For example, the `isString` function can be used to check if a variable is a string.
import { isString } from '@sentry/utils';
function logMessage(message) {
if (isString(message)) {
console.log(message);
} else {
console.log('Not a string');
}
}
Environment Checks
Includes functions to check the current runtime environment, such as whether the code is running in a browser or Node.js environment. This is useful for writing isomorphic code that runs both on the client and server.
import { isNodeEnv } from '@sentry/utils';
if (isNodeEnv()) {
console.log('Running in a Node environment');
} else {
console.log('Not running in a Node environment');
}
Integration Helpers
Provides functions and classes to help integrate with Sentry, including adding global event processors that can modify or filter events before they are sent to Sentry.
import { addGlobalEventProcessor } from '@sentry/utils';
addGlobalEventProcessor(event => {
// Modify the event object or return null to skip sending the event
return event;
});
Other packages similar to @sentry/utils
lodash
Lodash is a comprehensive utility library offering a wide array of functions for tasks like data manipulation, array and object operations, and more. While it doesn't provide direct integrations with error tracking systems, its broad utility function set makes it a versatile tool for many of the same data manipulation tasks as @sentry/utils.
debug
The debug package is used for logging debug messages in a development environment. It doesn't offer the same utility functions or Sentry integration as @sentry/utils, but it's useful for debugging applications in development, similar to how one might use Sentry's logging and error tracking in production.
Sentry JavaScript SDK Utilities
Links
General
Common utilities used by the Sentry JavaScript SDKs.
Note: This package is only meant to be used internally, and as such is not part of our public API contract and does not
follow semver.
8.34.0
Important Changes
- ref(nextjs): Remove dead code (#13828)
Relevant for users of the @sentry/nextjs
package: If you have previously configured a
SENTRY_IGNORE_API_RESOLUTION_ERROR
environment variable, it is now safe to unset it.
Other Changes
- feat(cdn): Export
getReplay
in replay CDN bundles
(#13881) - feat(replay): Clear fallback buffer when switching buffers
(#13914)
- feat(replay): Upgrade rrweb packages to 2.28.0 (#13732)
- fix(docs): Correct supported browsers due to
globalThis
(#13788) - fix(nextjs): Adjust path to
requestAsyncStorageShim.js
template file
(#13928) - fix(nextjs): Detect new locations for request async storage to support Next.js v15.0.0-canary.180 and higher
(#13920)
- fix(nextjs): Drop
_not-found
spans for all HTTP methods
(#13906) - fix(nextjs): Fix resolution of request storage shim fallback
(#13929)
- fix(node): Ensure graphql options are correct when preloading
(#13769)
- fix(node): Local variables handle error (#13827)
- fix(node): Remove
dataloader
instrumentation from default integrations
(#13873) - fix(nuxt): Create declaration files for Nuxt module
(#13909)
- fix(replay): Ensure
replay_id
is removed from frozen DSC when stopped
(#13893) - fix(replay): Try/catch
sendBufferedReplayOrFlush
to prevent cycles
(#13900) - fix(sveltekit): Ensure trace meta tags are always injected
(#13231)
- fix(sveltekit): Update
wrapServerRouteWithSentry
to respect ParamMatchers
(#13390) - fix(wasm): Integration wasm uncaught WebAssembly.Exception
(#13787) (#13854)
- ref(nextjs): Ignore sentry spans based on query param attribute
(#13905)
- ref(utils): Move
vercelWaitUntil
to utils (#13891)
Work in this release was contributed by @trzeciak, @gurpreetatwal, @ykzts and @lizhiyao. Thank you for your
contributions!