Tracer for module requires/imports to optimize coldstarts in serverless

Overview

treq

workflow npm version license

treq is a library to automatically trace requires/imports in your serverless applications and gives you insights about the most expensive modules in terms of coldstart overhead.

START RequestId: 7419d6fb-7dcb-4c53-a689-0d1d352328bc Version: $LATEST
2022-03-28T20:28:47.740Z	undefined	INFO	|-- require('/var/task/index.js') took 630.785845 ms
2022-03-28T20:28:47.740Z	undefined	INFO	..|-- require('@aws-sdk/client-dynamodb') took 282.050937 ms
2022-03-28T20:28:47.740Z	undefined	INFO	....|-- require('./DynamoDB') took 262.586494 ms
2022-03-28T20:28:47.740Z	undefined	INFO	......|-- require('./commands/BatchExecuteStatementCommand') took 54.849051 ms
2022-03-28T20:28:47.740Z	undefined	INFO	........|-- require('@aws-sdk/smithy-client') took 10.210297 ms
2022-03-28T20:28:47.740Z	undefined	INFO	........|-- require('../protocols/Aws_json1_0') took 25.35611 ms
2022-03-28T20:28:47.740Z	undefined	INFO	..........|-- require('uuid') took 11.320902 ms
2022-03-28T20:28:47.740Z	undefined	INFO	......|-- require('./DynamoDBClient') took 187.273312 ms
2022-03-28T20:28:47.740Z	undefined	INFO	........|-- require('@aws-sdk/config-resolver') took 12.8885 ms
2022-03-28T20:28:47.740Z	undefined	INFO	........|-- require('@aws-sdk/middleware-endpoint-discovery') took 12.118507 ms
2022-03-28T20:28:47.740Z	undefined	INFO	........|-- require('@aws-sdk/middleware-retry') took 13.529461 ms
2022-03-28T20:28:47.740Z	undefined	INFO	........|-- require('@aws-sdk/middleware-signing') took 17.70112 ms
2022-03-28T20:28:47.740Z	undefined	INFO	..........|-- require('./configurations') took 14.718523 ms
2022-03-28T20:28:47.740Z	undefined	INFO	............|-- require('@aws-sdk/signature-v4') took 11.853916 ms
2022-03-28T20:28:47.740Z	undefined	INFO	..............|-- require('./SignatureV4') took 10.149309 ms
2022-03-28T20:28:47.740Z	undefined	INFO	........|-- require('./runtimeConfig') took 123.567573 ms
2022-03-28T20:28:47.740Z	undefined	INFO	..........|-- require('@aws-sdk/client-sts') took 120.895623 ms
2022-03-28T20:28:47.740Z	undefined	INFO	............|-- require('./STS') took 116.251668 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..............|-- require('./commands/AssumeRoleCommand') took 22.53696 ms
2022-03-28T20:28:47.741Z	undefined	INFO	................|-- require('../protocols/Aws_query') took 20.750245 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..................|-- require('entities') took 14.045998 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..............|-- require('./STSClient') took 89.669653 ms
2022-03-28T20:28:47.741Z	undefined	INFO	................|-- require('./runtimeConfig') took 87.875766 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..................|-- require('@aws-sdk/credential-provider-node') took 84.898272 ms
2022-03-28T20:28:47.741Z	undefined	INFO	....................|-- require('./defaultProvider') took 83.672074 ms
2022-03-28T20:28:47.741Z	undefined	INFO	......................|-- require('@aws-sdk/credential-provider-ini') took 76.227651 ms
2022-03-28T20:28:47.741Z	undefined	INFO	........................|-- require('./fromIni') took 75.707995 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..........................|-- require('./resolveProfileData') took 70.243135 ms
2022-03-28T20:28:47.741Z	undefined	INFO	............................|-- require('./resolveAssumeRoleCredentials') took 12.684291 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..............................|-- require('./resolveCredentialSource') took 12.257091 ms
2022-03-28T20:28:47.741Z	undefined	INFO	................................|-- require('@aws-sdk/credential-provider-imds') took 11.887286 ms
2022-03-28T20:28:47.741Z	undefined	INFO	............................|-- require('./resolveSsoCredentials') took 54.422646 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..............................|-- require('@aws-sdk/credential-provider-sso') took 53.719582 ms
2022-03-28T20:28:47.741Z	undefined	INFO	................................|-- require('./fromSSO') took 52.288542 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..................................|-- require('./resolveSSOCredentials') took 50.657345 ms
2022-03-28T20:28:47.741Z	undefined	INFO	....................................|-- require('@aws-sdk/client-sso') took 50.277645 ms
2022-03-28T20:28:47.741Z	undefined	INFO	......................................|-- require('./SSO') took 43.303073 ms
2022-03-28T20:28:47.741Z	undefined	INFO	........................................|-- require('./SSOClient') took 35.038433 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..........................................|-- require('./runtimeConfig') took 34.253186 ms
2022-03-28T20:28:47.741Z	undefined	INFO	............................................|-- require('@aws-sdk/node-http-handler') took 14.914675 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..|-- require('@aws-sdk/client-s3') took 138.489329 ms
2022-03-28T20:28:47.741Z	undefined	INFO	....|-- require('./S3') took 123.365087 ms
2022-03-28T20:28:47.741Z	undefined	INFO	......|-- require('./commands/AbortMultipartUploadCommand') took 44.071934 ms
2022-03-28T20:28:47.741Z	undefined	INFO	........|-- require('../models/models_0') took 10.537944 ms
2022-03-28T20:28:47.741Z	undefined	INFO	........|-- require('../protocols/Aws_restXml') took 27.656476 ms
2022-03-28T20:28:47.741Z	undefined	INFO	......|-- require('./commands/DeleteObjectsCommand') took 15.740644 ms
2022-03-28T20:28:47.741Z	undefined	INFO	........|-- require('@aws-sdk/middleware-flexible-checksums') took 15.35287 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..........|-- require('./flexibleChecksumsMiddleware') took 13.63264 ms
2022-03-28T20:28:47.741Z	undefined	INFO	............|-- require('./selectChecksumAlgorithmFunction') took 10.345904 ms
2022-03-28T20:28:47.741Z	undefined	INFO	......|-- require('./S3Client') took 18.328771 ms
2022-03-28T20:28:47.741Z	undefined	INFO	........|-- require('./runtimeConfig') took 12.748143 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..|-- require('@aws-sdk/client-sqs') took 24.766564 ms
2022-03-28T20:28:47.741Z	undefined	INFO	....|-- require('./SQS') took 19.305477 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..|-- require('@aws-sdk/client-ssm') took 185.064697 ms
2022-03-28T20:28:47.741Z	undefined	INFO	....|-- require('./SSM') took 135.679327 ms
2022-03-28T20:28:47.741Z	undefined	INFO	......|-- require('./commands/AddTagsToResourceCommand') took 62.956037 ms
2022-03-28T20:28:47.741Z	undefined	INFO	........|-- require('../models/models_0') took 17.333932 ms
2022-03-28T20:28:47.741Z	undefined	INFO	........|-- require('../protocols/Aws_json1_1') took 44.988784 ms
2022-03-28T20:28:47.741Z	undefined	INFO	..........|-- require('../models/models_1') took 11.553608 ms
2022-03-28T20:28:47.742Z	undefined	INFO	....|-- require('./commands') took 19.612849 ms
2022-03-28T20:28:47.742Z	undefined	INFO	......|-- require('./ListDocumentsCommand') took 13.616722 ms
2022-03-28T20:28:47.742Z	undefined	INFO	....|-- require('./pagination') took 19.10802 ms
END RequestId: 7419d6fb-7dcb-4c53-a689-0d1d352328bc
REPORT RequestId: 7419d6fb-7dcb-4c53-a689-0d1d352328bc	Duration: 2.86 ms	Billed Duration: 3 ms	Memory Size: 2048 MB	Max Memory Used: 95 MB	Init Duration: 798.59 ms	
XRAY TraceId: 1-62421a7e-0920949e7de8b8455b00f7c4	SegmentId: 05b5512a6f0e008a	Sampled: true	

Installation

You can add treq package into your AWS Lambda function either by NPM package or by AWS Lambda layer as shown below:

By NPM package

To install the middleware, you can use NPM:

npm install --save treq

By AWS Lambda Layer

You can also add treq as layer into your AWS Lambda function.

arn:aws:lambda:${region}:273094347961:layer:treq:3

Note: In the ARN above, you need to replace ${region} with the actual AWS region you deployed your AWS Lambda function.

Usage

  • Configure treq to be required/bootstrapped automatically at startup by setting NODE_OPTIONS environment variable:
NODE_OPTIONS=-r treq
  • Optionally, you can configure require duration threshold (in milliseconds) for tracing. Requires/imports take lower than the threshold are ignored from tracing. By default, the threshold is 10 milliseconds and it can be configured by TREQ_DURATION_THRESHOLD environment variable. For example:
TREQ_DURATION_THRESHOLD=20
  • Optionally, you can configure maximum depth/level limit to trace nested requires/imports. Nested requires/imports deeper than the maximum depth/level limit are ignored from tracing. By default, the max depth is 100 and it can be configured by TREQ_MAX_DEPTH environment variable. For example:
TREQ_MAX_DEPTH=3
  • Optionally, you can disable treq by setting TREQ_DISABLE environment variable to true. For example:
TREQ_DISABLE=true

Contributing

Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.

License

Licensed under MIT License.

You might also like...

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Dec 28, 2022

Learn Web 2.0 and Web 3.0 Development using Next.js, Typescript, AWS CDK, AWS Serverless, Ethereum and AWS Aurora Serverless

Learn Web 2.0 Cloud and Web 3.0 Development in Baby Steps In this course repo we will learn Web 2.0 cloud development using the latest state of the ar

Jan 3, 2023

A Serverless GraphQL Sample project using Apollo and Serverless Framework with TypeScript and Webpack.

Serverless GraphQL Boilerplate This is a base project with a structure that includes Serverless Framework, Apollo, TypeScript and Webpack. It can be d

Aug 23, 2022

AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs. Develop thousands line of aws lambda functions interact to aws serverless services with real-world hands-on labs

AWS Lambda & Serverless - Developer Guide with Hands-on Labs UDEMY COURSE WITH DISCOUNTED - Step by Step Development of this Repository - https://www

Dec 17, 2022

Sheetzapper imports your account value accross Zapper.fi supported wallets and dapps into a Google Sheet

Sheetzapper imports your account value accross Zapper.fi supported wallets and dapps into a Google Sheet

Overview Sheetzapper imports your account value accross Zapper.fi supported wallets and dapps into a Google Sheet. This allows you to chart your net w

Nov 27, 2022

Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Sep 29, 2022

An imports transform unplugin.

unplugin-transform-imports An imports transform unplugin based on babel inspired by babel-plugin-transform-imports. What unplugin-transform-imports Do

Nov 29, 2022

Sort imports by path - VS Code extension

Import sort by absolute path The sorting algorithm will group each item in the array and sort (alphabetically) its children that starts with the path

Feb 2, 2022

Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called

bun-livereload Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called. import liveRelo

Dec 19, 2022
Releases(v1.0.1)
Owner
Serkan ÖZAL
Founder & CTO @ Thundra | AWS Serverless Hero
Serkan ÖZAL
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
"Space Travelers' Hub" This project will lay foundations for your understanding the new features for Redux, using slice reducer and API requires with createAsyncThunk

Space Travelers' Hub Space Travelers' Hub React - Redux "Space Travelers' Hub" This project will lay foundations for your understand new features for

Hendrid Gonzalez 5 Mar 6, 2022
Reddit Place Tracer is a browser based userscript for the 2022 Reddit /r/Place project

Reddit Place Tracer is a browser based userscript for the 2022 Reddit /r/Place project which adds a transparent image on top of the canvas to aid communities with drawing the same image. It shows how the canvas should look, where each pixel goes, and what color. The user must manually click on these spots. It is not an automated bot and does not break any rules.

null 3 Apr 3, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A tracer based on frida for XPC messages in iOS and macOS.

XPC tracer A tracer based on frida for XPC messages in iOS and macOS. This project is a variant of xpcspy. In particular for my purpose I didn't devel

Lorenzo 12 Dec 31, 2022
Imagable - Create, Edit, Optimize And Add Effects to Images

Imagable Imagable is an open-source image editor build on top of Typescript and Node.js. We serve with next-gen tools and filters and effects to make

Haneen Mahdin 2 May 5, 2022
Dynamically resize, format and optimize images based on url modifiers.

Local Image Sharp Dynamically resize, format and optimize images based on url modifiers. Table of Contents ✨ Features ?? Installation ?? Usage Contrib

Strapi Community 30 Nov 29, 2022
Github action to collect metrics (CPU, memory, I/O, etc ...) from your workflows to help you debug and optimize your CI/CD pipeline

workflow-telemetry-action A GitHub Action to track and monitor the resource metrics of your GitHub Action workflow runs. If the run is triggered via a

Thundra 32 Dec 30, 2022
optimize image & upload file to cloud as image bed with tiny image automic.

Rush! 图片压缩 & 直传图床工具 这是一个兴趣使然的项目, 希望 Rush! 能让这个世界的网络资源浪费减少一点点 下载 Downloads 获取最新发行版 功能 Features 拖拽批量压缩图片, 支持格式 jpg/png/gif Drop to optimize, jpg/png/gif

{ Chao } 3 Nov 12, 2022