Deprecated utilities package for Sentry JavaScript SDKs - all functionality moved to @sentry/core
npx @tessl/cli install tessl/npm-sentry--utils@8.55.0DEPRECATED NOTICE: The @sentry/utils package is deprecated as of version 8.55.0. All functionality has been moved to @sentry/core. This package now serves only as a compatibility layer during the migration period.
@sentry/utils provides common utilities used internally by all Sentry JavaScript SDKs. While deprecated, it contains over 160 utility functions and classes for error handling, performance monitoring, browser compatibility, envelope creation, instrumentation handlers, and various helper functions that were previously shared across different Sentry SDK packages.
npm install @sentry/utils (deprecated - use @sentry/core instead)Deprecated imports (migrate to @sentry/core):
import {
SentryError,
logger,
normalize,
uuid4,
addInstrumentationHandler,
isError,
isBrowser
} from "@sentry/utils";Recommended migration (import from @sentry/core instead):
import {
SentryError,
logger,
normalize,
uuid4,
addInstrumentationHandler,
isError,
isBrowser
} from "@sentry/core";For CommonJS:
const { SentryError, logger, normalize } = require("@sentry/utils"); // deprecated
const { SentryError, logger, normalize } = require("@sentry/core"); // recommendedNote: All examples show deprecated usage. Replace @sentry/utils imports with @sentry/core.
import { SentryError, logger, normalize, uuid4 } from "@sentry/utils";
// Create Sentry-specific errors
const error = new SentryError("Custom error message");
// Use the logger
logger.info("Processing data...");
// Normalize data for transmission
const normalized = normalize({ user: "john", data: largeObject }, 3);
// Generate unique identifiers
const eventId = uuid4();
// Check environment
import { isBrowser, isNodeEnv } from "@sentry/utils";
if (isBrowser()) {
// Browser-specific logic
} else if (isNodeEnv()) {
// Node.js-specific logic
}@sentry/utils is organized around several key areas:
Core error processing functionality for detecting, normalizing, and enriching error data before transmission to Sentry.
class SentryError extends Error {
constructor(message: string, logLevel?: string);
}
function isError(wat: unknown): wat is Error;
function isErrorEvent(wat: unknown): wat is ErrorEvent;
function isDOMError(wat: unknown): wat is DOMError;
function isDOMException(wat: unknown): wat is DOMException;
function exceptionFromError(parser: StackParser, ex: Error): Exception;
function applyAggregateErrorsToEvent(
exceptionFromErrorImplementation: (stackParser: StackParser, ex: Error) => Exception,
parser: StackParser,
maxValueLimit: number,
key: string,
limit: number,
event: Event,
hint?: EventHint,
): void;Instrumentation handlers for automatically capturing console logs, network requests, errors, and other events.
function addConsoleInstrumentationHandler(handler: (level: string, ...args: any[]) => void): void;
function addFetchInstrumentationHandler(handler: (data: FetchBreadcrumbData) => void): void;
function addGlobalErrorInstrumentationHandler(handler: (data: ErrorEventData) => void): void;
function addGlobalUnhandledRejectionInstrumentationHandler(handler: (data: UnhandledRejectionEventData) => void): void;
function resetInstrumentationHandlers(): void;
function triggerHandlers(type: string, data: any): void;Comprehensive type checking utilities for safe runtime type detection and validation.
function isPlainObject(wat: unknown): wat is Record<string, any>;
function isPrimitive(wat: unknown): wat is Primitive;
function isString(wat: unknown): wat is string;
function isRegExp(wat: unknown): wat is RegExp;
function isThenable(wat: any): wat is PromiseLike<any>;
function isInstanceOf(wat: any, base: any): boolean;
function isElement(wat: unknown): wat is Element;
function isEvent(wat: unknown): wat is Event;
function isSyntheticEvent(wat: unknown): wat is { [key: string]: any };Environment detection utilities for determining runtime capabilities and platform-specific features.
function isBrowser(): boolean;
function isNodeEnv(): boolean;
function isBrowserBundle(): boolean;
function supportsFetch(): boolean;
function supportsNativeFetch(): boolean;
function supportsDOMError(): boolean;
function supportsDOMException(): boolean;
function supportsErrorEvent(): boolean;
function supportsHistory(): boolean;
function supportsReferrerPolicy(): boolean;
function supportsReportingObserver(): boolean;Data normalization and serialization utilities for preparing data structures for transmission.
function normalize(input: any, depth?: number, maxProperties?: number): any;
function normalizeToSize(
object: { [key: string]: any },
minSize?: number,
maxSize?: number,
): { [key: string]: any };
function convertToPlainObject(input: any): PlainObject;
function dropUndefinedKeys(inputValue: { [key: string]: any }): { [key: string]: any };
function addNonEnumerableProperty(obj: any, name: string, value: any): void;
function objectify(wat: unknown): { [key: string]: any };
function arrayify(wat: unknown): any[];
function flatten<T>(arr: ReadonlyArray<T | ReadonlyArray<T>>): T[];Centralized logging system with console sandboxing and original method preservation.
interface Logger {
disable(): void;
enable(): void;
log(...args: any[]): void;
warn(...args: any[]): void;
error(...args: any[]): void;
}
declare const logger: Logger;
declare const CONSOLE_LEVELS: readonly string[];
declare const originalConsoleMethods: { [key in 'log' | 'warn' | 'error']: (...args: any[]) => void };
function consoleSandbox<T>(callback: () => T): T;Stack trace parsing, manipulation, and filtering utilities for error processing.
interface StackFrame {
filename?: string;
function?: string;
module?: string;
platform?: string;
lineno?: number;
colno?: number;
abs_path?: string;
context_line?: string;
pre_context?: string[];
post_context?: string[];
in_app?: boolean;
instruction_addr?: string;
addr_mode?: string;
package?: string;
symbol?: string;
symbol_addr?: string;
trust?: string;
}
type StackLineParser = (line: string) => StackFrame | undefined;
type StackParser = (stack: string, skipFirst?: number) => StackFrame[];
function createStackParser(...parsers: StackLineParser[]): StackParser;
function getFramesFromEvent(event: Event): StackFrame[] | undefined;
function parseStackFrames(parser: StackParser, err: Error & { stacktrace?: string }): StackFrame[];Data packaging system for structuring and transmitting telemetry data to Sentry servers.
type EnvelopeItemType = 'event' | 'transaction' | 'session' | 'attachment' | 'user_report' | 'profile';
interface EnvelopeItem<T = any> {
0: EnvelopeItemHeader;
1: T;
}
interface Envelope {
0: EnvelopeHeader;
1: EnvelopeItem[];
}
function createEnvelope<E extends Envelope>(
headers: E[0],
items?: E[1]
): E;
function addItemToEnvelope<E extends Envelope>(envelope: E, newItem: E[1][number]): E;
function forEachEnvelopeItem<E extends Envelope>(
envelope: E,
callback: (item: E[1][number], type?: EnvelopeItemType) => boolean | void,
): boolean;
function serializeEnvelope(envelope: Envelope): string;
function parseEnvelope(env: string): Envelope;Synchronous promise implementation and promise buffer management for reliable async operations.
class SyncPromise<T> implements PromiseLike<T> {
constructor(
executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void
);
then<TResult1 = T, TResult2 = never>(
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
): SyncPromise<TResult1 | TResult2>;
catch<TResult = never>(
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null,
): SyncPromise<T | TResult>;
}
function resolvedSyncPromise<T>(value: T): SyncPromise<T>;
function rejectedSyncPromise<T = never>(value: any): SyncPromise<T>;
interface PromiseBuffer<T> {
$: Array<PromiseLike<T>>;
add(taskProducer: () => PromiseLike<T>): PromiseLike<T>;
drain(timeout?: number): PromiseLike<boolean>;
}
function makePromiseBuffer<T>(limit?: number): PromiseBuffer<T>;interface InternalGlobal {
console?: Console;
__SENTRY__?: {
globalEventProcessors?: EventProcessor[];
hub?: Hub;
logger?: Logger;
};
}
type SdkSource = 'npm' | 'cdn' | 'loader';
interface RateLimits {
[category: string]: number;
}
interface AddRequestDataToEventOptions {
include?: {
cookies?: boolean;
data?: boolean;
headers?: boolean;
ip?: boolean;
query_string?: boolean;
url?: boolean;
user?: boolean;
};
deps?: {
cookie?: {
parse: (cookieStr: string) => Record<string, string>;
};
url?: {
parse: (urlStr: string) => {
query: string | null;
};
};
};
}Migration Notice: All types, functions, and classes from @sentry/utils are deprecated. Import them from @sentry/core instead:
// ❌ Deprecated
import { SentryError, Logger } from "@sentry/utils";
// ✅ Recommended
import { SentryError, Logger } from "@sentry/core";