Skip to content

apm-js-collab/tracing-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tracing Hooks

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

Usage

To load esm loader:

import { register } from 'node:module';
const packages = new Set('pkg1', 'pkg2');
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, packages }
});

To load CJS patch:

const ModulePatch = require('@apm-js-collab/tracing-hooks')
const packages = new Set('pkg1', 'pkg2');
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, packages });
modulePatch.patch()

About

ESM and CJS patch to load orchestrion

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published