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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ollyv/express

v0.0.1

Published

Ollyv sdk is designed to empower your applications with seamless logging and comprehensive distributed tracing capabilities.

Readme

Ollyv: Express

Installation

To install the Ollyv SDK for Express logging, run the following command in your project's root directory:

npm i @ollyv/express

Open a file named app.js or the main file to be executed.

  • 🎤 Example for CommonJS
    // 1. Import necessary modules
    // 1.1. [Logging] Use contextMiddleware for logging
    // 1.2. [Tracing] Use openSegment and closeSegment for tracing
    const { contextMiddleware, openSegment, closeSegment } = require('@ollyv/express');
    
    const app = express();
      
    // 2.1 [Tracing] If you wish to enable tracing, add the tracing middleware
    app.use(openSegment());
    // 2.2 [Logging] Register the contextMiddleware after body-parser, e.g., express-busboy, body-parser
    app.use(contextMiddleware);
    ...
    // 3. [Tracing] Don't forget to close the segment to ensure proper tracing
    app.use(closeSegment());
  • 🎤 Example for ES Module
    // 1. Import necessary modules
    // 1.1. [Logging] Use contextMiddleware for logging
    // 1.2. [Tracing] Use openSegment and closeSegment for tracing
    import { contextMiddleware, openSegment, closeSegment } from '@ollyv/express';
    
    export const startServer = () => {
      ...
      // 2.1 [Tracing] If you wish to enable tracing, add the tracing middleware
      app.use(openSegment());
      // 2.2 [Logging] Register the contextMiddleware after body-parser, e.g., express-busboy, body-parser
      app.use(contextMiddleware);
      ...
    
      // 3. [Tracing] Don't forget to close the segment to ensure proper tracing
      app.use(closeSegment());
      ...
    };
    

Configuration

The Ollyv SDK offers a simple way to configure its behavior through *.properties files, which are environment-specific. Below are the available properties and their usage:

...

[saas]
observability.name = delivery-service
observability.tracing.origin = AWS::ECS::Fargate
observability.logging.enable = true
  • observability.name
    • Description: Specifies the name of the observability component for tracing.
    • Example: observability.name = delivery-service
  • observability.tracing.origin
    • Description: Specifies the origin of the tracing.
    • Example: observability.tracing.origin = AWS::ECS::Fargate
  • observability.logging.enable
    • Description: Determines whether logging is enabled or disabled.
    • Example: observability.logging.enable = true

Logging

If you want to log with error, it's required to use logger.error(e.stack)

  • 🎤 Example for CommonJS

    const { contextMiddleware, openSegment, closeSegment } = require('@ollyv/express');
    ...
    const bb = require('express-busboy');
    const app = express();
    bb.extend(app, {
      upload: true,
      path : './temp/'
    });
    app.use(openSegment());
    
    // if express uses "body parser" like express-busboy,  contextMiddleware should be placed after the body parser.
    app.use(contextMiddleware); 
    app.use(timeout('1820s'));
    ...
    
  • 🎤 Example for ES Module

    import { logger, ContextAwareSqsConsumer } from '@ollyv/express';
    
    export const sqsListener = () => {
      ...
      const sqsConsumer = ContextAwareSqsConsumer.create({
        messageAttributeNames: ['All'],
        queueUrl: queueUrl,
        handleMessage: async (m) => {
          try {
            const { Body } = m;
            logger.info(`message : `, JSON.stringify(m));
            const body = JSON.parse(Body);
            await sendMessage(body);
          } catch (e) {
            logger.info(`error: `, e.stack);
          }
        }
      });
    //...

Tracing

  • 🎤 Example for CommonJS

    const { contextMiddleware, openSegment, closeSegment } = require('@ollyv/express');
    //...
    const app = express();
    app.use(openSegment());
    app.use(contextMiddleware); 
    //...
    app.use(closeSegment());
    const { logger, tracer } = require('@ollyv/express');
    const AWS = tracer.captureAWS(require('aws-sdk'));
  • 🎤 Example for ES Module

    import { logger, contextMiddleware, openSegment, closeSegment } from '@ollyv/express';
    const app = express();
    export const startServer = () => {
      app.use(openSegment());
      app.use(contextMiddleware);
      app.use(closeSegment());
    import { logger, tracer } from '@ollyv/express';
    import plainPg from 'pg';
    const pg = tracer.capturePostgres(plainPg);

Generating custom subsegments

  • Each time you make a call with an instrumented client, the tracer from SDK records the information generated in a subsegment. You can create additional subsegments to group other sebsegments, to measure the performance of a section of code, or to record annotations and metadata.
    • Example app.js - custom subsegments Express
      const { tracer, openSegment, closeSegment } = require('@ollyv/express');
      app.use(openSegment('MyApp'));
      
      app.get('/', function (req, res) {
        var host = 'api.example.com';
      
        tracer.captureAsyncFunc('send', function(subsegment) {
          sendRequest(host, function() {
            console.log('rendering!');
            res.render('index');
            subsegment.close();
          });
        });
      });
      
      app.use(closeSegment());
      
      function sendRequest(host, cb) {
        var options = {
          host: host,
          path: '/',
        };
      
        var callback = function(response) {
          var str = '';
          response.on('data', function (chunk) {
            str += chunk;
          });
          response.on('end', function () {
            cb();
          });
        }
        http.request(options, callback).end();
      };

Dependencies

List of dependencies required for the SDK.

{
  "devDependencies": {
    "@babel/cli": "^7.22.5",
    "@babel/core": "^7.22.5",
    "@babel/plugin-transform-modules-commonjs": "^7.22.5",
    "@babel/preset-env": "^7.22.5",
    "@types/sqs-consumer": "^5.0.0",
    "babel-jest": "^29.5.0",
    "clean-jsdoc-theme": "^4.2.9",
    "esm": "^3.2.25",
    "jest": "^29.5.0",
    "jsdoc": "^4.0.2",
    "mocha": "^10.2.0",
    "nodemon": "^2.0.22"
  },
  "dependencies": {
    "async_hooks": "^1.0.0",
    "aws-sdk": "^2.1398.0",
    "aws-xray-sdk": "^3.5.0",
    "callee": "^1.1.1",
    "jsonwebtoken": "^9.0.0",
    "lodash": "^4.17.21",
    "properties-reader": "^2.2.0",
    "sqs-consumer": "^5.8.0",
    "winston": "^3.9.0"
  }
}

Package Structure

ollyv/express/
  ├── configs : configurations for build and packaging
  ├── dist : transpiled output of the package
  │   ├── cjs : support the use of package in commonjs type
  │   │   ├── compiled output for commonjs
  │   │   ├── compiled output for commonjs
  │   │   └── ...
  │   └── esm : support the use of package in es module type
  │       ├── compiled output for esmodule
  │       ├── compiled output for esmodule
  │       └── ...
  ├── src
  │   ├── configuration
  │   ├── const
  │   ├── layout
  │   ├── message
  │   ├── middleware
  │   └── service
  └── test : test code
  │   ├── configuration
  │   ├── message
  │   ├── middleware
  │   └── service
  ├── jest.config.js
  ├── jsdoc.config.json
  ├── package-lock.json
  └── package.json

Test

  • run test
    npm test
  • test coverage
    npx jest --coverage

Debugging

  • 🔎 When the log context set to unknown?
    • 💡 Need to verify that the field exists in the token you actually receive from the client
    • 💡 Neet to make sure that you set logFormattingMap correctly in express/src/layout/logLayout.js

Documentation

npm run jsdoc
  • configuration : jsdoc.config.json
      {
        "plugins": [
            "plugins/markdown"
        ],
        "opts": {
            "readme": "README.md",
            "destination": "./docs",
            "template": "node_modules/clean-jsdoc-theme",
            "theme_opts": {
                "default_theme": "dark",
                "search": false,
                "title": "<a href=\"index.html\" class=\"sidebar-title\" >Ollyv: NodeExpress</a>",
                "homepageTitle": "Ollyv Docs: NodeExpress",
                "includeFilesListInHomepage": true
              }
        },
        "script": {
            "generate-docs": "jsdoc --configure jsdoc.json --verbose"
        },
        "recurseDepth": 10,
        "source": {
            "include": [
                "src",
                "src/service",
                "src/configuration",
                "src/const",
                "src/layout",
                "src/message",
                "src/middleware"
            ],
            "includePattern": "/.+\\.js(doc|x)?$",
            "excludePattern": "(^|\\/|\\\\)_"
        },
        "sourceType": "module",
        "tags": {
            "allowUnknownTags": true,
            "dictionaries": [
                "jsdoc",
                "closure"
            ]
        },
        "templates": {
            "cleverLinks": false,
            "monospaceLinks": false
        }
    }

Reference