Skip to content

Commit 1869bb7

Browse files
committed
ref: Make it easier to use stackParser
1 parent 1c5bff0 commit 1869bb7

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
lines changed

packages/browser/src/exports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export {
4545

4646
export { BrowserClient } from './client';
4747
export {
48-
defaultStackParsers,
48+
defaultStackParser,
49+
defaultStackLineParsers,
4950
chromeStackParser,
5051
geckoStackParser,
5152
opera10StackParser,

packages/browser/src/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import {
1111
getGlobalObject,
1212
logger,
1313
resolvedSyncPromise,
14-
stackParserFromOptions,
14+
stackParserFromStackParserOptions,
1515
supportsFetch,
1616
} from '@sentry/utils';
1717

1818
import { BrowserClient, BrowserClientOptions, BrowserOptions } from './client';
1919
import { IS_DEBUG_BUILD } from './flags';
2020
import { ReportDialogOptions, wrap as internalWrap } from './helpers';
2121
import { Breadcrumbs, Dedupe, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';
22-
import { defaultStackParsers } from './stack-parsers';
22+
import { defaultStackParser } from './stack-parsers';
2323
import { makeFetchTransport, makeXHRTransport } from './transports';
2424

2525
export const defaultIntegrations = [
@@ -110,7 +110,7 @@ export function init(options: BrowserOptions = {}): void {
110110

111111
const clientOptions: BrowserClientOptions = {
112112
...options,
113-
stackParser: stackParserFromOptions(options.stackParser || defaultStackParsers),
113+
stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),
114114
integrations: getIntegrationsToSetup(options),
115115
transport: options.transport || (supportsFetch() ? makeFetchTransport : makeXHRTransport),
116116
};

packages/browser/src/stack-parsers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { StackFrame, StackLineParser, StackLineParserFn } from '@sentry/types';
2+
import { createStackParser } from '@sentry/utils';
23

34
// global reference to slice
45
const UNKNOWN_FUNCTION = '?';
@@ -130,7 +131,9 @@ const opera11: StackLineParserFn = line => {
130131

131132
export const opera11StackParser: StackLineParser = [OPERA11_PRIORITY, opera11];
132133

133-
export const defaultStackParsers = [chromeStackParser, geckoStackParser, winjsStackParser];
134+
export const defaultStackLineParsers = [chromeStackParser, geckoStackParser, winjsStackParser];
135+
136+
export const defaultStackParser = createStackParser(...defaultStackLineParsers);
134137

135138
/**
136139
* Safari web extensions, starting version unknown, can produce "frames-only" stacktraces.

packages/node/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export { NodeClient } from './client';
4646
export { defaultIntegrations, init, lastEventId, flush, close, getSentryRelease } from './sdk';
4747
export { deepReadDirSync } from './utils';
4848
export { SDK_NAME } from './version';
49-
export { nodeStackParser } from './stack-parser';
49+
export { defaultStackParser } from './stack-parser';
5050

5151
import { Integrations as CoreIntegrations } from '@sentry/core';
5252
import { getMainCarrier } from '@sentry/hub';

packages/node/src/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { getCurrentHub, getIntegrationsToSetup, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
22
import { getMainCarrier, setHubOnCarrier } from '@sentry/hub';
33
import { SessionStatus } from '@sentry/types';
4-
import { getGlobalObject, logger, stackParserFromOptions } from '@sentry/utils';
4+
import { getGlobalObject, logger, stackParserFromStackParserOptions } from '@sentry/utils';
55
import * as domain from 'domain';
66

77
import { NodeClient } from './client';
88
import { IS_DEBUG_BUILD } from './flags';
99
import { Console, ContextLines, Http, LinkedErrors, OnUncaughtException, OnUnhandledRejection } from './integrations';
10-
import { nodeStackParser } from './stack-parser';
10+
import { defaultStackParser } from './stack-parser';
1111
import { makeNodeTransport } from './transports';
1212
import { NodeClientOptions, NodeOptions } from './types';
1313

@@ -130,7 +130,7 @@ export function init(options: NodeOptions = {}): void {
130130
// TODO(v7): Refactor this to reduce the logic above
131131
const clientOptions: NodeClientOptions = {
132132
...options,
133-
stackParser: stackParserFromOptions(options.stackParser || [nodeStackParser]),
133+
stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),
134134
integrations: getIntegrationsToSetup(options),
135135
transport: options.transport || makeNodeTransport,
136136
};

packages/node/src/stack-parser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { StackLineParser, StackLineParserFn } from '@sentry/types';
2-
import { basename, dirname } from '@sentry/utils';
2+
import { basename, createStackParser, dirname } from '@sentry/utils';
33

44
/** Gets the module */
55
function getModule(filename: string | undefined): string | undefined {
@@ -114,4 +114,6 @@ const node: StackLineParserFn = (line: string) => {
114114
};
115115
};
116116

117-
export const nodeStackParser: StackLineParser = [90, node];
117+
export const nodeStackLineParser: StackLineParser = [90, node];
118+
119+
export const defaultStackParser = createStackParser(nodeStackLineParser);

packages/utils/src/stacktrace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function createStackParser(...parsers: StackLineParser[]): StackParser {
3636
*
3737
* If options contains an array of line parsers, it is converted into a parser
3838
*/
39-
export function stackParserFromOptions(stackParser: StackParser | StackLineParser[]): StackParser {
39+
export function stackParserFromStackParserOptions(stackParser: StackParser | StackLineParser[]): StackParser {
4040
if (Array.isArray(stackParser)) {
4141
return createStackParser(...stackParser);
4242
}

0 commit comments

Comments
 (0)