|
| 1 | +# Upgrading from 4.x to 5.x |
| 2 | + |
| 3 | +In this version upgrade, there are a few breaking changes. This guide should help you update your code accordingly. |
| 4 | + |
| 5 | +## Integrations |
| 6 | + |
| 7 | +We moved optional integrations into their own package, called `@sentry/integrations`. Also, we made a few default |
| 8 | +integrations now optional. This is probably the biggest breaking change regarding the upgrade. |
| 9 | + |
| 10 | +Integrations that are now opt-in and were default before: |
| 11 | + |
| 12 | +- Dedupe (responsible for sending the same error only once) |
| 13 | +- ExtraErrorData (responsible for doing fancy magic, trying to extract data out of the error object using any |
| 14 | + non-standard keys) |
| 15 | + |
| 16 | +Integrations that were pluggable/optional before, that also live in this package: |
| 17 | + |
| 18 | +- Angular (browser) |
| 19 | +- Debug (browser/node) |
| 20 | +- Ember (browser) |
| 21 | +- ReportingObserver (browser) |
| 22 | +- RewriteFrames (browser/node) |
| 23 | +- Transaction (browser/node) |
| 24 | +- Vue (browser) |
| 25 | + |
| 26 | +### How to use `@sentry/integrations`? |
| 27 | + |
| 28 | +Lets start with the approach if you install `@sentry/browser` / `@sentry/electron` with `npm` or `yarn`. |
| 29 | + |
| 30 | +Given you have a `Vue` application running, in order to use the `Vue` integration you need to do the following: |
| 31 | + |
| 32 | +With `4.x`: |
| 33 | + |
| 34 | +```js |
| 35 | +import * as Sentry from '@sentry/browser'; |
| 36 | + |
| 37 | +Sentry.init({ |
| 38 | + dsn: '___PUBLIC_DSN___', |
| 39 | + integrations: [ |
| 40 | + new Sentry.Integrations.Vue({ |
| 41 | + Vue, |
| 42 | + attachProps: true, |
| 43 | + }), |
| 44 | + ], |
| 45 | +}); |
| 46 | +``` |
| 47 | + |
| 48 | +With `5.x` you need to install `@sentry/integrations` and change the import. |
| 49 | + |
| 50 | +```js |
| 51 | +import * as Sentry from '@sentry/browser'; |
| 52 | +import * as Integrations from '@sentry/integrations'; |
| 53 | + |
| 54 | +Sentry.init({ |
| 55 | + dsn: '___PUBLIC_DSN___', |
| 56 | + integrations: [ |
| 57 | + new Integrations.Vue({ |
| 58 | + Vue, |
| 59 | + attachProps: true, |
| 60 | + }), |
| 61 | + ], |
| 62 | +}); |
| 63 | +``` |
| 64 | + |
| 65 | +In case you are using the CDN version or the Loader, we provide a standalone file for every integration, you can use it |
| 66 | +like this: |
| 67 | + |
| 68 | +```html |
| 69 | +<!-- Note that we now also provide a es6 build only --> |
| 70 | +<!-- <script src="https://browser.sentry-cdn.com/5.0.0/bundle.es6.min.js" crossorigin="anonymous"></script> --> |
| 71 | +<script src="https://browser.sentry-cdn.com/5.0.0/bundle.min.js" crossorigin="anonymous"></script> |
| 72 | + |
| 73 | +<!-- If you include the integration it will be available under Sentry.Integrations.Vue --> |
| 74 | +<script src="https://browser.sentry-cdn.com/5.0.0/vue.min.js" crossorigin="anonymous"></script> |
| 75 | + |
| 76 | +<script> |
| 77 | + Sentry.init({ |
| 78 | + dsn: '___PUBLIC_DSN___', |
| 79 | + integrations: [ |
| 80 | + new Sentry.Integrations.Vue({ |
| 81 | + Vue, |
| 82 | + attachProps: true, |
| 83 | + }), |
| 84 | + ], |
| 85 | + }); |
| 86 | +</script> |
| 87 | +``` |
| 88 | + |
| 89 | +## New Scope functions |
| 90 | + |
| 91 | +We realized how annoying it is to set a whole object using `setExtra`, that's why there are now a few new methods on the |
| 92 | +`Scope`. |
| 93 | + |
| 94 | +```typescript |
| 95 | +setTags(tags: { [key: string]: string }): this; |
| 96 | +setExtras(extras: { [key: string]: any }): this; |
| 97 | +clearBreadcrumbs(): this; |
| 98 | +``` |
| 99 | + |
| 100 | +So you can do this now: |
| 101 | + |
| 102 | +```js |
| 103 | +// New in 5.x setExtras |
| 104 | +Sentry.withScope(scope => { |
| 105 | + scope.setExtras(errorInfo); |
| 106 | + Sentry.captureException(error); |
| 107 | +}); |
| 108 | + |
| 109 | +// vs. 4.x |
| 110 | +Sentry.withScope(scope => { |
| 111 | + Object.keys(errorInfo).forEach(key => { |
| 112 | + scope.setExtra(key, errorInfo[key]); |
| 113 | + }); |
| 114 | + Sentry.captureException(error); |
| 115 | +}); |
| 116 | +``` |
| 117 | + |
| 118 | +## Less Async API |
| 119 | + |
| 120 | +We removed a lot of the internal async code since in certain situations it generated a lot of memory pressure. This |
| 121 | +really only affects you if you where either using the `BrowserClient` or `NodeClient` directly. |
| 122 | + |
| 123 | +So all the `capture*` functions now instead of returning `Promise<Response>` return `string | undefined`. `string` in |
| 124 | +this case is the `event_id`, in case the event will not be sent because of filtering it will return `undefined`. |
| 125 | + |
| 126 | +## `close` vs. `flush` |
| 127 | + |
| 128 | +In `4.x` we had both `close` and `flush` on the `Client` draining the internal queue of events, helpful when you were |
| 129 | +using `@sentry/node` on a serverless infrastructure. |
| 130 | + |
| 131 | +Now `close` and `flush` work similar, with the difference that if you call `close` in addition to returing a `Promise` |
| 132 | +that you can await it also **disables** the client so it will not send any future events. |
0 commit comments