Skip to content

ref: Make it easier to use stackParser #5015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 3, 2022
Merged

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Apr 28, 2022

After writing up #5011, I realized using clients manually was kind of annoying as you had to use a util to pass in the stackParser correctly:

import { BrowserClient, defaultStackParsers, defaultIntegrations, makeFetchTransport } from '@sentry/browser';
import { stackParserFromOptions } from '@sentry/utils';
// New in v7:
const client = new BrowserClient({
  transport: makeFetchTransport,
  stackParser: stackParserFromOptions(defaultStackParsers),
  integrations: defaultIntegrations,
});

This PR update exports so that you can just reference the defaultStackParser directly.

import { BrowserClient, defaultStackParser, defaultIntegrations, makeFetchTransport } from '@sentry/browser';

// New in v7:
const client = new BrowserClient({
  transport: makeFetchTransport,
  stackParser: defaultStackParser,
  integrations: defaultIntegrations,
});

@AbhiPrasad AbhiPrasad requested review from a team, lforst and lobsterkatie and removed request for a team April 28, 2022 19:53
@github-actions
Copy link
Contributor

github-actions bot commented Apr 28, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 18.71 KB (-7.13% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 58.39 KB (-9.64% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 17.42 KB (-7.67% 🔽)
@sentry/browser - ES6 CDN Bundle (minified) 52.55 KB (-9.35% 🔽)
@sentry/browser - Webpack (gzipped + minified) 19.2 KB (-17.37% 🔽)
@sentry/browser - Webpack (minified) 62.09 KB (-24.01% 🔽)
@sentry/react - Webpack (gzipped + minified) 19.22 KB (-17.41% 🔽)
@sentry/nextjs Client - Webpack (gzipped + minified) 42.89 KB (-10.75% 🔽)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 24.5 KB (-6.04% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 22.97 KB (-6.2% 🔽)

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good change. Some tests still need adjustments small import adjustments like here:

import { defaultStackParsers, opera10StackParser, opera11StackParser } from '../../../src/stack-parsers';
const operaParser = createStackParser(opera10StackParser, opera11StackParser);
const chromiumParser = createStackParser(...defaultStackParsers);

@kamilogorek
Copy link
Contributor

kamilogorek commented Apr 29, 2022

How about:

import { defaultBrowserOptions } from '@sentry/browser';

const client = BrowserClient({
  ...defaultBrowserOptions
});
import { defaultBrowserOptions } from '@sentry/browser';

const client = BrowserClient({
  ...defaultBrowserOptions,
  transport: myCustomTransportFactory
});
import { defaultBrowserOptions } from '@sentry/browser';

const { transport, stackParser, integrations } = defaultBrowserOptions;

const client = BrowserClient({
  transport,
  stackParser,
  integrations
});

or call it defaultClientOptions, so we can reuse the same name in every package.
If someone wants, they can always rename it during import.

@Lms24
Copy link
Member

Lms24 commented Apr 29, 2022

@kamilogorek do you mean defaultBrowserOptions could replace defaultIntegrations, defaultStackParser, etc?

Seems clean but would default integrations then still get tree-shaken out if they're not used? Say in a case like this:

import { defaultBrowserOptions } from '@sentry/browser';

const client = BrowserClient({
  ...defaultBrowserOptions,
  integrations: []
});

@kamilogorek
Copy link
Contributor

@kamilogorek do you mean defaultBrowserOptions could replace defaultIntegrations, defaultStackParser, etc?

Yes

I'm not sure, but there's a chance they would not, it'd have to be tested.

const { transport, stackParser, integrations } = defaultBrowserOptions;

has a higher chance of being tree shaken (at least from a logical perspective)

@AbhiPrasad
Copy link
Member Author

We had a chat about this - decided against the defaultClientOptions object (or similar) being included for now, we can always add it in afterwards if many people ask for it.

@AbhiPrasad AbhiPrasad force-pushed the v7-abhi-stack-parser-option branch from 1869bb7 to 5fab95a Compare April 29, 2022 18:59
@AbhiPrasad AbhiPrasad force-pushed the v7-abhi-stack-parser-option branch from 5fab95a to 100ba1a Compare April 29, 2022 19:03
lforst added a commit that referenced this pull request May 3, 2022
@lforst lforst requested a review from Lms24 May 3, 2022 09:11
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing the tests and for adding the migration changes!

@AbhiPrasad AbhiPrasad merged commit 2df499b into 7.x May 3, 2022
@AbhiPrasad AbhiPrasad deleted the v7-abhi-stack-parser-option branch May 3, 2022 11:12
AbhiPrasad added a commit that referenced this pull request May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants