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(node): Add Spotlight option to Node SDK #9629

Merged
merged 7 commits into from
Nov 22, 2023
Merged

Conversation

HazAT
Copy link
Member

@HazAT HazAT commented Nov 21, 2023

This PR adds a new top level option called spotlight to Node init options. Under the hood, if this option is true,

  • all integrations will be forcefully initialized . This ensures that without a DSN, we still capture and process events (but simply don't send them to Sentry)
  • a new Spotlight integration is added. This integration will make a http post request to the sidecar URL. Either we take the default sidecar URL or users provide their own URL:
// enable/disable
Sentry.init({
  spotlight: process.env.NODE_ENV === "development"
});

// enbale by setting a custom URL
Sentry.init({
  spotlight: process.env.NODE_ENV === "development" ? 'http://localhost:7777' : false 
});

This option should also work in Node Experimental, given that Node experimental just calls the node init function.

@dcramer
Copy link
Member

dcramer commented Nov 21, 2023

Just FYI weve agreed upon this interface for Spotlight through all SDKs. If anyone thinks we're missing anything please chime in, but we are intentionally not going to use the integrations interface as its error-prone for customers.

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.

UPDATE: This comment is outdated, it seems like we need the top level option after all.

I still think this should be an integration for now rather than immediately a top level option. Reasons:

  • A lot of SDKs inherit from Node (e.g. serverless) and we can't guarantee that this works (or doesn't at least cause problems) everywhere but the option will be there.
  • fetch only works natively in Node 18+, so the current implementation will not work in our older supported Node versions
  • Instead of jumping through the hoops of getting this bullet proof within the Node SDK right now, let's start with the integration where we can more easily say "Only use this with Node 18+ and in Dev mode". We can still make this a top-level option later on.

Maybe I'm overthinking but I wanna avoid adding something rushed to the SDK (or other non-JS SDKs for that matter) that can very well stand on its own.

Or IOW, does

Sentry.init({
  spotlight: true
})

// vs

Sentry.init({
  integrations: [new Spotlight()]
})

really justify this effort?

@Lms24 Lms24 marked this pull request as ready for review November 22, 2023 12:06
@Lms24 Lms24 requested a review from mydea November 22, 2023 12:07
* @returns
*/
export class Spotlight implements Integration {
public name = 'Spotlight';
Copy link
Member

Choose a reason for hiding this comment

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

we should set static id as well, shouldn't we?

Copy link
Member

Choose a reason for hiding this comment

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

Good point, added it

Copy link
Contributor

github-actions bot commented Nov 22, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 66.02 KB (+0.12% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 56.1 KB (+0.14% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.1 KB (+0.27% 🔺)
@sentry/browser - Webpack (gzipped) 21.41 KB (+0.39% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 62.42 KB (+0.1% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 29.23 KB (+0.29% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 21.35 KB (+0.35% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 196.93 KB (+0.16% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 88.74 KB (+0.35% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 63.71 KB (+0.49% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.96 KB (+0.3% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 66.31 KB (+0.12% 🔺)
@sentry/react - Webpack (gzipped) 21.45 KB (+0.39% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 83.08 KB (+0.11% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 48.25 KB (+0.18% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 16.19 KB (+0.55% 🔺)

Comment on lines +84 to +94
res => {
res.on('data', () => {
// Drain socket
});

res.on('end', () => {
// Drain socket
});
res.setEncoding('utf8');
},
);
Copy link
Member

Choose a reason for hiding this comment

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

tbh, I'm not sure if we need this but I found the same logic in the Http transport request creation function.

@HazAT HazAT changed the title feat: Add spotlight option to Node SDK feat: Add Spotlight option to Node SDK Nov 22, 2023

if (options.spotlight) {
const client = getCurrentHub().getClient();
if (client && client.addIntegration) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we check if this has run, and only then call this? Even if we check this inside of setupIntegrations(), may be a bit cleaner I'd say?

Copy link
Member

Choose a reason for hiding this comment

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

Discussed this offline quickly: Checking this is not easy outside the BaseClient class. Given this call no-ops if integrations were already set up, let's keep it as is for now.

packages/node/src/types.ts Outdated Show resolved Hide resolved
@Lms24 Lms24 changed the title feat: Add Spotlight option to Node SDK feat(node): Add Spotlight option to Node SDK Nov 22, 2023
@Lms24 Lms24 merged commit 92c9fbb into develop Nov 22, 2023
67 checks passed
@Lms24 Lms24 deleted the feat/spotlight-option branch November 22, 2023 16:10
const req = http.request(
{
method: 'POST',
path: '/stream',

Choose a reason for hiding this comment

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

Looks like spotlightUrl.path should be /stream already? Is hardcoding intentional?

Copy link
Member

Choose a reason for hiding this comment

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

If I'm not mistaken (it's laaate here 😅) spotlightUrl is the optionally user configurable part of the URL - protocol, host and port. The path I think we're going to mandate to be /stream.

Copy link
Member

Choose a reason for hiding this comment

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

Id just make it the full URL tbqh. That makes it easier for us to swap out different proxies later if we wanted.

e.g. make it http://localhost:8969/stream as the default (or w/e it is)

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.

5 participants