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

@oas-tools/oas-telemetry

v0.3.0

Published

This package exports an Express middleware that traces requests and responses of an Express application using OpenTelemetry.

Downloads

95

Readme

OAS TELEMETRY

OAS Telemetry offers an express middleware designed for collecting telemetry data using Open Telemetry in applications built using the OpenAPI Specification (OAS). This middleware allows developers to easily incorporate telemetry functionality into their APIs.

OAS Telemetry provides a set of endpoints that can be accessed to perform various actions related to telemetry data, such as starting and stopping data collection, resetting telemetry data, listing collected data, and searching for specific telemetry records. These endpoints can be easily integrated into an Express.js application, providing developers with a convenient way to manage and analyze telemetry data.

Additionally, OAS Telemetry offers customization options, allowing developers to configure the telemetry middleware according to their specific requirements.

Overall, OAS Telemetry will serve as a valuable tool for developers looking to gain insights into the operation and performance of their OAS-based APIs, enabling them to monitor, debug, and optimize their applications effectively.

Usage

To use the middelware add this two lines in your index.js (ESM):

import oasTelemetry from 'oas-telemetry';
import {readFileSync} from 'fs';

app.use(oasTelemetry({
    spec : readFileSync('./spec/oas.yaml',{ encoding: 'utf8', flag: 'r' })
}))

Custom Configuration

You can also customize the telemetry configuration by passing options to the middleware function. For example:

const customTelemetryConfig = {
    exporter: myCustomExporter,
    spec: /* OAS content in json or yaml */
};

app.use(oasTelemetry(customTelemetryConfig));

Telemetry UI

You can access the telemetry UI in the endpoint /telemetry

API Telemetry Endpoints

OAS Telemetry middleware adds the following endpoints to your Express application:

  • /telemetry/start: Start telemetry data collection.
  • /telemetry/stop: Stop telemetry data collection.
  • /telemetry/status: Get status of telemetry.
  • /telemetry/reset: Reset telemetry data.
  • /telemetry/list: List all telemetry data.
  • /telemetry/find (POST): Search telemetry data.
  • /telemetry/heapStats: Shows v8 heapStats.

Simple Example ES Module (*.mjs)

import oasTelemetry from '@oas-tools/oas-telemetry';
import express from 'express';

const app = express();
const port = 3000;

const spec = { "paths": {
                    "/api/v1/pets": {
                        "get": {
                            "summary": "Get pets",
                            "responses":{
                                "200": {
                                    "description": "Success"
                                }
                            }
                        }
                    }
                }
            }

app.use(oasTelemetry({
    spec : JSON.stringify(spec)
}))

app.use(express.json());

app.get("/api/v1/pets", (req, res) => {
    res.send([{ name: "rocky"},{ name: "pikachu"}]);
});

app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`);
    console.log(`Telemetry portal available at http://localhost:${port}/telemetry`);
});

Simple Example Common.js Module (*.cjs)

let oasTelemetry = require('@oas-tools/oas-telemetry');
let express = require('express');

const app = express();
const port = 3000;

const spec = { "paths": {
                    "/api/v1/pets": {
                        "get": {
                            "summary": "Get pets",
                            "responses":{
                                "200": {
                                    "description": "Success"
                                }
                            }
                        }
                    }
                }
            }

app.use(oasTelemetry({
    spec : JSON.stringify(spec)
}))

app.use(express.json());

app.get("/api/v1/pets", (req, res) => {
    res.send([{ name: "rocky"},{ name: "pikachu"}]);
});

app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`);
    console.log(`Telemetry portal available at http://localhost:${port}/telemetry`);
});