You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(core): Add type & utility for function-based integrations (#9818)
This PR adds new types for function-based integrations, that eventually
(in v8) should fully replace the class-based functions.
This also introduces a small helper function to make writing such
integrations easier (as we need to set an id/name etc. on the
integration). With this, you can write an integration like this:
```ts
const inboundFiltersIntegration = makeIntegrationFn(
'InboundFilters',
(options: Partial<InboundFiltersOptions>) => {
return {
processEvent(event, _hint, client) {
const clientOptions = client.getOptions();
const mergedOptions = _mergeOptions(options, clientOptions);
return _shouldDropEvent(event, mergedOptions) ? null : event;
}
}
});
```
And you get a fully typed integration ready to go!
For backwards compatibility, and so that we can actually start
converting integrations in v7 already, this PR also adds a small utility
`convertIntegrationFnToClass()` to convert such an integration to the
"current" integration class syntax.
So we can actually already start porting integrations over like this:
```js
/** Inbound filters configurable by the user */
// eslint-disable-next-line deprecation/deprecation
export const InboundFilters = convertIntegrationFnToClass(inboundFiltersIntegration);
```
Then, in v8 we only have to remove all the `convertIntegrationFnToClass`
calls, export the integration functions directly, and update the overall
integration types which can be passed to `init()` etc.
0 commit comments