pinpoint-node-agent
Version:
Pinpoint node agent provided by NAVER
61 lines (48 loc) • 1.18 kB
JavaScript
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/
const semver = require('semver')
const AsyncContextLocalStorage = require('./async-context-local-storage')
const AsyncHooksLocalStorage = require('./async-hooks-local-storage')
const { getConfig } = require('../../config')
class LocalStorage {
constructor() {
this.storage = this.createLocalStorage()
}
createLocalStorage() {
const config = getConfig()
if (config && !config.enable) {
return new EmptyLocalStorage()
}
if (!semver.satisfies(process.version, '>=16.4.0')) {
return new AsyncHooksLocalStorage()
}
return new AsyncContextLocalStorage()
}
run(store, callback) {
return this.storage.run(store, callback)
}
getStore() {
return this.storage.getStore()
}
disable() {
this.storage.disable()
}
enterWith(store) {
this.storage.enterWith(store)
}
}
class EmptyLocalStorage {
run() {
}
getStore() {
}
disable() {
}
enterWith() {
}
}
module.exports = new LocalStorage()