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.0.0-alpha.2
This alpha release fixes a build problem that prevented 8.0.0-alpha.1 from being properly released.
Important Changes
- feat: Remove
@sentry/opentelemetry-node
package (#10906)
The @sentry/opentelemetry-node
package has been removed. Instead, you can either use @sentry/node
with built-in
OpenTelemetry support, or use @sentry/opentelemetry
to manually connect Sentry with OpenTelemetry.
Removal/Refactoring of deprecated functionality
- ref: Refactor some deprecated
startSpan
options (#10825) - feat(v8/core): remove void from transport return (#10794)
- ref(integrations): Delete deprecated class integrations (#10887)
Other Changes
- feat(core): Use serialized spans in transaction event (#10912)
- feat(deps): bump @sentry/cli from 2.28.6 to 2.29.1 (#10908)
- feat(node): Allow to configure
skipOpenTelemetrySetup
(#10907) - feat(esm): Import rather than require
inspector
(#10910) - fix(browser): Don't use chrome variable name (#10874)
- chore(sveltekit): Fix punctuation in a console.log (#10895)
- fix(opentelemetry): Ensure DSC propagation works correctly (#10904)
- feat(browser): Exclude span exports from non-performance CDN bundles (#10879)
- ref: Refactor span status handling to be OTEL compatible (#10871)
- feat(core): Fix span scope handling & transaction setting (#10886)
- ref(ember): Avoid namespace import to hopefully resolve minification issue (#10885)
Work in this release contributed by @harish-talview & @bfontaine. Thank you for your contributions!