Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@ if (
* node_modules, but some packages which use ES6 syntax only NEED to be
* transformed.
*/
const ESM_NODE_MODULES = ['screenfull', 'cbor2', 'nuqs', 'color', 'marked'];
const ESM_NODE_MODULES = [
'screenfull',
'cbor2',
'nuqs',
'color',
'marked',
'@sentry\\+sqlish',
];

const config: Config.InitialOptions = {
verbose: false,
Expand Down Expand Up @@ -301,6 +308,11 @@ const config: Config.InitialOptions = {
'^echarts/(.*)': '<rootDir>/tests/js/sentry-test/mocks/echartsMock.js',
'^zrender/(.*)': '<rootDir>/tests/js/sentry-test/mocks/echartsMock.js',

// @sentry/sqlish is ESM-only with `exports` that only define `import`
// conditions. Jest's CJS resolver can't follow them without explicit mapping.
'^@sentry/sqlish/react$': '<rootDir>/node_modules/@sentry/sqlish/dist/react.js',
'^@sentry/sqlish$': '<rootDir>/node_modules/@sentry/sqlish/dist/index.js',

// Disabled @sentry/toolbar in tests. It depends on iframes and global
// window/cookies state.
'@sentry/toolbar': '<rootDir>/tests/js/sentry-test/mocks/sentryToolbarMock.js',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"@sentry/node": "10.41.0-beta.0",
"@sentry/react": "10.41.0-beta.0",
"@sentry/release-parser": "^1.3.1",
"@sentry/sqlish": "1.0.1",
"@sentry/status-page-list": "^0.6.1",
"@sentry/toolbar": "1.0.0-beta.16",
"@sentry/webpack-plugin": "4.6.1",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import type {Organization} from 'sentry/types/organization';
import {formatBytesBase2} from 'sentry/utils/bytes/formatBytesBase2';
import {generateLinkToEventInTraceView} from 'sentry/utils/discover/urls';
import {toRoundedPercent} from 'sentry/utils/number/toRoundedPercent';
import {SQLishFormatter} from 'sentry/utils/sqlish/SQLishFormatter';
import {SQLishFormatter} from 'sentry/utils/sqlish';
import {safeURL} from 'sentry/utils/url/safeURL';
import {useLocation} from 'sentry/utils/useLocation';
import {useOrganization} from 'sentry/utils/useOrganization';
Expand Down
69 changes: 69 additions & 0 deletions static/app/utils/sqlish.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Thin wrapper around @sentry/sqlish that adds Sentry observability
* (performance spans and error capture with fingerprinting on parse failures)
* and re-adds `toSimpleMarkup()` which the npm package doesn't include as a
* class method — it ships `simpleMarkup` as a standalone function from
* `@sentry/sqlish/react` instead.
*/
import * as Sentry from '@sentry/react';
import {SQLishFormatter as BaseSQLishFormatter, SQLishParser} from '@sentry/sqlish';
import {simpleMarkup} from '@sentry/sqlish/react';

type StringFormatterOptions = Parameters<BaseSQLishFormatter['toString']>[1];

export class SQLishFormatter {
private formatter: BaseSQLishFormatter;
private parser: SQLishParser;

constructor() {
this.formatter = new BaseSQLishFormatter();
this.parser = new SQLishParser();
}

toString(sql: string, options?: StringFormatterOptions): string {
return this._withSentry('string', () => this.formatter.toString(sql, options), sql);
}

toSimpleMarkup(sql: string): React.ReactElement[] {
return this._withSentry(
'simpleMarkup',
() => simpleMarkup(this.parser.parse(sql)),
sql
);
}

private _withSentry<T>(format: string, fn: () => T, sql: string): T {
const sentrySpan = Sentry.startInactiveSpan({
op: 'function',
name: 'SQLishFormatter.toFormat',
attributes: {format},
onlyIfParent: true,
});

try {
const result = fn();
return result;
} catch (error: any) {
Sentry.withScope(scope => {
const fingerprint = ['sqlish-parse-error'];

if (error?.message) {
scope.setExtra('message', error.message?.slice(-100));
scope.setExtra('found', error.found);

if (error.message.includes('Expected')) {
fingerprint.push(error.message.slice(-10));
}
}

scope.setFingerprint(fingerprint);
Sentry.captureException(error);
});

// If we fail to parse the SQL, return the original string
return sql as unknown as T;
} finally {
sentrySpan?.end();
}
Comment thread
sentry[bot] marked this conversation as resolved.
}
}
148 changes: 0 additions & 148 deletions static/app/utils/sqlish/SQLishFormatter.spec.tsx

This file was deleted.

82 changes: 0 additions & 82 deletions static/app/utils/sqlish/SQLishFormatter.tsx

This file was deleted.

Loading
Loading