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

@ballin-team/lib-apm

v1.5.0

Published

<h1 align="center"> ๐Ÿ‘€ </h1>

Downloads

59

Readme

:package: Content

:hammer_and_wrench: Technologies

We are using the following technologies:

:climbing: Getting Started

This lib aims to centralize all the necessary tools for the Ballin Team logs.

How to install

npm install @ballin-team/lib-apm

Config

import { Logger } from "@ballin-team/lib-apm";

const logger = Logger.createLogger({
  "name": "lib-logger", // service/ms name
  "minLevel": "debug", // the minimum level to log into the terminal
  "suppressStdOutput": false, // suspend log in terminal
  "transports": [  // custom services to execute methods with logObject as parameter
    {
      "provider": "coralogix", // transport type
      "minLevel": "debug", // the minimum level to execute the transport
      "enabled": true, // activate or not the transport
      "options": { // transport options
        "applicationName": "",
        "privateKey": "",
        "subsystemName": "",
        "category": ""
      }
    },
    {
      "provider": "sentry",
      "minLevel": "info",
      "enabled": true
    },
  ]
});

Habilitar source map para TypeScript:

This feature enables lib-apm to reference a correct line number in your TypeScript source code.

// tsconfig.json
{
  // ...
  "compilerOptions": {
    // ...
    "sourceMap": true,
    // we recommend using a current ES version
    "target": "es2019"
  }
}

Use Cases

Basic Implementation

import { Logger } from "@ballin-team/lib-apm";

const logger = new Logger({
  instanceName: 'service name',
  minLevel: 'info',
  transports: [],
});

logger.setRequestId(123)
logger.silly("I am a silly log.");
logger.trace("I am a trace log with a stack trace.");
logger.debug("I am a debug log.");
logger.info("I am an info log.");
logger.warn("I am a warn log with a json object:", {foo: "bar"});
logger.error("I am an error log.");
logger.fatal(new Error("I am a pretty Error with a stacktrace."));

Implementation with express

// logger/index.ts
import { Logger } from '@ballin-team/lib-apm'
import * as dotenv from 'dotenv'
dotenv.config({ path: `./environments/.env.${process.env.NODE_ENV}` });

const configLogger = () => {
  const enableTransport = process.env.NODE_ENV === 'production'
  return new Logger({
    name: "ms_test",
    minLevel: "info",
    suppressStdOutput: false,
    transports: [
      {
        provider: 'coralogix',
        minLevel: 'error',
        enabled: enableTransport,
        options: {
          applicationName: "",
          privateKey: "",
          subsystemName: "",
          category: "",
        }
      },
      {
        provider: 'sentry',
        minLevel: 'info',
        enabled: true
      },
    ]
  })
}

export const logger = configLogger()

// app.ts
import { logger } from './logger';
import express from "express";

export const initApp = async () => {
  const app = express()

  // ...setting other configs and middlewares

  app.use(express.json()); // the "express.json" needs to be instantiated before the "logger.setContext"
  app.use(logger.setContext) // will create context for each request

  // ... routes and middlewares

  return app
};

// middleware/setRequestId.ts
import { NextFunction, Response } from 'express'
import { IRequest } from '../interfaces/request'
import { v4 as uuid } from 'uuid'
import { Logger } from '../logger'


export const setRequestId = (req: IRequest, res: Response, next: NextFunction): void => {
  const requestId = (req.headers['x-request-id'] as string) || uuid()

  req.requestId = requestId

  Logger.setRequestId(requestId)
  Logger.info(req.method,req.path,req.body)

  return next()
};

// Now just call the logger anywhere in your code =)

Transports

Coralogix

Transport Coralogix aims to capture all logs from the level defined in the setup and insert them as an occurrence in case of error;

:incoming_envelope: Made by

  • :feelsgood: Time Ballin