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.23.0
Important Changes
- feat(cloudflare): Add Cloudflare D1 instrumentation (#13142)
This release includes support for Cloudflare D1, Cloudflare's serverless SQL database. To instrument your Cloudflare D1
database, use the instrumentD1WithSentry
method as follows:
// env.DB is the D1 DB binding configured in your `wrangler.toml`
const db = instrumentD1WithSentry(env.DB);
// Now you can use the database as usual
await db.prepare('SELECT * FROM table WHERE id = ?').bind(1).run();
Other Changes
- feat(cloudflare): Allow users to pass handler to sentryPagesPlugin (#13192)
- feat(cloudflare): Instrument scheduled handler (#13114)
- feat(core): Add
getTraceData
function (#13134) - feat(nestjs): Automatic instrumentation of nestjs interceptors before route execution (#13153)
- feat(nestjs): Automatic instrumentation of nestjs pipes (#13137)
- feat(nuxt): Filter out Nuxt build assets (#13148)
- feat(profiling): Attach sdk info to chunks (#13145)
- feat(solidstart): Add sentry
onBeforeResponse
middleware to enable distributed tracing (#13221) - feat(solidstart): Filter out low quality transactions for build assets (#13222)
- fix(browser): Avoid showing browser extension error message in non-
window
global scopes (#13156) - fix(feedback): Call dialog.close() in dialog close callbacks in
\_loadAndRenderDialog
(#13203) - fix(nestjs): Inline Observable type to resolve missing 'rxjs' dependency (#13166)
- fix(nuxt): Detect pageload by adding flag in Vue router (#13171)
- fix(utils): Handle when requests get aborted in fetch instrumentation (#13202)
- ref(browser): Improve browserMetrics collection (#13062)
Work in this release was contributed by @horochx. Thank you for your contribution!