https://serverless-stack.com/ logo
#sst
Title
# sst
r

Ross Coundon

04/06/2021, 2:02 PM
We use Epsagon for tracing our serverless deployments and to do so we use a serverless framework plugin that automatically wraps each handler function when deploying. Is there an ‘official’ way to do something similar i.e. a plugin framework with SST?
We can get around it my manually wrapping each handler but I like the automated way that doesn’t rely on people remembering to do so
j

Jay

04/06/2021, 2:23 PM
We don’t currently but I know @Frank has some ideas on how we can implement this.
r

Ross Coundon

04/06/2021, 2:24 PM
Ok, cool, I’ll keep my eye out for developments 🙂
f

Frank

04/06/2021, 5:53 PM
Yeah @Ross Coundon that’s a good point. I have seen Datadog has something along that line https://www.npmjs.com/package/datadog-cdk-constructs
So the code looks like:
Copy code
const datadog = new Datadog(this, "Datadog", ...);
datadog.addLambdaFunctions([a list of lambdas]);
The Datadog CDK construct takes in a list of lambda functions and installs the Datadog Lambda Library by attaching the Lambda Layers for Node.js and Python to your functions. It redirects to a replacement handler that initializes the Lambda Library without any required code changes.
Or alternatively, I’m thinking of letting ppl define
wrappers
like:
Copy code
new sst.Function(this, "MyFunction", {
  handler: "src/lambda.main",
  wrappers: [ epsagonWrapper ]
})
Where
easagonWrapper
can just be user defined wrapper function
r

Ross Coundon

04/06/2021, 6:00 PM
That'd work
p

Pål Brattberg

04/06/2021, 6:25 PM
That'd be an alternative way of doing middleware then as well?
f

Frank

04/06/2021, 6:36 PM
Yeah, and I’ve thought about adding default wrappers to functions for things most ppl probably need by default: like wrapping aws-sdk import with aws-xray-sdk; console.log full event and response when developing (ie. sst start); etc. And have a way for them to opt out.
p

Pål Brattberg

04/06/2021, 6:37 PM
Very nice!
f

Frank

04/06/2021, 6:39 PM
Yeah.. I’ll need to get more feedback from u guys when i get to it 🙏
j

justindra

04/08/2021, 9:04 PM
Wrappers would be cool. We actually have our own set of wrappers in an internal library to convert requests coming in and events from dynamodb hooks or sqs queues so it's all consistent and also to wrap it all with sentry for a catch all.
f

Frank

04/09/2021, 8:24 AM
@justindra Yeah definitely a common use case.
3 Views