Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lokalise/fastify-extras

Package Overview
Dependencies
Maintainers
11
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lokalise/fastify-extras

Opinionated set of fastify plugins, commonly used in Lokalise

  • 10.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.4K
decreased by-26.67%
Maintainers
11
Weekly downloads
 
Created
Source

fastify-extras 🧩

Reusable plugins for Fastify.

Dependency Management

The following needs to be taken into consideration when adding new runtime dependency for the fastify-extras package:

  • If dependency is an implementation detail, and end consumer is not expected to import and use the dependency directly, it should be a dependency;
  • If dependency needs to be imported and used by consumer directly for it to function properly, it should be a peerDependency.

Dependencies

  • @bugsnag/js;
  • @opentelemetry/api;
  • @opentelemetry/exporter-trace-otlp-grpc;
  • @opentelemetry/instrumentation;
  • @opentelemetry/resources;
  • @opentelemetry/sdk-trace-base;
  • @opentelemetry/sdk-trace-node;
  • @opentelemetry/semantic-conventions;
  • @prisma/instrumentation;
  • @splitsoftware/splitio;
  • fastify-metrics;
  • fastify-plugin;
  • tslib.

Peer Dependencies

  • @fastify/request-context;
  • fastify;
  • newrelic;
  • pino.

Plugins

RequestContext Provider Plugin

Plugin to:

  • extend existing FastifyRequest with request context by setting the following:
    • logger, an instance of FastifyBaseLogger;
    • reqId, the request-id;
  • store the request-id in Asynchronous Local Storage to be picked up by instrumentation tooling (e. g. OpenTelemetry).

No options are required to register the plugin.

The getRequestIdFastifyAppConfig() method is exported and returns:

  • genReqId, a function for generating the request-id;
  • requestIdHeader, the header name used to set the request-id.

Which can be passed to Fastify during instantiation.

Public Healthcheck Plugin

Plugin to monitor app status through public healthcheck.

Add the plugin to your Fastify instance by registering it with the following options:

  • healthChecks, a list of promises with healthcheck in the callback;
  • responsePayload (optional), the response payload that the public healthcheck should return. If no response payload is provided, the default response is:
    {"heartbeat": "HEALTHY"}
    

Your Fastify app will reply with the status of the app when hitting the GET / route.

Split IO Plugin

Plugin to handle feature flags in Split IO.

Add the plugin to your Fastify instance by registering it with the following options:

  • isEnabled, if true the plugin will connect to Split IO using the provided apiKey and store data in memory with background syncing;
  • apiKey, your SDK key;
  • debugMode;
  • localhostFilePath (optional), used to utilize the SDK in localhost mode. It corresponds to the full path to a file with the mapping of feature flag name to treatment. apiKey will be automatically replaced with localhost if localhostFilePath is provided.

The plugin decorates your Fastify instance with a SplitIOFeatureManager, which you can inject and use to leverage the following methods:

  • init(), returns a promise that resolves once the SDK has finished loading. It's called automatically when registering the plugin;
  • getTreatment(), returns the proper treatment based on the feature flag name and the key in input. Expected parameters are:
    • key, the ID of the user/account/etc. you're trying to evaluate a treatment for;

    • splitName, the Split IO feature flag name;

    • attributes (optional), a set of Attributes used in evaluation to further decide whether to show the on or off treatment;

    NOTE: If isEnabled is false, getTreatement() will return control to signal disabled treatment.

  • getTreatmentWithConfig(), used to leverage dynamic configurations with your treatment. It accepts the same parameters as getTreatment(), but the response structure is as follows:
    type TreatmentResult = {
      treatment: string,
      config: string | null
    };
    

    NOTE: If isEnabled is false, getTreatementWithConfig() will return control as treatment and null as config to signal disabled treatment.

  • track(), used to record any actions your customers perform. Returns a boolean to indicate whether or not the SDK was able to successfully queue the event. Expected parameters are:
    • key, the ID of the user/account/etc. you're trying to evaluate a treatment for;
    • trafficType, the traffic type of the key;
    • eventType, the event type that this event should correspond to;
    • value (optional), the value to be used in creating the metric;
    • properties(optional), an object of key value pairs that represent the properties to be used to filter your metrics;
  • shutdown(), gracefully shuts down the client.

More info about Split IO can be checked here.

BugSnag Plugin

Plugin to report errors to BugSnag.

Add the plugin to your Fastify instance by registering it with the following options:

Once the plugin has been added to your Fastify instance and loaded, errors will be reported to BugSnag.

Metrics Plugin

Plugin to expose Prometheus metrics.

Add the plugin to your Fastify instance by registering it with the following options:

  • loggerOptions, used to configure the internal logger instance. It can be a boolean or a set of Pino options. By default it is set to false and the logger is disabled;
  • disablePrometheusRequestLogging (optional). By default Fastify will issue an info level log message when a request is received and when the response for that request has been sent. By setting this option to true, these log messages will be disabled. Defaults to true;
  • bindAddress (optional). By default, the server will listen on the address(es) resolved by localhost when no specific host is provided. See the possible values for host when targeting localhost here;
  • errorObjectResolver, a resolver method that, given an err and optionally a correlationID, it will log the error if something goes wrong.

The plugin exposes a GET /metrics route in your Fastify app to retrieve Prometheus metrics. If something goes wrong while starting the Prometheus metrics server, an Error is thrown. Otherwise, a success message is displayed when the plugin has been loaded.

NewRelic Transaction Manager Plugin

Plugin to create custom NewRelic spans for background jobs.

Add the plugin to your Fastify instance by registering it with the following options:

  • isEnabled.

The plugin decorates your Fastify instance with a NewRelicTransactionManager, which you can inject and use to leverage the following methods:

  • start(), which takes a jobName, and starts a background transaction with the provided name;
  • stop(), which takes a jobId, and ends the background transaction referenced by the ID;
  • addCustomAttribute(), which takes attrName and attrValue and records the custom attribute as such defined. attrValue can be a string, a number, or a boolean.

Keywords

FAQs

Package last updated on 05 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc