or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

async-utilities.mddata-processing.mdenvelopes.mdenvironment.mderror-handling.mdindex.mdinstrumentation.mdlogging.mdstack-processing.mdtype-guards.md
tile.json

tessl/npm-sentry--utils

Deprecated utilities package for Sentry JavaScript SDKs - all functionality moved to @sentry/core

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@sentry/utils@8.55.x

To install, run

npx @tessl/cli install tessl/npm-sentry--utils@8.55.0

index.mddocs/

@sentry/utils

DEPRECATED 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.

Package Information

  • Package Name: @sentry/utils
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @sentry/utils (deprecated - use @sentry/core instead)
  • Node.js requirement: >=14.18

Core Imports

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");   // recommended

Basic Usage

Note: 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
}

Architecture

@sentry/utils is organized around several key areas:

  • Error Processing: Exception handling, error type detection, and error normalization
  • Instrumentation: Event handlers for console, fetch, errors, and unhandled rejections
  • Environment Detection: Browser/Node.js detection and feature support checking
  • Data Processing: Normalization, serialization, and data structure manipulation
  • Logging: Centralized logging with console sandboxing
  • Stack Processing: Stack frame parsing, filtering, and manipulation utilities
  • Envelope System: Data packaging for transmission to Sentry servers
  • Tracing: Trace propagation and baggage header processing
  • Helper Functions: UUID generation, path utilities, URL processing, and type guards

Capabilities

Error Handling & Processing

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;

Error Handling

Instrumentation & Event Handling

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;

Instrumentation

Type Guards & Validation

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 };

Type Guards

Environment & Browser Detection

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;

Environment Detection

Data Normalization & Processing

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[];

Data Processing

Logging & Console

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;

Logging

Stack Processing & Parsing

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[];

Stack Processing

Envelope System

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;

Envelopes

Promise & Async Utilities

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>;

Async Utilities

Types

Core Types

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";