Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ To load esm loader:
```js
// esm-loader.mjs
import { register } from 'node:module';
const packages = new Set(['pkg1', 'pkg2']);
const instrumentations = [
{
channelName: 'channel1',
Expand All @@ -31,7 +30,7 @@ const instrumentations = [
]

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

Expand All @@ -46,7 +45,6 @@ To load CJS patch:
```js
// cjs-patch.js
const ModulePatch = require('@apm-js-collab/tracing-hooks')
const packages = new Set(['pkg1', 'pkg2']);
const instrumentations = [
{
channelName: 'channel1',
Expand All @@ -61,15 +59,15 @@ const instrumentations = [
channelName: 'channel2',
module: { name: 'pkg2', verisonRange: '>=1.0.0', filePath: 'index.js' },
functionQuery: {
className: 'Class2,
className: 'Class2',
methodName: 'method2',
kind: 'Sync'
}
}
]


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

Expand Down
2 changes: 1 addition & 1 deletion hook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let instrumentator = null
export async function initialize(data = {}) {
const instrumentations = data?.instrumentations || []
instrumentator = create(instrumentations)
packages = data?.packages || new Set()
packages = new Set(instrumentations.map(i => i.module.name))
transformers = new Map()
}

Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const getPackageVersion = require('./lib/get-package-version')
const debug = require('debug')('@apm-js-collab/tracing-hooks:module-patch')

class ModulePatch {
constructor({ packages = new Set(), instrumentations = [] } = {}) {
this.packages = packages
constructor({ instrumentations = [] } = {}) {
this.packages = new Set(instrumentations.map(i => i.module.name))
this.instrumentator = create(instrumentations)
this.transformers = new Map()
this.resolve = Module._resolveFilename
Expand Down
Loading