Skip to content

Commit

Permalink
[pinpoint-apm#140] Support nested async trace
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Nov 22, 2023
1 parent 5db9558 commit 598fe60
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 7,888 deletions.
5 changes: 1 addition & 4 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ class Agent {

log.warn('[Pinpoint Agent] Configuration', this.config)

if (!this.config.enable || this.config.enable.toString() !== 'true') {
global.__PINPOINT_ENABLED__ = false
if (!this.config || !this.config.enable || this.config.enable.toString() !== 'true') {
log.warn('[Pinpoint Agent][' + this.config.agentId + '] Disabled')
return
}

global.__PINPOINT_ENABLED__ = true
log.warn('[Pinpoint Agent][' + this.config.agentId + '] Init Started')

const agentId = this.config.agentId
Expand Down
5 changes: 1 addition & 4 deletions lib/context/context-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'use strict'

const async_hooks = require('async_hooks')

const traceObjectMap = new Map()

const init = (asyncId, type, triggerAsyncId, resource) => {

Check failure on line 12 in lib/context/context-manager.js

View workflow job for this annotation

GitHub Actions / Checkstyle

eslint.rules.no-unused-vars

'resource' is defined but never used. (no-unused-vars)

Check failure on line 12 in lib/context/context-manager.js

View workflow job for this annotation

GitHub Actions / Checkstyle

eslint.rules.no-unused-vars

'resource' is defined but never used. (no-unused-vars)

Check failure on line 12 in lib/context/context-manager.js

View workflow job for this annotation

GitHub Actions / Checkstyle

eslint.rules.no-unused-vars

'resource' is defined but never used. (no-unused-vars)
Expand All @@ -24,9 +23,7 @@ const destroy = (asyncId) => {
}

const start = () => {
if (global.__PINPOINT_ENABLED__) {
async_hooks.createHook({init, destroy}).enable()
}
async_hooks.createHook({init, destroy}).enable()
}

const getObject = () => {
Expand Down
18 changes: 17 additions & 1 deletion lib/instrumentation/context/local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
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()
}
Expand All @@ -35,4 +40,15 @@ class LocalStorage {
}
}

class EmptyLocalStorage {
run() {
}

getStore() {
}

disable() {
}
}

module.exports = new LocalStorage()
Loading

0 comments on commit 598fe60

Please sign in to comment.