Serverless Framework

Epsagon's plugin for the Serverless Framework that enables tracing for your functions.


Open-Source Project

This is an open-source project which can be found at our GitHub repository.


Install the Epsagon Agent

npm install epsagon
pip install epsagon

// note: if you are using the `serverless-python-requirements`
// plugin, please also add `epsagon` to your `requirements.txt` file

Install The Plugin

sls plugin install --name serverless-plugin-epsagon
npm install --save-dev serverless-plugin-epsagon

# note: add the plugin to your `serverless.yml` file

When installing with NPM, add the plugin to your serverless.yml file:

  - serverless-plugin-epsagon

For the best results, make sure this is the first plugin specified in your
plugins list.


When using this plugin, make sure to use just this method for tracing. You don't need to manually copy or import the epsagon library to your code, nor enable the auto-tracing.

To get started with the plugin, open your serverless.yml, and add the following snippet in the custom section:

    token: <epsagon-token>
    appName: <app-name-stage>

You can find your token in the Epsagon settings page.

The plugin will be activated automatically during sls deploy,
sls package, and sls invoke local events automatically.

To cleanup any Epsagon-related files run sls epsagon clean and it will clean up files after deployment (can happen when you stop in the middle of a deployment)


Service Level Options

These options are defined at the service level, under the custom.epsagon section
of your serverless.yml file. Any function level option will override options
defined here.

Available options:

ParameterMandatory/OptionalDefault ValueDescription
tokenMandatory-Epsagon account token. You can find your token in the Epsagon settings page.
appNameOptional``Application name that will be set for traces
disableOptionalfalseWhen set to true it disables Epsagon for the entire service. When this option is active wrapping your functions with Epsagon will be skipped.
metadataOnlyOptionalfalseWhether to send only the metadata (true) or also the payloads (false)
handlersDirNameOptionalepsagon_handlersCustomize the name of the directory Epsagon stores its handlers in. Do not use this option unless you know what you are doing.
packageJsonPathOptional./package.jsonCustomize the path of your package.json
collectorURLOptional-The address of the trace collector to send trace to
ignoredKeysOptional-May contain strings (will perform a loose match, so that First Name also matches first_name)
urlsToIgnoreOptional-Ignore HTTP calls to specific domains
labelsOptional[]Global labels applied to all traces. For example "[['key', 'val']]". (Not available for Python)

Function Level Options

These options are defined at the function level, under the epsagon member of your function in the serverless.yml file.
Configuring the values at the function level, will override the service level configurations.

For example:

    handler: handler.handle
      wrapper: lambda_wrapper
      disable: true

Available options:

ParameterMandatory/OptionalDefault ValueDescription
disableOptionalfalseWhen set to true it disables Epsagon for the function.
appNameOptional``Application name that will be set for traces
wrapperOptionallambda_wrapper/lambdaWrapper - The wrapper to use to wrap this function. See wrappers

Tracing Wrappers

Use these wrappers to trace functions.

  • Python functions:
    • lambda_wrapper - regular lambda wrapper
    • step_lambda_wrapper - Used to wrap step functions
    • python_wrapper - Used to wrap generic Python functions (doesn't have to run on Lambda)
  • Node.js functions:
    • lambdaWrapper - regular lambda wrapper
    • stepLambdaWrapper - Used to wrap step functions
    • nodeWrapper - Used to wrap generic Node functions (doesn't have to run on Lambda)


Does this plugin work with webpack?

Yes. you can use webpack or any serverless plugins utilizing webpack with
this plugin. Just make sure to specify this plugin before any other
plugin in your serverless.yml:

  - serverless-plugin-epsagon
  - serverless-webpack
  - any-other-plugin

In order to get the full tracing ability of epsagon, please specify any packages
that should be traced (e.g. aws-sdk, pg, mongodb) as external in your webpack

Is TypeScript supported?

Yes. Just make sure to specify this plugin first in your serverless.yml

Unable to import module epsagon_handlers error:

During deployment, the plugin creates epsagon_handlers/ dir to wrap the function. Please make sure this dir is not excluded in the configuration.

[Node.js] Cannot find module 'epsagon' error:

node_modules must be included in the function package being deployed, make sure that node_modules is not excluded somewhere.

An example below of how your serverless.yml could look like:

# ...

  individually: true
    - ./**  # excludes everything
  include:  # include necessary dependencies for your function
    - "node_modules/**"
    - "epsagon_handlers/**"
  # ...
    handler: handler.handle
          - handler.js # include only your function
# ...

[Node.js] Epsagon's Node library must be installed in order to use this plugin! error:

The plugin verifies that epsagon module exists on your ./package.json before deployment.
In some cases, the package.json might be in a different path. You can easily update it using packageJsonPath parameter, for example:

    packageJsonPath: `../../dir/package.json`

Can I use this plugin together with another methods of tracing using Epsagon?

No. Make sure to choose only a single way to trace your functions.

In my AWS Lambda I'm accessing a local file. Using the plugin causes an issue.

If you are using a relative path to a local file in your Lambda function, using the plugin might cause some issues.
The reason for that is that the plugin changes the location of your Lambda handler.

Getting Help

If you have any issue around using the library or the product, please don't hesitate to:

  • Use the documentation.
  • Use the help widget inside the product.
  • Open an issue in GitHub.

Opening Issues

If you encounter a bug with the Epsagon library for Node.js, we want to hear about it.

When opening a new issue, please provide as much information about the environment:

  • Library version, runtime version, dependencies, etc.
  • Snippet of the usage.
  • A reproducible example can really help.

The GitHub issues are intended for bug reports and feature requests.
For help and questions about Epsagon, use the help widget inside the product.


Provided under the MIT license. See LICENSE for details.

Copyright 2020, Epsagon

Did this page help you?