or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

console-capture.mdcontext-lines.mddebug-integration.mderror-deduplication.mdextra-error-data.mdframe-rewriting.mdhttp-client.mdindex.mdoffline-support.mdreporting-observer.mdsession-timing.mdtransaction-integration.md

console-capture.mddocs/

0

# Console Capture

1

2

Captures Console API calls (console.log, console.error, console.warn, etc.) as Sentry events. This integration is useful for debugging and monitoring console output in production environments.

3

4

## Capabilities

5

6

### Modern Function-based Integration

7

8

```typescript { .api }

9

/**

10

* Captures Console API calls as Sentry events

11

* @param options - Configuration options for console capture

12

* @returns Integration instance

13

*/

14

function captureConsoleIntegration(options?: CaptureConsoleOptions): Integration;

15

16

interface CaptureConsoleOptions {

17

/** Console levels to capture. Defaults to all available console levels */

18

levels?: string[];

19

}

20

```

21

22

**Usage Examples:**

23

24

```typescript

25

import { captureConsoleIntegration } from '@sentry/integrations';

26

27

// Capture all console levels (default)

28

const consoleIntegration = captureConsoleIntegration();

29

30

// Capture only errors and warnings

31

const errorWarningConsole = captureConsoleIntegration({

32

levels: ['error', 'warn']

33

});

34

35

// Capture specific levels

36

const customLevels = captureConsoleIntegration({

37

levels: ['error', 'warn', 'info', 'debug']

38

});

39

```

40

41

### Legacy Class-based Integration (Deprecated)

42

43

```typescript { .api }

44

/**

45

* Legacy class-based console capture integration

46

* @deprecated Use captureConsoleIntegration() instead

47

*/

48

class CaptureConsole implements Integration {

49

constructor(options?: { levels?: string[] });

50

name: string;

51

setup(client: Client): void;

52

}

53

```

54

55

## Configuration

56

57

### Console Levels

58

59

The `levels` option accepts an array of console method names. Available levels are:

60

61

- `'debug'` - console.debug() calls

62

- `'info'` - console.info() calls

63

- `'warn'` - console.warn() calls

64

- `'error'` - console.error() calls

65

- `'log'` - console.log() calls

66

- `'assert'` - console.assert() calls

67

- `'trace'` - console.trace() calls

68

69

If not specified, all available console levels are captured (uses `CONSOLE_LEVELS` from @sentry/utils which contains: `['debug', 'info', 'warn', 'error', 'log', 'assert', 'trace']`).

70

71

## Behavior

72

73

### Event Creation

74

75

- **Regular console calls**: Creates message events with the console arguments

76

- **console.assert()**: Creates message events when assertion fails (first argument is false)

77

- **console.error() with Error objects**: Creates exception events when Error objects are found in arguments

78

- **Event metadata**: All events include:

79

- `logger: 'console'` field

80

- `level` set based on console method used

81

- `extra.arguments` containing the original console arguments

82

- Exception mechanism with `type: 'console'` and `handled: false`

83

84

### Argument Processing

85

86

Console arguments are processed as follows:

87

- Arguments are joined with spaces for the message text

88

- Original arguments are preserved in `extra.arguments`

89

- Error objects are converted to exception events when possible

90

- console.assert() uses arguments after the first (assertion condition) for the message

91

92

**Usage in Sentry Configuration:**

93

94

```typescript

95

import * as Sentry from '@sentry/browser';

96

import { captureConsoleIntegration } from '@sentry/integrations';

97

98

Sentry.init({

99

dsn: 'YOUR_DSN',

100

integrations: [

101

captureConsoleIntegration({

102

levels: ['error', 'warn', 'assert']

103

})

104

]

105

});

106

107

// These will now be captured as Sentry events:

108

console.error('API request failed', { status: 404 });

109

console.warn('Deprecated function used');

110

console.assert(false, 'Assertion failed with details');

111

```