sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Exclude optional performance instrumentation by default for AWS Serverless

Open jd-carroll opened this issue 1 year ago • 6 comments

Problem Statement

Opentelemetry adds a massive amount of overhead. The screen shot below represents a minimized / treeshook lambda built with esbuild that has very little of its own code. image

I understand some of the challenges here (ie. nothing is free or magic), but Sentry + Opentelemetry is > 50% of the bundled lambda.

For opentelemetry specifically, it bundles a whole series of instrumentation hooks which will never be consumed. image

Of the 16 bundled instrumentation hooks, we will only use three of them:

  • instrumentation-aws-sdk
  • instrumentation-http
  • instrumentation-aws-lambda

There is a guide which mentions "customizing" the opentelemetry configuration: https://docs.sentry.io/platforms/javascript/guides/node/migration/v7-to-v8/v8-opentelemetry/#custom-opentelemetry-setup

But it seems incomplete. It is not clear how or where I would instantiate the three instrumentation providers.

Solution Brainstorm

It would be great if there was a complete example of an aws lambda which configures only three instrumentation providers:

  • instrumentation-aws-sdk
  • instrumentation-http
  • instrumentation-aws-lambda

This should be a "gold-standard" for how to configure sentry for aws-lambda, because even with full ESM + treeshaking + minification the size of Sentry + Opentelemetry is a substantial problem.

jd-carroll avatar May 12 '24 04:05 jd-carroll

Thank you for raising this, this is a valid point. We will adjust this so that we do not include all integrations by default for serverless, meaning you'll have to manually add the DB integrations etc. you care about.

mydea avatar May 13 '24 09:05 mydea

We just shipped v8.0.0, where we do not automatically add all auto Instrumentation anymore. This should help to reduce the default bundle size!

mydea avatar May 13 '24 15:05 mydea

Amazing, thank you for getting this in last minute :heart:

Separately, it would be nice to have a little more detail to the instrumentation customization guide.

jd-carroll avatar May 13 '24 16:05 jd-carroll

@mydea I just tried v8.0.0 🎊 ... and the problem still exists.

The core of the issue is that they are "statically" imported and still on a valid code path: image

Here is the latest screenshot from esbuild output: image image

So there is no difference, despite the changes you included in v8.

Would it be possible to create a "node-core" package that is most of the current "node" package? The difference being, using @sentry/node would be an instantiation of "node-core" and contain references to all of the standard instrumentation. But then "serverless" would be an instantiation of "node-core" (instead of "node") and only have reference to:

  • instrumentation-aws-sdk
  • instrumentation-http
  • instrumentation-aws-lambda

Then you would be required to add any additional if you wanted.

jd-carroll avatar May 13 '24 16:05 jd-carroll

So just the presence/exporting of certain things should normally not affect the bundle size. As long as the code is not used, it should be tree-shaken away. How do you build your lambda function, if I may ask? Maybe there is some config option missing to ensure tree shaking works as expected 🤔

EDIT: Ignore this, I've seen there is a new issue with newer info.

mydea avatar May 14 '24 08:05 mydea

Actually, I just noticed my "fix" did not really fix this. I will make sure to actually fix the bundle size, sorry about that...

mydea avatar May 14 '24 08:05 mydea

This is resolved, thank you! ❤️

jd-carroll avatar May 23 '24 16:05 jd-carroll