GithubHelp home page GithubHelp logo

isabella232 / serverless-plugin-datadog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from datadog/serverless-plugin-datadog

0.0 0.0 0.0 362 KB

Serverless plugin to automagically instrument your Lambda functions with Datadog

License: Apache License 2.0

TypeScript 88.35% JavaScript 0.62% Shell 6.06% Python 4.96%

serverless-plugin-datadog's Introduction

Datadog Serverless Plugin

serverless build Code Coverage NPM Slack License

Datadog recommends the Serverless Framework Plugin for developers using the Serverless Framework to deploy their serverless applications. The plugin automatically configures ingestion of metrics, traces, and logs from your serverless applications by:

  • Installing and configuring the Datadog Lambda library for your Python and Node.js Lambda functions.
  • Enabling the collection of enhanced Lambda metrics and custom metrics from your Lambda functions.
  • Managing subscriptions from the Datadog Forwarder to your Lambda function log groups.

Getting started

To quickly get started, follow the installation instructions for Python or Node.js, and view your function's enhanced metrics, traces, and logs in Datadog. These instructions will get you a basic working setup.

More configuration options

To further configure your plugin, use the following custom parameters in your serverless.yml:

Parameter Description
flushMetricsToLogs Send custom metrics by using logs with the Datadog Forwarder Lambda function (recommended). Defaults to true. If you disable this parameter, it's required to set the parameters site and apiKey (or apiKMSKey if encrypted).
site Set which Datadog site to send data, only needed when flushMetricsToLogs is false. Defaults to datadoghq.com. Set to datadoghq.eu for the Datadog EU site.
apiKey Datadog API Key, only needed when flushMetricsToLogs is false. For more information about getting a Datadog API key, see the API key documentation.
apiKMSKey Datadog API Key encrypted using KMS. Use this parameter in place of apiKey when flushMetricsToLogs is false, and you are using KMS encryption.
addLayers Whether to install the Datadog Lambda library as a layer. Defaults to true. Set to false when you plan to package the Datadog Lambda library to your function's deployment package on your own so that you can install a specific version of the Datadog Lambda library (Python or Node.js).
logLevel The log level, set to DEBUG for extended logging. Defaults to info.
enableXrayTracing Set true to enable X-Ray tracing on the Lambda functions and API Gateway integrations. Defaults to false.
enableDDTracing Enable Datadog tracing on the Lambda function. Defaults to true. When enabled, it's required to set the forwarder parameter.
forwarder Setting this parameter subscribes the Lambda functions' CloudWatch log groups to the given Datadog forwarder Lambda function. Required when enableDDTracing is set to true.
enableTags When set, automatically tag the Lambda functions with the service and env tags using the service and stage values from the serverless application definition. It does NOT override if a service or env tag already exists. Defaults to true.
injectLogContext When set, the lambda layer will automatically patch console.log with Datadog's tracing ids. Defaults to true.

To use any of these parameters, add a custom > datadog section to your serverless.yml similar to this example:

custom:
  datadog:
    flushMetricsToLogs: true
    apiKey: "{Datadog_API_Key}"
    apiKMSKey: "{Encripted_Datadog_API_Key}"
    addLayers: true
    logLevel: "info"
    enableXrayTracing: false
    enableDDTracing: true
    forwarder: arn:aws:lambda:us-east-1:000000000000:function:datadog-forwarder
    enableTags: true
    injectLogContext: true

Note: If you use webpack, Datadog recommends using the prebuilt layers by setting addLayers to true, which is the default, and add datadog-lambda-js and dd-trace to the externals section of your webpack config.

TypeScript

If you are using serverless-typescript, make sure that serverless-datadog is above the serverless-typescript entry in your serverless.yml. The plugin will automatically detect .ts files.

plugins:
  - serverless-plugin-datadog
  - serverless-typescript

If you use TypeScript, you may encounter the error of missing type definitions. A missing type definition happens when you use the prebuilt layers (for example, set addLayers to true, which is the default) and need to import helper functions from the datadog-lambda-js and dd-trace packages to submit custom metrics or instrument a specific function. To resolve the error, add datadog-lambda-js and dd-trace to the devDependencies list of your project's package.json.

Webpack

dd-trace is known to be not compatible with webpack due to the use of conditional import and other issues. If using webpack, make sure to mark datadog-lambda-js and dd-trace as externals for webpack, so webpack knows these dependencies will be available in the runtime. You should also remove datadog-lambda-js and dd-trace from package.json and the build process to ensure you're using the versions provided by the Datadog Lambda Layer.

serverless-webpack

If using serverless-webpack, make sure to also exclude datadog-lambda-js and dd-trace in your serverless.yml in addition to declaring them as external in your webpack config file.

webpack.config.js

var nodeExternals = require('webpack-node-externals')

module.exports = {
  // we use webpack-node-externals to excludes all node deps.
  // You can manually set the externals too.
  externals: [nodeExternals(), 'dd-trace', 'datadog-lambda-js'],
}

serverless.yml

custom:
  webpack:
    includeModules:
      forceExclude:
        - dd-trace
        - datadog-lambda-js

Forwarder

The Datadog Forwarder Lambda function needs to be installed and subscribed to your Lambda functions' log groups. The plugin automatically creates the log subscriptions when the Forwarder's ARN is supplied via the forwarder option.

If you run into the following error, double check the supplied Forwarder ARN is correct and ensure it is from the same region and account where your serverless application is deployed.

An error occurred: GetaccountapiLogGroupSubscription - Could not execute the lambda function. Make sure you have given CloudWatch Logs permission to execute your function. (Service: AWSLogs; Status Code: 400; Error Code: InvalidParameterException).

Opening Issues

If you encounter a bug with this package, let us know by filing an issue! Before opening a new issue, please search the existing issues to avoid duplicates.

When opening an issue, include your Serverless Framework version, Python/Node.js version, and stack trace if available. Also, please include the steps to reproduce when appropriate.

You can also open an issue for a feature request.

Contributing

If you find an issue with this package and have a fix, please feel free to open a pull request following the procedures.

License

Unless explicitly stated otherwise, all files in this repository are licensed under the Apache License Version 2.0.

This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2019 Datadog, Inc.

serverless-plugin-datadog's People

Contributors

darcyraynerdd avatar tianchu avatar czechh avatar sfirrin avatar hghotra avatar adambartholomew avatar dependabot[bot] avatar dls314 avatar dylanlovescoffee avatar jacksondavenport avatar julienpavon avatar nhinsch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.