:wave: Hi, I'd like to add Datadog monitoring to ...
# help
d
đź‘‹ Hi, I'd like to add Datadog monitoring to our stack. I see that Datadog has a macro to help set things up for AWS CDK. I'm assuming that I can use it with SST by migrating the code somehow? Sorry, all of this is brand new to me. Datadog Macro: https://github.com/DataDog/datadog-cloudformation-macro/tree/master/serverless
Copy code
// Datadog's AWS CDK macro:
from aws_cdk import core

class CdkStack(core.Stack):
  def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
    super().__init__(scope, id, **kwargs)
    self.add_transform("DatadogCfnMacro")

    mapping = core.CfnMapping(self, "Datadog", 
      mapping={
        "Parameters": { 
          "enableDDTracing": true,
          "flushMetricsToLogs": true,
          "stackName": self.stackName,
          "forwarderArn": "arn:aws:lambda:<REGION>:<ACCOUNT-ID>:function:datadog-forwarder",
          "service": "my-cdk-app",
          [...]
        }
      })
f
Hey @Drew, lemme take a quick look at link you sent
d
Thanks Frank!
f
The snippet u sent is Python.. is ur Lambda in Python?
d
Okay, so if I convert that idea into Node/TS it should work?
Yes, our Lambda is in Node
d
Down in the docs, I see a typescript section.
f
yeah.. @Dennis Dang +1
d
Okay, cool. We'll give it a try
f
Something like this:
Copy code
export default class MyStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    this.addTransform("DatadogServerless");

    new cdk.CfnMapping(this, "Datadog", {
      mapping: {
        Parameters: {
          nodeLayerVersion: "<LAYER_VERSION>",
          forwarderArn: "<FORWARDER_ARN>",
          stackName: this.stackName,
          service: "<SERVICE>", // Optional
          env: "<ENV>", // Optional
          // For additional parameters, see the Configuration section
        },
      },
    });
  }
}
I haven’t looked at what’s going on inside
addTransform
but it should work? let’s see
d
Beauty!
f
And for the
service
param, if you want to set that to the SST app name, you can do:
Copy code
service: scope.name,
d
Nice!
f
and to set
env
as the current stage:
Copy code
env: this.stage
d
ahh ty. Drew and I are on the same team, with Dmitry. Steadily migrating our pieces over.
d
Thanks Frank, that seemed to work. I have a little more to add to get the whole thing going.
f
Awesome! If you don’t mind, when you get a chance could you shared the bit that got it to work? It’d be helpful if we added that to our docs.
d
Totally
d
awesome