npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-plugin-lambda-otel

v1.0.0

Published

A Serverless Framework plugin for enabling AWS OTEL Lambda layer on Lambda services

Downloads

164

Readme

serverless-plugin-lambda-otel

A Serverless Framework plugin for enabling AWS OTEL Lambda layer on Lambda services

npm

Enables AWS Lambda OTEL Layer (https://aws.amazon.com/blogs/mt/introducing-cloudwatch-lambda-insights/) for the entire Serverless stack functions or individual functions.

By default, enabling this plugin will add the AWS OTEL layer, which will instrument your code and export traces to X-Ray. If you want to use this layer for exporting traces to other providers, such as Prometheus, Datadog etc, check the layer documentation on how to configure custom exporters (https://aws-otel.github.io/docs/getting-started/lambda).

This plugin implements the instructions as can be found at https://aws-otel.github.io/docs/getting-started/lambda/lambda-js

(This plugin was highly inspired on https://github.com/awslabs/serverless-plugin-lambda-insights)

Why use AWS OTEL Lambda layer

You can use this AWS Layer on your Lambda services so they can generate and publish OTEL traces for dependencies called within your Lambda function without manual instrumentation. For example, after using it, X-Ray traces dashboard will show segments related to external APIs your NodeJS based Lambda service is calling along with its latency, number of calls and status.

AWS OTEL Lambda


Getting started

Installation

This Plugin requires a Serverless Framework version of >= 2.0.0.

npm install --save-dev serverless-plugin-lambda-otel

add Plugin to your serverless.yml in the plugins section.

Minimal Usage

Example serverless.yml:

provider:
  name: aws
  tracing:
    apiGateway: true
    lambda: true

plugins:
  - serverless-plugin-lambda-otel

functions:
  hello:
    handler: handler.hello

custom:
  lambdaOTEL:
    enable: true
  • With this configuration you will enable OTEL layer and X-Ray tracing by default on all the functions

Functionality

The plugin will enable Lambda OTEL instrumentation by adding a Lambda Layer (see Layer Details and Versions) and adding necessary permissions for making X-Ray traces work out-of-the-box.

You can check in your AWS Console: go to AWS Lambda -> select your Lambda function -> Layers

Usage

Example serverless.yml:

service: your-great-sls-service

provider:
  name: aws
  stage: dev
  tracing:
    apiGateway: true #for enabling X-Ray tracing (nor required if not using X-Ray)
    lambda: true #for enabling X-Ray tracing (nor required if not using X-Ray)

plugins:
  - serverless-plugin-lambda-otel

functions:
  mainFunction: #inherits tracing settings from "provider"
    otelEnable: true # defaults to custom.lambdaOTEL.enable
    otelVersion: '1-7-0' # defaults to custom.lambdaOTEL.version
    handler: src/app/index.handler
  secondFunction: #inherits tracing settings from "provider"
    otelEnable: false #explicitly disable AWS OTEL Layer for this function (this will override default settings)
    handler: src/app/index.handler

custom:
  lambdaOTEL:
    enable: true # enables Lambda OTEL layer for all your functions. defaults to false
    version: '1-8-0' # defaults to the latest version for the specific runtime (nodejs, python, java or collector) when the plugin was published
    xrayPolicy: false # attach X-Ray Managed Policy to functions. defaults to true

Example

You can find an example in the example folder of this repository. Run it with the following command.

cd example; serverless deploy

  • This will deploy a hello-world Lambda function with Lambda OTEL layer enabled, which will give you X-Ray instrumentation by default.

  • After the deployment, call the endpoint URL that is displayed

curl https://[SOMETHING].execute-api.us-east-1.amazonaws.com/dev/hello
  • It should return a random user data, which was gotten from the service https://randomuser.me/api/

  • Open the AWS Console and check X-Ray traces. You should be able to inspect the calls to your service and to randomuser.me apis (the tracing to the external API is only possible due to the OTEL layer instrumentation)


Want to contribute?

This is your repo - just go head and create a pull request. See also CONTRIBUTING for more introductions.

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT License. See the LICENSE file.