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-beta.4
Important Changes
- feat(browser): Add INP support for v8 (#11650)
INP web vital support was now forward-ported to version 8. Recording of INP data is enabled by default.
- feat(core): Increase default transport buffer size from 30 to 64 (#11764)
The default limit of queued events to be sent was increased from 30 to 64 events. You may observe a higher memory
footprint of the SDK. You can override this limit by setting the transportOptions.bufferSize
option in
Sentry.init()
.
- feat(replay): Add "maxCanvasSize" option for replay canvases (#11617)
A maxCanvasSize
option was added to the replayCanvasIntegration
to disallow capturing of canvases larger than a
certain size. This value defaults to 1280
which will not capture canvases bigger than 1280x1280 pixels.
Other Changes
- deps: Downgrade
@opentelemetry/instrumentation-http
to 0.48.0
(#11745) - deps(nextjs): Remove unnecessary and faulty
@opentelemetry/api
dependency from Next.js package (#11717) - feat(aws): Add OTEL based integrations (#11548)
- feat(core): Ensure trace context only includes relevant data (#11713)
- feat(deps): Bump @opentelemetry/instrumentation-fastify from 0.33.0 to 0.35.0 (#11690)
- feat(deps): Bump @opentelemetry/instrumentation-graphql from 0.37.0 to 0.39.0 (#11692)
- feat(deps): Bump @opentelemetry/instrumentation-http from 0.48.0 to 0.50.0 (#11725)
- feat(deps): Bump @opentelemetry/instrumentation-mongoose from 0.35.0 to 0.37.0 (#11693)
- feat(deps): Bump @opentelemetry/instrumentation-mysql2 from 0.35.0 to 0.37.0 (#11726)
- feat(deps): Bump @opentelemetry/instrumentation-nestjs-core from 0.34.0 to 0.36.0 (#11727)
- feat(deps): Bump @opentelemetry/sdk-metrics from 1.21.0 to 1.23.0 (#11695)
- feat(deps): Bump @prisma/instrumentation from 5.9.0 to 5.12.1 (#11724)
- feat(feedback): Create async bundles and code to resolve helper integrations (#11621)
- feat(nextjs): Sample out low-quality spans on older Next.js versions (#11722)
- feat(opentelemetry): Support new http method attribute (#11756)
- feat(opentelemetry): Use rest args for addOpenTelemetryInstrumentation (#11721)
- feat(replay): Upgrade rrweb packages to 2.15.0 (#11736)
- fix(browser): Ensure
lazyLoadIntegration
works in NPM mode (#11673) - fix(browser): Set custom sentry source correctly (#11735)
- fix(ember): Do not create rendering spans without transaction (#11749)
- fix(serverless): Check if cloud event callback is a function (#9044) (#11701)
- ref(nextjs): Remove unnecessary logic to filter symbolification/sentry spans (#11714)