Git Product home page Git Product logo

fastify-metrics's People

Contributors

antoniomuso avatar dependabot[bot] avatar dnlup avatar mdoria12 avatar ryanrishi avatar semantic-release-bot avatar simonecorsi avatar snyk-bot avatar zajozor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastify-metrics's Issues

FastifyContextConfig type error

The configuration of the route should have fastifyPrefix and routesPrefix optional, but we have set it mandatory.

interface FastifyContextConfig {
        metrics: {
            /** The id for this route that will be used for the label */
            routeId: string;
            /** Normalized fastify prefix for this route */
            fastifyPrefix: string;
            /** Normalized prefix of the routes */
            routesPrefix: string;
        };
    }

500 error codes on 404

A 404 generates an internal server error because the plugin tries to send a metric using the reply decorator, which in turn checks for the presence of a routeId inside the metrics object. This object is not setup for a route that doesn't exists because we use the onRoute hook to do it. We should take this into account in the onError hook.

Flaky tests

Some checks are flaky because they rely on counting the ms passed. Let's try to use fake timers in those cases, otherwise it's better to remove them.

Try to add examples with other metrics libraries

I think it could be nice to see if it's possible to integrate this library with other metric libraries (even not statsd ones) using our client interface. I am not sure if it's possible but I think it's worth a try and, in case it works, add some examples in the docs.

Refactor tests

Having the tests in a single file has become too cumbersome to handle. We could use a refactor.

Refactor plugin

We could refactor the plugin entry point moving all generic functions and utilities in separate files. We might improve readability.

Cannot cast metricsClient

let metricsClient: MetricsPluginOptions['client']; // Option | CustomClient | undefined
metricsClient?.host 

leads to type error and i cannot cast witch type of client to use in my code

Missing types integration for FastifyContextConfig

Retrieving routeId from request.context leads to type error due to the missing definition of metrics object.

something like:

declare module 'fastify' {
    interface FastifyContextConfig {
        metrics: {
             routeId: string
        }
    }
}

Add the possibity to track a time execution of async functions

What do you think of trackAsyncCbTime function to trace async function resolve's time?

async function asyncFunction(a, b, c) {
    await doSomething(a, b, c);
    return doSomething2(a, b, c);
}

const asyncFunctionOutput = await fastify.trackAsyncCbTime(
    { scope: 'something', label: 'test' },
    asyncFunction,
    a,
    b,
    c
);

WDYT?

Backport `customLabels` implementation for version 9.x

Hi! First, wanna say great work for implementing automated metrics in fastify.

Currently we're trying to use fastify-metrics version 9.x with nestjs. Due to some limitation we cannot upgrade nestjs to latest version. When exploring our usecase, we cannot add custom labels with existing implementation while we can do it in version 10.x or above.

Is it possible to backport customLabels functionality in version 9.x? Wouldn't mind to raise a PR here.

Label is undefined

If you pass a configuration like this:

fastify.register(plugin, {
    client: {
        host: 'udp://127.0.0.1:4000',
        namespace: 'test',
    },
    routes: {
        timing: false,
        // TODO: add responseSize
        /**
         * Route hit counter
         */
        hits: false,
        /**
         * Route errors counter
         */
        errors: false,
    },
    health: false,
});

You can use the method sendCounterMetric inside the reply, but the label is undefined.

To fix it we can remove the following check:

        if (
            config.routes.timing ||
            config.routes.errors ||
            config.routes.hits
        ) {

Fix README

Things to look for:

  • examples still referencing old config object in route setup (routeId)
  • specificy context.config is on both reply and request
  • specify getLabel should not have a . at the beginning and the end of the string.
  • specify that getLabel is needed in dynamic mode
  • add a migration guide

Config options refactor

Scope requests/respose flags inside a dedicated key. Use the health key to pass custom sampler options too.

Types Migration

The current types do the overloading of Fastify default types, this creates the problem that we found the plugin types also in data type not reached from the plugin.

fastify.get<ReqReplyMetrics, MetricsConfig>(
        '/',
        { config: { metrics: { metricId: '' } } },
        (request, reply) => {}
    );

For this reason, we can evaluate the migration to generics typing, in this way, it is the user's responsibility to type his data.

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.