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.7
This is the seventh alpha release of Sentry JavaScript SDK v8, which includes a variety of breaking changes.
Read the in-depth migration guide to find out how to address any breaking changes in your code.
Important Changes
- feat(nextjs): Use OpenTelemetry for performance monitoring and tracing (#11016)
We now use OpenTelemetry under the hood to power performance monitoring and tracing in the Next.js SDK.
- feat(v8/gatsby): Update SDK initialization for gatsby (#11292)
In v8, you cannot initialize the SDK anymore via Gatsby plugin options. Instead, you have to configure the SDK in a
sentry.config.js
file.
We also removed the automatic initialization of browserTracingIntegration
. You now have to add this integration
yourself.
Removal/Refactoring of deprecated functionality
- feat(v8): Remove addGlobalEventProcessor (#11255)
- feat(v8): Remove deprecated span id fields (#11180)
- feat(v8): Remove makeMain export (#11278)
- feat(v8/core): Remove deprecated span.sampled (#11274)
- feat(v8/core): Remove getActiveTransaction (#11280)
- feat(v8/core): Remove spanMetadata field (#11271)
- feat(v8/ember): Remove deprecated StartTransactionFunction (#11270)
- feat(v8/replay): Remove deprecated replay options (#11268)
- feat(v8/svelte): Remove deprecated componentTrackingPreprocessor export (#11277)
- ref: Remove more usages of getCurrentHub in the codebase (#11281)
- ref(core): Remove
scope.setSpan()
and scope.getSpan()
methods (#11051) - ref(profiling-node): Remove usage of getCurrentHub (#11275)
- ref(v8): change integration.setupOnce signature (#11238)
- ref: remove node-experimental references (#11290)
Other Changes
- feat(feedback): Make "required" text for input elements configurable (#11152) (#11153)
- feat(feedback): Update user feedback screenshot and cropping to align with designs (#11227)
- feat(nextjs): Remove
runtime
and vercel
tags (#11291) - feat(node): Add scope to ANR events (#11256)
- feat(node): Do not include
prismaIntegration
by default (#11265) - feat(node): Ensure
tracePropagationTargets
are respected (#11285) - feat(node): Simplify
SentrySpanProcessor
(#11273) - feat(profiling): Use OTEL powered node package (#11239)
- feat(utils): Allow text encoder/decoder polyfill from global SENTRY (#11283)
- fix(nextjs): Show misconfiguration warning (no
instrumentation.ts
) (#11266) - fix(node): Add logs when node-fetch cannot be instrumented (#11289)
- fix(node): Skip capturing Hapi Boom error responses. (#11151)
- fix(node): Use
suppressTracing
to avoid capturing otel spans (#11288) - fix(opentelemetry): Do not stomp span status when
startSpan
callback throws (#11170)