@apm-js-collab/tracing-hooks
CJS and ESM hooks for orchestrion
Last updated 4 days ago by GitHub Actions .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @apm-js-collab/tracing-hooks 
SYNC missed versions from official npm registry.

Tracing Hooks

This repository contains a ESM loader for injecting tracing channel hooks into Node.js modules. It also has a patch for Module to be used to patch CJS modules.

Usage

To load esm loader:

// esm-loader.mjs
import { register } from 'node:module';
const instrumentations = [
  {
    channelName: 'channel1',
    module: { name: 'pkg1', verisonRange: '>=1.0.0', filePath: 'index.js' },
    functionQuery: {
      className: 'Class1',
      methodName: 'method1', 
      kind: 'Async'
    }
  },
  {
    channelName: 'channel2',
    module: { name: 'pkg2', verisonRange: '>=1.0.0', filePath: 'index.js' },
    functionQuery: {
      className: 'Class2,
      methodName: 'method2', 
      kind: 'Sync'
    }
  }
]

register('@apm-js-collab/tracing-hooks/hook.mjs', import.meta.url, {
  data: { instrumentations }
});

To use the loader, you can run your Node.js application with the --import flag:

node --import esm-loader.mjs your-app.js

To load CJS patch:

// cjs-patch.js
const ModulePatch = require('@apm-js-collab/tracing-hooks')
const instrumentations = [
  {
    channelName: 'channel1',
    module: { name: 'pkg1', verisonRange: '>=1.0.0', filePath: 'index.js' },
    functionQuery: {
      className: 'Class1',
      methodName: 'method1', 
      kind: 'Async'
    }
  },
  {
    channelName: 'channel2',
    module: { name: 'pkg2', verisonRange: '>=1.0.0', filePath: 'index.js' },
    functionQuery: {
      className: 'Class2',
      methodName: 'method2', 
      kind: 'Sync'
    }
  }
]


const modulePatch = new ModulePatch({ instrumentations });
modulePatch.patch()

To use the CJS patch you can run your Node.js application with the --require flag:

node --require cjs-patch.js your-app.js

Debugging

The debug module is used to provide insight into the patching process. Set DEBUG='@apm-js-collab*' to view these logs.

Additionally, any patched files can be written out by enabling dump mode. This is done by setting the environment variable TRACING_DUMP to any value. By default, it will write out file to the system's temporary directory as the parent directory. The target parent directory can be configured by setting the TRACING_DUMP_DIR environment variable to an absolute path. In either case, the resolved filename of the module being patched is appended. For example, if we are patching lib/index.js in the foo package, and we set a base directory of /tmp/dump/, then the patched code will be written to /tmp/dump/foo/lib/index.js.

Current Tags

  • 0.6.0                                ...           latest (4 days ago)

9 Versions

  • 0.6.0                                ...           4 days ago
  • 0.5.0                                ...           a month ago
  • 0.4.0                                ...           a month ago
  • 0.3.1                                ...           7 months ago
  • 0.3.0                                ...           7 months ago
  • 0.2.0                                ...           7 months ago
  • 0.1.1                                ...           8 months ago
  • 0.1.0                                ...           8 months ago
  • 0.0.1                                ...           8 months ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |