Skip to content
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

feat: Switch to new transports #4943

Merged
merged 60 commits into from
Apr 25, 2022
Merged

feat: Switch to new transports #4943

merged 60 commits into from
Apr 25, 2022

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Apr 14, 2022

Fixes #4660

This PR switches over from the old transports to the new ones. It deletes the functionality from the client of passing in transports explicitly and instead expects the transport to be passed in through options.

Instead of passing in an instance of a transport to the client, we pass in a constructor function. This allows the client to control exactly what options are passed into the transport.

this._transport = options.transport({ ...options.transportOptions, url });

Resolves https://getsentry.atlassian.net/browse/WEB-774

@AbhiPrasad AbhiPrasad changed the base branch from 7.x to v7-options-from-client April 19, 2022 02:42
...((this._transport as unknown as { _api: Partial<APIDetails> })._api || {}),
metadata: options._metadata || {},
};
this._transport = options.transport({ ...options.transportOptions, url: url || '' });
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the key here, making sure the client still controls what is being passed in as options.

@AbhiPrasad AbhiPrasad force-pushed the v7-abhi-use-new-transport branch 3 times, most recently from 7e52ad5 to 870f57a Compare April 19, 2022 15:54
@github-actions
Copy link
Contributor

github-actions bot commented Apr 19, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.86 KB (-1.04% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 63.09 KB (-2.26% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.54 KB (-1.29% 🔽)
@sentry/browser - ES6 CDN Bundle (minified) 56.81 KB (-1.98% 🔽)
@sentry/browser - Webpack (gzipped + minified) 21.77 KB (-6.2% 🔽)
@sentry/browser - Webpack (minified) 74.12 KB (-10.11% 🔽)
@sentry/react - Webpack (gzipped + minified) 21.81 KB (-6.21% 🔽)
@sentry/nextjs Client - Webpack (gzipped + minified) 46.21 KB (-3.72% 🔽)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.67 KB (-1.2% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.09 KB (-1.31% 🔽)

Base automatically changed from v7-options-from-client to 7.x April 19, 2022 16:46
Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

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

Looking good. Some small things. We should definitely fix the tests before merging. Let me know if I can help there!

packages/core/src/transports/base.ts Outdated Show resolved Hide resolved
packages/core/src/baseclient.ts Outdated Show resolved Hide resolved
packages/core/src/baseclient.ts Show resolved Hide resolved
packages/node/src/transports/new.ts Outdated Show resolved Hide resolved
...options.transportOptions,
...(options.httpProxy && { httpProxy: options.httpProxy }),
...(options.httpsProxy && { httpsProxy: options.httpsProxy }),
...(options.caCerts && { caCerts: options.caCerts }),
Copy link
Member

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 idea. That's what your changes do anyways right?


assertSentryEvent(requestBody, {
assertSentryEvent(envelopes[1][2], {
Copy link
Member

Choose a reason for hiding this comment

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

This is super wonky. We might want to write utility functions in the future to avoid these index shenanigans. (not this PR tho)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes we can improve this API a lot, I'll write up a improvement ticket.

packages/types/src/transport.ts Show resolved Hide resolved
- Inject transport into client instead of initializing it in the client in `setupTransport` (see
[#4921](https://github.com/getsentry/sentry-javascript/pull/4921/)). If you are creating your own `Client` or
calling `initAndBind`, you will have to supply your desired transport. Either provide a custom one or call
`setupBrowserTransport` or `setupNodeTransport` for default transports, depending on your requirements.
- Remove support for Opera browser pre v15
Copy link
Member

Choose a reason for hiding this comment

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

I think this PR might be a good opportuinity to add the transport changes to the migration docs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah agree, I'll add those.

Copy link
Member Author

Choose a reason for hiding this comment

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

Decided that I'll do this in a follow up PR!

@lforst
Copy link
Member

lforst commented Apr 21, 2022

Tests are finally passing! 🍾

@AbhiPrasad it would be great if you could check if the changes I made actually make sense.

Edit: Actually I'm not sure if ember is flaky again or if it has failing tests for real.

@AbhiPrasad
Copy link
Member Author

AbhiPrasad commented Apr 21, 2022

Ember tests were for real! Fixed them - hopefully this should be it 🤞

Update: It wasn't :(

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.

Overall, this looks really good to me, nice work @AbhiPrasad and @lforst! All my questions/remarks are more or less asked out of curiosity which is why I think this is ready to go regardless of the answers.

Admittedly, I only skimmed over the tests but they also seemed fine to me. I do have a few questions related to tests:

  • It seems like we deleted the integration tests for the new transports (browser and node). Is there a reason for this?
  • Also, we deleted the transport setup unit tests (the ones that test correct setup of fetch and xhr, http/s transports). I mean those weren't the most critical tests for sure but wouldn't it still be good to test this behaviour? Or did I miss something here (i.e. were they moved to a different file)?

Nice bundle size reduction btw! 🚀

packages/core/src/baseclient.ts Show resolved Hide resolved
@lforst
Copy link
Member

lforst commented Apr 22, 2022

@Lms24

It seems like we deleted the integration tests for the new transports (browser and node). Is there a reason for this?

I think this is due to the fact that we now don't have "new" transports anymore and the integration tests for the old transports now test the new ones. Keeping these tests would mean we would test stuff twice, which is unnecessary.

Also, we deleted the transport setup unit tests (the ones that test correct setup of fetch and xhr, http/s transports). I mean those weren't the most critical tests for sure but wouldn't it still be good to test this behaviour? Or did I miss something here (i.e. were they moved to a different file)?

We entirely removed the setup functions and their tests. This is what we discussed in #4921 (comment). I think these setup functions are redundant if we don't have to deal with the old transports and so would be their tests.

@AbhiPrasad
Copy link
Member Author

Thanks for answering the questions ❤️ @lforst

Merging this in to unblock the rest of our work!

@AbhiPrasad AbhiPrasad merged commit 6267b54 into 7.x Apr 25, 2022
@AbhiPrasad AbhiPrasad deleted the v7-abhi-use-new-transport branch April 25, 2022 03:08
@AbhiPrasad AbhiPrasad added this to the 7.0.0 milestone Apr 25, 2022
Lms24 pushed a commit that referenced this pull request Apr 26, 2022
This PR switches over from the old transports to the new ones. It deletes the functionality from the client of passing in transports explicitly and instead expects the transport to be passed in through options.

Instead of passing in an instance of a transport to the client, we pass in a constructor function. This allows the client to control exactly what options are passed into the transport.

```ts
this._transport = options.transport({ ...options.transportOptions, url });
```
lobsterkatie pushed a commit that referenced this pull request Apr 26, 2022
This PR switches over from the old transports to the new ones. It deletes the functionality from the client of passing in transports explicitly and instead expects the transport to be passed in through options.

Instead of passing in an instance of a transport to the client, we pass in a constructor function. This allows the client to control exactly what options are passed into the transport.

```ts
this._transport = options.transport({ ...options.transportOptions, url });
```
lobsterkatie pushed a commit that referenced this pull request Apr 26, 2022
This PR switches over from the old transports to the new ones. It deletes the functionality from the client of passing in transports explicitly and instead expects the transport to be passed in through options.

Instead of passing in an instance of a transport to the client, we pass in a constructor function. This allows the client to control exactly what options are passed into the transport.

```ts
this._transport = options.transport({ ...options.transportOptions, url });
```
AbhiPrasad added a commit that referenced this pull request May 30, 2022
This PR switches over from the old transports to the new ones. It deletes the functionality from the client of passing in transports explicitly and instead expects the transport to be passed in through options.

Instead of passing in an instance of a transport to the client, we pass in a constructor function. This allows the client to control exactly what options are passed into the transport.

```ts
this._transport = options.transport({ ...options.transportOptions, url });
```
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.

3 participants