CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sentry--integrations

Pluggable integrations that enhance Sentry JavaScript SDKs with additional error tracking, monitoring, and debugging capabilities.

Pending
Overview
Eval results
Files

extra-error-data.mddocs/

Extra Error Data

Extracts additional custom properties from Error objects and attaches them as event context. This integration captures non-standard error properties, error causes, and custom data attached to Error instances.

Capabilities

Modern Function-based Integration

/**
 * Extracts additional data from original exceptions
 * @param options - Configuration for error data extraction
 * @returns Integration instance that enhances error events
 */
function extraErrorDataIntegration(options?: Partial<ExtraErrorDataOptions>): Integration;

interface ExtraErrorDataOptions {
  /** The object depth up to which to capture data on error objects. Default: 3 */
  depth: number;
  /** Whether to capture error causes (Error.cause property). Default: false */
  captureErrorCause: boolean;
}

Legacy Class-based Integration (Deprecated)

/**
 * Legacy class-based extra error data integration
 * @deprecated Use extraErrorDataIntegration() instead
 */
class ExtraErrorData implements Integration {
  constructor(options?: Partial<{
    depth: number;
    captureErrorCause: boolean;
  }>);
  name: string;
  processEvent(event: Event, hint: EventHint): Event;
}

Configuration Options

depth Option

Controls how deeply nested objects on Error instances are serialized:

  • Default: 3 levels deep
  • Purpose: Prevents infinite recursion and excessive data capture
  • Applied: Uses normalize() from @sentry/utils with specified depth

captureErrorCause Option

Controls whether to capture the standard Error.cause property:

  • Default: false (will be true in v8)
  • Standard: Part of ES2022 Error.cause specification
  • Fallback: Non-enumerable property access for error.cause

Behavior

Property Extraction

The integration extracts all enumerable properties from Error objects, excluding standard Error properties:

Excluded Properties (native Error properties):

  • name, message, stack
  • line, column, fileName
  • lineNumber, columnNumber
  • toJSON

Additional Processing:

  • Error values in custom properties are converted to strings
  • toJSON() method results are merged if present
  • Error.cause captured separately when enabled

Context Attachment

Extracted data is attached to the event under contexts[ExceptionName]:

  • Context key uses the Error constructor name or name property
  • Data is normalized to prevent serialization issues
  • Marked with __sentry_skip_normalization__ to prevent double-processing

Usage Examples

import { extraErrorDataIntegration } from '@sentry/integrations';
import * as Sentry from '@sentry/browser';

// Basic setup with defaults
Sentry.init({
  dsn: 'YOUR_DSN',
  integrations: [
    extraErrorDataIntegration()
  ]
});

// Custom configuration
Sentry.init({
  dsn: 'YOUR_DSN',
  integrations: [
    extraErrorDataIntegration({
      depth: 5,              // Deeper object traversal
      captureErrorCause: true // Include error causes
    })
  ]
});

// Usage with custom error properties
class CustomError extends Error {
  constructor(message, { userId, requestId, metadata }) {
    super(message);
    this.userId = userId;
    this.requestId = requestId;
    this.metadata = metadata;
    this.timestamp = Date.now();
  }
}

// Error with cause chain
const rootCause = new Error('Database connection failed');
const apiError = new Error('API request failed', { cause: rootCause });
apiError.statusCode = 500;
apiError.endpoint = '/api/users';

throw apiError;
// Results in Sentry event with custom properties in contexts

Error Object Examples

Custom Error Properties

const error = new Error('Custom error');
error.userId = '12345';
error.context = { 
  action: 'data-processing',
  retryCount: 3 
};
error.timestamp = Date.now();

throw error;
// Custom properties appear in Sentry contexts

Library Error Objects

Many libraries attach additional data to errors:

// Axios errors
const axiosError = new Error('Request failed');
axiosError.config = { url: '/api', method: 'POST' };
axiosError.response = { status: 404, data: { error: 'Not found' } };

// This data is automatically captured
throw axiosError;

Error Causes (ES2022)

const dbError = new Error('Connection timeout');
const serviceError = new Error('Service unavailable', { cause: dbError });

// Both error messages and cause chain captured when enabled
throw serviceError;

The integration is particularly valuable for applications using custom Error classes or third-party libraries that attach metadata to Error objects.

Install with Tessl CLI

npx tessl i tessl/npm-sentry--integrations

docs

console-capture.md

context-lines.md

debug-integration.md

error-deduplication.md

extra-error-data.md

frame-rewriting.md

http-client.md

index.md

offline-support.md

reporting-observer.md

session-timing.md

transaction-integration.md

tile.json