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

@meltwater/esbuild-plugin-node

v0.1.1

Published

Metapackage which bundles opentelemetry node core and contrib instrumentations via an esbuild plugin

Downloads

815

Readme

THIS IS A FORK FROM https://github.com/open-telemetry/opentelemetry-js-contrib/pull/1856 only mean to be used until this issue gets addressed in opentelemetry-js-contrib repo

OpenTelemetry Esbuild for Node

NPM Published Version Apache License

About

This module provides a way to auto instrument any Node application to capture telemetry from a number of popular libraries and frameworks, via an esbuild plugin. You can export the telemetry data in a variety of formats. Exporters, samplers, and more can be configured via environment variables. The net result is the ability to gather telemetry data from a Node application without any code changes.

This module also provides a simple way to manually initialize multiple Node instrumentations for use with the OpenTelemetry SDK.

Compatible with OpenTelemetry JS API and SDK 1.0+.

Installation

npm install --save @meltwater/esbuild-plugin-node

Usage: Esbuild plugin

This module includes instrumentation for all supported instrumentations and all available data exporters. It provides a completely automatic, out-of-the-box experience. Please see the Supported Instrumentations section for more information.

Enable auto instrumentation by configuring it in your esbuild script:

const { openTelemetryPlugin } = require('@meltwater/esbuild-plugin-node');
const { build } = require('esbuild');

build({
  entryPoints: ['src/server.ts'],
  bundle: true,
  outfile: 'dist/server.js',
  target: 'node20',
  platform: 'node',
  sourcemap: true,
  plugins: [openTelemetryPlugin()],
});

Usage: Instrumentation Initialization

OpenTelemetry Meta Packages for Node automatically loads instrumentations for Node builtin modules and common packages.

Enable auto instrumentation by configuring it in your esbuild script:

const { openTelemetryPlugin } = require('@meltwater/esbuild-plugin-node');
const { build } = require('esbuild');

build({
  entryPoints: ['src/server.ts'],
  bundle: true,
  outfile: 'dist/server.js',
  target: 'node20',
  platform: 'node',
  sourcemap: true,
  plugins: [openTelemetryPlugin()],
});

Custom configuration for each of the instrumentations can be passed to the plugin, by providing an object with the name of the instrumentation as a key, and its configuration as the value.

const { openTelemetryPlugin } = require('@meltwater/esbuild-plugin-node');
const { build } = require('esbuild');

build({
  entryPoints: ['src/server.ts'],
  bundle: true,
  outfile: 'dist/server.js',
  target: 'node20',
  platform: 'node',
  sourcemap: true,
  plugins: [
    openTelemetryPlugin({
      instrumentationConfig: {
        '@meltwater/instrumentation-aws-sdk': {
          suppressInternalInstrumentation: true,
        },
      },
    }),
  ],
});

This esbuild script will instrument non-builtin packages but will not configure the rest of the OpenTelemetry SDK to export traces from your application. To do that you must also configure the SDK.

The esbuild script currently only patches non-builtin modules (more specifically, modules in opentelemetry-js-contrib), so this is also the place to configure the instrumentation for builtins or add any additional instrumentations.

Gotchas

There are limitations to the configuration options for each package. Most notably, any functions (like ignoreIncomingRequestHook in the example) are not allowed to be passed in to plugins.

The reason for this is that the current mechanism of instrumenting packages involves stringifying the instrumentation configs, which does not account for any external scoped dependencies, and thus creates subtle opportunities for bugs.

const {
  getNodeAutoInstrumentations,
} = require('@meltwater/auto-instrumentations-node');
const {
  AsyncHooksContextManager,
} = require('@meltwater/context-async-hooks');
const {
  OTLPTraceExporter,
} = require('@meltwater/exporter-trace-otlp-http');
const { NodeSDK } = require('@meltwater/sdk-node');

const instrumentations = getNodeAutoInstrumentations();

const sdk = new NodeSDK({
  traceExporter: new OTLPTraceExporter(),
  contextManager: new AsyncHooksContextManager().enable(),
  instrumentations,
});

sdk.start();

process.on('SIGTERM', () => {
  sdk.shutdown().finally(() => process.exit(0));
});

Supported instrumentations

See @meltwater/auto-instrumentations-node for the supported packages.

Note that Node.js builtin modules will not be patched by this plugin.

Useful links

License

APACHE 2.0 - See LICENSE for more information.