@upscale/upscale-js
v0.7.1
Published
`@upscale/upscale-js` is an SDK library for app optimization. Current version is built on top of Winston for logger optimizatoin, designed to provide advanced logging capabilities with sampling features.
Readme
Upscale.guru SDK
@upscale/upscale-js is an SDK library for app optimization.
Current version is built on top of Winston for logger optimizatoin, designed to provide advanced logging capabilities with sampling features.
The service is designed to work in server side app, which can be standalone server, docker container or kubernetes pod, or even lambda function.
It can work with conjunction of multiple log shippers, like AWS CloudWatch, SumoLogic, Datadog, etc.
The service will provide most relevant developer a PR containing the optimization. New optimizations coming soon!
Paramters:
- productKey: a unique key taken from upscale.guru saas Service.
- sampleRate: the rate of sampling for the global logs. When a log is adding the metadata {sampled: true} :
it will be sampled within this rate. (Default: 0.05)logger.info('This is an info log', { meta: { sampled: true } });, - debugSample: the rate of sampling for the debug logs. when log level is reduced to debug, it will be sampled within this rate for ALL debug logs if you set the winston level to debug. Now you can have debug logs in production while not caring about performance and cost! (Default: 1. No sampling, recommended is to start with very low rate in production 0.001)
Installation
You can install the library via npm:
npm install @upscale/upscale-jsUsage
To use the upscaleFormatter, you need to import it and create a Winston logger instance. The formatter allows you to specify a product key and sampling rates for debug and info logs.
Example
Here's a simple example of how to set up the logger with the upscaleFormatter:
import winston from 'winston';
import upscaleFormatter from '@upscale/upscale-js';
SAMPLE_GLOBAL_RATIO = 0.05;
SAMPLE_DEBUG_RATIO = 0.001;
// create logger
const logger = winston.createLogger({
level: 'debug',
format: winston.format.combine(
upscaleFormatter("license key from upscale.guru", SAMPLE_GLOBAL_RATIO, SAMPLE_DEBUG_RATIO), // productKey, sampleRate, debugSample
winston.format.json()
),
transports: [
new winston.transports.Console({
handleExceptions: true,
}),
],
});
logger.debug('This is a debug log');
logger.info('This is an info log', { meta: { sampled: true } });License
This project is licensed under the ISC License.
