Skip to content

feat(remix): Add Remix server SDK #5269

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
Jun 21, 2022
Merged

feat(remix): Add Remix server SDK #5269

merged 4 commits into from
Jun 21, 2022

Conversation

onurtemizkan
Copy link
Collaborator

Part 3 of #4894

Adds server side SDK for error tracking / performance tracing of Remix.

  • Uses Node SDK underneath.
  • For tracing, monkey-patches createRequestHandler from @remix-run/server-runtime which apparently is used by all server-side adapters of Remix.
  • action and loader functions are patched as parameters of createRequestHandler.

Tested:

  • Tracing action / loader
  • Tracing requestHandler
  • With Prisma spans
  • Error Tracking

Link to Transaction
Link to Event

@github-actions
Copy link
Contributor

github-actions bot commented Jun 16, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.35 KB (added)
@sentry/browser - ES5 CDN Bundle (minified) 59.85 KB (added)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.15 KB (added)
@sentry/browser - ES6 CDN Bundle (minified) 53.49 KB (added)
@sentry/browser - Webpack (gzipped + minified) 19.92 KB (added)
@sentry/browser - Webpack (minified) 64.85 KB (added)
@sentry/react - Webpack (gzipped + minified) 19.95 KB (added)
@sentry/nextjs Client - Webpack (gzipped + minified) 43.98 KB (added)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.57 KB (added)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.08 KB (added)

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

I like how simple wrapping the handlers are!


// debugger;
const transaction = hasTracingEnabled()
? startTransaction({
Copy link
Member

Choose a reason for hiding this comment

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

startTransaction should no-op if tracing is not enabled, so we don't need the ternary, we can just always call startTransaction

declare const __SENTRY_DEBUG__: boolean;

/** Flag that is true for debug builds, false otherwise. */
export const IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this file. Please see https://github.com/getsentry/sentry-javascript/blob/master/CONTRIBUTING.md#debug-build-flags for more details.

#5155

We should just be able to use __DEBUG_BUILD__ everywhere now.

Comment on lines 31 to 34
export { ErrorBoundary, withErrorBoundary } from '@sentry/react';
export { remixRouterInstrumentation, withSentryRouteTracing } from './performance/client';
export { BrowserTracing, Integrations } from '@sentry/tracing';
export * from '@sentry/node';
Copy link
Member

Choose a reason for hiding this comment

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

let's move these exports to the top

type AppLoadContext = unknown;
type AppData = unknown;
type RequestHandler = (request: Request, loadContext?: AppLoadContext) => Promise<Response>;
type CreateRequestHandlerFunction = (build: ServerBuild, mode?: string) => RequestHandler;
Copy link
Member

Choose a reason for hiding this comment

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

Are these all vendored in? Can we link to the code + git sha where we did this?

let res: Response | AppData;
const activeTransaction = getActiveTransaction();
const currentScope = getCurrentHub().getScope();

Copy link
Member

Choose a reason for hiding this comment

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

Instead of using optional chaining, let's just early return if there is no activeTransaction. Same if there is no currentScope

}

res = await origFn.call(this, args);
span?.finish();
Copy link
Member

Choose a reason for hiding this comment

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

Should we re-add back the transaction onto the scope?

currentScope.setSpan(activeTransaction);
span.finish();

Copy link
Member

Choose a reason for hiding this comment

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

Why is optional chaining still needed here?

return async function (this: unknown, request: Request, loadContext?: unknown): Promise<Response> {
const currentScope = getCurrentHub().getScope();

// debugger;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// debugger;

@AbhiPrasad AbhiPrasad mentioned this pull request Jun 20, 2022
26 tasks
@AbhiPrasad AbhiPrasad added this to the Sentry Remix SDK milestone Jun 21, 2022
},
"sideEffects": [
"./esm/index.server.js",
"./src/index.server.ts"
Copy link
Member

Choose a reason for hiding this comment

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

Why do these have side effects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I took that from Next.JS SDK.

As I understand, we need to export browser / react stuff from index.server.ts to make TypeScript happy on compile time, but it's not guaranteed that it'll be used on runtime. (index.client.ts is used instead on the demo project).

So my guess is that flagging index.server.* as side effects is to prevent a pre-bundler that may fail TS compilation.

}

res = await origFn.call(this, args);
span?.finish();
Copy link
Member

Choose a reason for hiding this comment

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

Why is optional chaining still needed here?

@AbhiPrasad AbhiPrasad merged commit 45818f3 into master Jun 21, 2022
@AbhiPrasad AbhiPrasad deleted the onur/remix-sdk-server branch June 21, 2022 17:44
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.

2 participants