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: add sentry #59

Merged
merged 7 commits into from
Dec 5, 2022
Merged

feat: add sentry #59

merged 7 commits into from
Dec 5, 2022

Conversation

vasco-santos
Copy link
Contributor

@vasco-santos vasco-santos commented Dec 1, 2022

@seed-deploy seed-deploy bot temporarily deployed to pr59 December 1, 2022 09:58 Inactive
@seed-deploy
Copy link

seed-deploy bot commented Dec 1, 2022

View stack outputs

@seed-deploy seed-deploy bot temporarily deployed to pr59 December 1, 2022 10:17 Inactive
@vasco-santos vasco-santos marked this pull request as ready for review December 1, 2022 10:17
stacks/config.js Outdated
/**
* @param {import('@serverless-stack/resources').Stack} stack
*/
export function setupSentry (stack) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe we should check stage here instead? thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, we're using the config file set config depending on the stage already, so let's do the if (!app.local) check once here rather than in every stack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done ✨

@vasco-santos vasco-santos requested a review from olizilla December 1, 2022 10:47
Copy link
Contributor

@olizilla olizilla left a comment

Choose a reason for hiding this comment

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

Use app.local to determine if we want Sentry. There isn't really a dev env. When i deploy locally the scope is olizilla.

app.local tells us if the deploy is in dev mode from running sst start, rather than a deploy. I think it'd be fine to put that check once in the config file as that is how we do other per stage config.

From the blog post it looks like you chose different options, can you explain a little about NODE_OPTIONS: "-r @sentry/serverless/dist/awslambda-auto", ? what does this do? Why not use it? Does it auto init with the sentry env vars?

@seed-deploy seed-deploy bot temporarily deployed to pr59 December 1, 2022 13:09 Inactive
@vasco-santos
Copy link
Contributor Author

From the blog post it looks like you chose different options, can you explain a little about NODE_OPTIONS: "-r @sentry/serverless/dist/awslambda-auto", ? what does this do? Why not use it? Does it auto init with the sentry env vars?

I think that I removed it involuntarily, because I thought I had it. Adding it back, I read that it sets automatic instrumentation of Lambda functions in Sentry. But in practise we need to see what it sets up when we actually have events there. There are NO nice docs for it, just the blogpost I linked

@vasco-santos vasco-santos requested a review from olizilla December 1, 2022 13:13
@seed-deploy seed-deploy bot temporarily deployed to pr59 December 1, 2022 14:20 Inactive
@olizilla
Copy link
Contributor

olizilla commented Dec 1, 2022

i'm trying to understand what it does. I can see

When Sentry is added to a Lambda function, the following modifications are made to your Lambda functions:

  • NODE_OPTIONS: This is to preload the awslambda-auto module which will automatically initialize Sentry
  • SENTRY_DSN: This is set to the DSN of your project
  • SENTRY_TRACES_SAMPLE_RATE: This sets the sampling rate for transactions. You can manually edit your environment variables if you want a different sampling rate.

and

import * as Sentry from './index';

const lambdaTaskRoot = process.env.LAMBDA_TASK_ROOT;
if (lambdaTaskRoot) {
  const handlerString = process.env._HANDLER;
  if (!handlerString) {
    throw Error(`LAMBDA_TASK_ROOT is non-empty(${lambdaTaskRoot}) but _HANDLER is not set`);
  }

  Sentry.AWSLambda.init({
    _invokedByLambdaLayer: true,
  });

  Sentry.AWSLambda.tryPatchHandler(lambdaTaskRoot, handlerString);
} else {
  throw Error('LAMBDA_TASK_ROOT environment variable is not set');
}

...given we are manually wrapping and initialising sentry and have included @sentry/serverless in our deps, I think we should drop the Lambda layer config step. I understand the purpose of lambda layers is to capture some common dependency and init step and make it shareable between lambdas... but we're not using it... its not clear what would happen if we use it and also include the dependency ourselves.

@vasco-santos
Copy link
Contributor Author

vasco-santos commented Dec 1, 2022

It is weird that that they recommend both things in their (it is sentry's own) blogpost and then only one is needed.

Did you setup this for pickup/linkdex? I saw w3up also uses both things:

I can definitely try without it first and report back if it works. For this, I can add a simple route handler in our API that throws an Error

@olizilla
Copy link
Contributor

olizilla commented Dec 1, 2022

The blogpost doesn't say to install @sentry/serverless... it skips straight to "now import this dep"... and i believe the dep will magically be available becuase that's what layers are used for.

@olizilla
Copy link
Contributor

olizilla commented Dec 1, 2022

I can add a simple route handler in our API that throws an Error

Yes please. This has been really helpful for testing Sentry in the web3.storage api

@seed-deploy seed-deploy bot temporarily deployed to pr59 December 2, 2022 13:11 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr59 December 2, 2022 13:23 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr59 December 2, 2022 13:36 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr59 December 2, 2022 13:47 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr59 December 2, 2022 13:49 Inactive
@seed-deploy seed-deploy bot temporarily deployed to pr59 December 2, 2022 13:54 Inactive
@vasco-santos
Copy link
Contributor Author

@olizilla great instinct!

Looks like Lambda layer is not really required. We only need to do:

stack.addDefaultFunctionEnv({
    SENTRY_DSN,
  })

within the stack, so that functions are able to get this. Otherwise, they do not send nothing to sentry.

See https://sentry.io/organizations/protocol-labs-it/issues/3783223576/?project=4504253926539264&query=is%3Aunresolved&referrer=issue-stream

@vasco-santos
Copy link
Contributor Author

Also, will keep /error to test in staging and make sure everything is also good there


import parseSqsEvent from '../utils/parse-sqs-event.js'

import { writeSatnavIndex } from '../index.js'

Sentry.AWSLambda.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this is gonna send telemetry to sentry from every invocation... this opts us in to Sentry perf monitoring where it tracks the response time of every request rather than just errors. The sample rate of 1 means "send to sentry for every request, no filtering"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I guess we can tweak or disable when launching or after we understand better our performance profile

Copy link
Contributor

@olizilla olizilla left a comment

Choose a reason for hiding this comment

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

Note that SENTRY_DSN was already copied over from w3up when we set up upload-api in seed.run, so that value needs to be replaced with a new one that is specifically for upload-api

@vasco-santos
Copy link
Contributor Author

Note that SENTRY_DSN was already copied over from w3up when we set up upload-api in seed.run, so that value needs to be replaced with a new one that is specifically for upload-api

I have set a new one last week for new project

Co-authored-by: Oli Evans <oli@protocol.ai>
@seed-deploy seed-deploy bot temporarily deployed to pr59 December 5, 2022 14:36 Inactive
@vasco-santos vasco-santos merged commit c25e879 into main Dec 5, 2022
@vasco-santos vasco-santos deleted the feat/add-sentry branch December 5, 2022 14:39
vasco-santos added a commit that referenced this pull request Dec 8, 2022
This was missing from #59 and errors happening within ucanto service
were not being propagated to sentry
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.

Wire up Sentry
2 participants