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

shron

v1.0.0

Published

Serverless Chronometer

Downloads

6

Readme

shron

Serverless Chronometer

workflow npm version license

shron is an NPM package to measure execution times of methods (sync/async) in TypeScript files by decorators (@Shron) automatically without modifying method bodies.

It also allows you to report those collected performance metrics (ShronResult) to external systems (AWS CloudWatch, Elasticsearch, Prometheus, etc ...) through callbacks.

Installation

You can add shron package into your AWS Lambda function as NPM package:

npm install --save shron

Shron is based on TypeScript's experimental method decorator feature. So to be able to use Shron without warning during compilation, you need to enable experimentalDecorators option in your tsconfig or jsconfig file:

{
  "compilerOptions": {
    ...
    "experimentalDecorators": true,
    ...
  },
  ...
}

Usage

import { Shron, ShronResult } from 'shron';

class Person {

    constructor(
        private firstName: string,
        private lastName: string,
    ) {}

    @Shron()
    hi(): void {
        console.log(`Hello!`);
    }

    @Shron({
        cb: (result: ShronResult) => {
            console.log(`Executed ${result.name} in ${result.duration} ms`);
        }
    })
    whoAreYou(): void {
        console.log(`I am ${this.firstName}, ${this.lastName}`);
    }

    @Shron({
        async: true,
    })
    async comeHere(): Promise<void> {
        console.log(`I am coming ...`);
        await new Promise(r => setTimeout(r, 1000));
        console.log(`Here I am`);
    }

    @Shron({
        async: true,
        cb: (result: ShronResult) => {
            console.log(`Executed ${result.name} in ${result.duration} ms`);
        }
    })
    async sleep(): Promise<void> {
        console.log(`Sleeping ...`);
        await new Promise(r => setTimeout(r, 1500));
        console.log(`Just woke up`);
    }

}

export async function hello(event: any) {
    const person = new Person('Serkan', 'Ozal');

    person.hi();

    person.whoAreYou();

    await person.comeHere();

    await person.sleep();

    return {
        message: 'Hello world!',
        input: event,
    };
}

which prints the following output:

2022-05-22T09:15:26.353+03:00	START RequestId: cc321720-17b8-4619-b986-5fdc785bcfd0 Version: $LATEST
2022-05-22T09:15:26.356+03:00	2022-05-22T06:15:26.356Z cc321720-17b8-4619-b986-5fdc785bcfd0 INFO Hello!
2022-05-22T09:15:26.356+03:00	2022-05-22T06:15:26.356Z cc321720-17b8-4619-b986-5fdc785bcfd0 INFO {"type":"shron","region":"us-east-1","functionName":"shron-playground-dev-hello","functionVersion":"$LATEST","traceId":"Root=1-6289d4fe-09ebe097262cbf46535df690;Parent=4a9c0ed8258690a7;Sampled=0","name":"hi","startTime":1653200126355,"duration":0,"durationHighRes":0.548095}
2022-05-22T09:15:26.356+03:00	2022-05-22T06:15:26.356Z cc321720-17b8-4619-b986-5fdc785bcfd0 INFO I am Serkan, Ozal
2022-05-22T09:15:26.356+03:00	2022-05-22T06:15:26.356Z cc321720-17b8-4619-b986-5fdc785bcfd0 INFO Executed whoAreYou in 0 ms
2022-05-22T09:15:26.357+03:00	2022-05-22T06:15:26.357Z cc321720-17b8-4619-b986-5fdc785bcfd0 INFO I am coming ...
2022-05-22T09:15:27.359+03:00	2022-05-22T06:15:27.359Z cc321720-17b8-4619-b986-5fdc785bcfd0 INFO Here I am
2022-05-22T09:15:27.360+03:00	2022-05-22T06:15:27.359Z cc321720-17b8-4619-b986-5fdc785bcfd0 INFO {"type":"shron","region":"us-east-1","functionName":"shron-playground-dev-hello","functionVersion":"$LATEST","traceId":"Root=1-6289d4fe-09ebe097262cbf46535df690;Parent=4a9c0ed8258690a7;Sampled=0","name":"comeHere","startTime":1653200126357,"duration":1002,"durationHighRes":1002.726858}
2022-05-22T09:15:27.360+03:00	2022-05-22T06:15:27.360Z cc321720-17b8-4619-b986-5fdc785bcfd0 INFO Sleeping ...
2022-05-22T09:15:28.865+03:00	END RequestId: cc321720-17b8-4619-b986-5fdc785bcfd0
2022-05-22T09:15:28.865+03:00   REPORT RequestId: cc321720-17b8-4619-b986-5fdc785bcfd0	Duration: 2509.56 ms	Billed Duration: 2510 ms	Memory Size: 1024 MB	Max Memory Used: 56 MB	Init Duration: 162.87 ms	

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.