@ohos-ports/pm2 0.0.0-stage → 7.1.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2607 -0
- package/CONTRIBUTING.md +124 -0
- package/GNU-AGPL-3.0.txt +665 -0
- package/LICENSE +1 -0
- package/README.md +255 -2
- package/SECURITY.md +41 -0
- package/bin/pm2 +3 -0
- package/bin/pm2-dev +3 -0
- package/bin/pm2-docker +3 -0
- package/bin/pm2-runtime +3 -0
- package/bin/pm2.ps1 +3 -0
- package/constants.js +113 -0
- package/index.js +12 -0
- package/lib/API/Configuration.js +212 -0
- package/lib/API/Containerizer.js +335 -0
- package/lib/API/Dashboard.js +726 -0
- package/lib/API/Deploy.js +117 -0
- package/lib/API/Extra.js +798 -0
- package/lib/API/ExtraMgmt/Docker.js +30 -0
- package/lib/API/Log.js +388 -0
- package/lib/API/LogManagement.js +351 -0
- package/lib/API/Modules/LOCAL.js +122 -0
- package/lib/API/Modules/Modularizer.js +148 -0
- package/lib/API/Modules/NPM.js +443 -0
- package/lib/API/Modules/TAR.js +368 -0
- package/lib/API/Modules/flagExt.js +46 -0
- package/lib/API/Modules/index.js +120 -0
- package/lib/API/Monit.js +247 -0
- package/lib/API/Serve.js +497 -0
- package/lib/API/Startup.js +630 -0
- package/lib/API/UX/helpers.js +213 -0
- package/lib/API/UX/index.js +9 -0
- package/lib/API/UX/pm2-describe.js +197 -0
- package/lib/API/UX/pm2-ls-minimal.js +31 -0
- package/lib/API/UX/pm2-ls.js +581 -0
- package/lib/API/Version.js +383 -0
- package/lib/API/interpreter.json +12 -0
- package/lib/API/pm2-plus/PM2IO.js +381 -0
- package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
- package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
- package/lib/API/pm2-plus/helpers.js +97 -0
- package/lib/API/pm2-plus/link.js +126 -0
- package/lib/API/pm2-plus/pres/motd +16 -0
- package/lib/API/pm2-plus/pres/motd.update +26 -0
- package/lib/API/pm2-plus/pres/welcome +28 -0
- package/lib/API/pm2-plus/process-selector.js +52 -0
- package/lib/API/schema.json +375 -0
- package/lib/API.js +1980 -0
- package/lib/Client.js +793 -0
- package/lib/Common.js +949 -0
- package/lib/Configuration.js +309 -0
- package/lib/Daemon.js +468 -0
- package/lib/Event.js +37 -0
- package/lib/God/ActionMethods.js +955 -0
- package/lib/God/ClusterMode.js +192 -0
- package/lib/God/ForkMode.js +205 -0
- package/lib/God/Methods.js +292 -0
- package/lib/God/Reload.js +300 -0
- package/lib/God/StdioLogger.js +239 -0
- package/lib/God.js +653 -0
- package/lib/HttpInterface.js +75 -0
- package/lib/OtelManager.js +74 -0
- package/lib/ProcessContainer.js +321 -0
- package/lib/ProcessContainerBun.js +355 -0
- package/lib/ProcessContainerFork.js +42 -0
- package/lib/ProcessContainerForkBun.js +31 -0
- package/lib/ProcessUtils.js +74 -0
- package/lib/TreeKill.js +111 -0
- package/lib/Utility.js +304 -0
- package/lib/VersionCheck.js +46 -0
- package/lib/Watcher.js +117 -0
- package/lib/Worker.js +200 -0
- package/lib/binaries/CLI.js +1092 -0
- package/lib/binaries/DevCLI.js +183 -0
- package/lib/binaries/Runtime.js +101 -0
- package/lib/binaries/Runtime4Docker.js +192 -0
- package/lib/completion.js +229 -0
- package/lib/completion.sh +40 -0
- package/lib/motd +36 -0
- package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
- package/lib/templates/ecosystem-es.tpl +24 -0
- package/lib/templates/ecosystem-simple-es.tpl +8 -0
- package/lib/templates/ecosystem-simple.tpl +6 -0
- package/lib/templates/ecosystem.tpl +22 -0
- package/lib/templates/init-scripts/launchd.tpl +35 -0
- package/lib/templates/init-scripts/openrc.tpl +52 -0
- package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
- package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
- package/lib/templates/init-scripts/rcd.tpl +44 -0
- package/lib/templates/init-scripts/smf.tpl +43 -0
- package/lib/templates/init-scripts/systemd-online.tpl +22 -0
- package/lib/templates/init-scripts/systemd.tpl +22 -0
- package/lib/templates/init-scripts/upstart.tpl +103 -0
- package/lib/templates/logrotate.d/pm2 +10 -0
- package/lib/templates/sample-apps/http-server/README.md +14 -0
- package/lib/templates/sample-apps/http-server/api.js +9 -0
- package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
- package/lib/templates/sample-apps/http-server/package.json +11 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
- package/lib/templates/sample-apps/python-app/README.md +4 -0
- package/lib/templates/sample-apps/python-app/echo.py +7 -0
- package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/python-app/package.json +11 -0
- package/lib/tools/Config.js +251 -0
- package/lib/tools/SysMetrics.js +375 -0
- package/lib/tools/copydirSync.js +101 -0
- package/lib/tools/deleteFolderRecursive.js +19 -0
- package/lib/tools/find-package-json.js +74 -0
- package/lib/tools/fmt.js +72 -0
- package/lib/tools/interpreter.js +88 -0
- package/lib/tools/isbinaryfile.js +94 -0
- package/lib/tools/json5.js +752 -0
- package/lib/tools/multimeter/bar.js +111 -0
- package/lib/tools/multimeter/charm/encode.js +18 -0
- package/lib/tools/multimeter/charm/index.js +305 -0
- package/lib/tools/multimeter/index.js +76 -0
- package/lib/tools/open.js +56 -0
- package/lib/tools/passwd.js +58 -0
- package/lib/tools/pm2-config-keys.js +165 -0
- package/lib/tools/prompt.js +76 -0
- package/lib/tools/serviceStop.js +149 -0
- package/lib/tools/sexec.js +55 -0
- package/lib/tools/treeify.js +113 -0
- package/lib/tools/typestrip.js +55 -0
- package/lib/tools/which.js +120 -0
- package/lib/tools/xdg-open +861 -0
- package/modules/blessed/LICENSE +20 -0
- package/modules/blessed/README.md +34 -0
- package/modules/blessed/index.js +1 -0
- package/modules/blessed/lib/alias.js +526 -0
- package/modules/blessed/lib/blessed.js +32 -0
- package/modules/blessed/lib/colors.js +530 -0
- package/modules/blessed/lib/events.js +189 -0
- package/modules/blessed/lib/gpmclient.js +221 -0
- package/modules/blessed/lib/helpers.js +165 -0
- package/modules/blessed/lib/keys.js +339 -0
- package/modules/blessed/lib/program.js +4297 -0
- package/modules/blessed/lib/tput.js +3022 -0
- package/modules/blessed/lib/unicode.js +885 -0
- package/modules/blessed/lib/widget.js +32 -0
- package/modules/blessed/lib/widgets/box.js +34 -0
- package/modules/blessed/lib/widgets/element.js +2570 -0
- package/modules/blessed/lib/widgets/list.js +599 -0
- package/modules/blessed/lib/widgets/log.js +83 -0
- package/modules/blessed/lib/widgets/node.js +282 -0
- package/modules/blessed/lib/widgets/screen.js +2298 -0
- package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
- package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
- package/modules/blessed/lib/widgets/text.js +35 -0
- package/modules/blessed/usr/linux +0 -0
- package/modules/blessed/usr/windows-ansi +0 -0
- package/modules/blessed/usr/xterm +0 -0
- package/modules/blessed/usr/xterm-256color +0 -0
- package/modules/blessed/usr/xterm.termcap +243 -0
- package/modules/chokidar/LICENSE +21 -0
- package/modules/chokidar/VENDORED.md +76 -0
- package/modules/chokidar/index.js +979 -0
- package/modules/chokidar/lib/brace-expand.js +180 -0
- package/modules/chokidar/lib/constants.js +66 -0
- package/modules/chokidar/lib/fsevents-handler.js +526 -0
- package/modules/chokidar/lib/nodefs-handler.js +654 -0
- package/modules/fclone.js +49 -0
- package/modules/pm2-axon/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/History.md +5 -0
- package/modules/pm2-axon/lib/configurable/Makefile +7 -0
- package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
- package/modules/pm2-axon/lib/configurable/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
- package/modules/pm2-axon/lib/configurable/package.json +68 -0
- package/modules/pm2-axon/lib/index.js +44 -0
- package/modules/pm2-axon/lib/plugins/queue.js +71 -0
- package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
- package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
- package/modules/pm2-axon/lib/sockets/pub.js +77 -0
- package/modules/pm2-axon/lib/sockets/pull.js +37 -0
- package/modules/pm2-axon/lib/sockets/push.js +32 -0
- package/modules/pm2-axon/lib/sockets/rep.js +73 -0
- package/modules/pm2-axon/lib/sockets/req.js +101 -0
- package/modules/pm2-axon/lib/sockets/sock.js +430 -0
- package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
- package/modules/pm2-axon/lib/sockets/sub.js +147 -0
- package/modules/pm2-axon/lib/utils.js +19 -0
- package/modules/pm2-axon-rpc/index.js +3 -0
- package/modules/pm2-axon-rpc/lib/client.js +63 -0
- package/modules/pm2-axon-rpc/lib/server.js +139 -0
- package/modules/pm2-io-agent/LICENSE +661 -0
- package/modules/pm2-io-agent/README.md +62 -0
- package/modules/pm2-io-agent/config.js +30 -0
- package/modules/pm2-io-agent/constants.js +118 -0
- package/modules/pm2-io-agent/index.js +2 -0
- package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
- package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
- package/modules/pm2-io-agent/src/PM2Client.js +112 -0
- package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
- package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
- package/modules/pm2-io-agent/src/Utility.js +392 -0
- package/modules/pm2-io-agent/src/WatchDog.js +70 -0
- package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
- package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
- package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
- package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
- package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
- package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
- package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
- package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
- package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
- package/modules/pm2-io-agent/src/utils/units.js +10 -0
- package/modules/pm2-io-bpm/configuration.js +141 -0
- package/modules/pm2-io-bpm/constants.js +10 -0
- package/modules/pm2-io-bpm/featureManager.js +110 -0
- package/modules/pm2-io-bpm/features/dependencies.js +48 -0
- package/modules/pm2-io-bpm/features/events.js +50 -0
- package/modules/pm2-io-bpm/features/metrics.js +102 -0
- package/modules/pm2-io-bpm/features/notify.js +238 -0
- package/modules/pm2-io-bpm/features/profiling.js +70 -0
- package/modules/pm2-io-bpm/features/tracing.js +174 -0
- package/modules/pm2-io-bpm/index.js +11 -0
- package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
- package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
- package/modules/pm2-io-bpm/metrics/network.js +132 -0
- package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
- package/modules/pm2-io-bpm/metrics/v8.js +104 -0
- package/modules/pm2-io-bpm/otel/constants.js +7 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
- package/modules/pm2-io-bpm/pmx.js +380 -0
- package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
- package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
- package/modules/pm2-io-bpm/serviceManager.js +21 -0
- package/modules/pm2-io-bpm/services/actions.js +159 -0
- package/modules/pm2-io-bpm/services/inspector.js +43 -0
- package/modules/pm2-io-bpm/services/metrics.js +186 -0
- package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
- package/modules/pm2-io-bpm/services/transport.js +11 -0
- package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
- package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
- package/modules/pm2-io-bpm/utils/EDS.js +113 -0
- package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
- package/modules/pm2-io-bpm/utils/autocast.js +61 -0
- package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
- package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
- package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
- package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
- package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
- package/modules/pm2-io-bpm/utils/module.js +67 -0
- package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
- package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
- package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
- package/modules/pm2-io-bpm/utils/units.js +16 -0
- package/modules/vizion/LICENSE +13 -0
- package/modules/vizion/README.md +133 -0
- package/modules/vizion/index.js +1 -0
- package/modules/vizion/lib/git/git.js +247 -0
- package/modules/vizion/lib/vizion.js +52 -0
- package/package.json +170 -4
- package/paths.js +121 -0
- package/pm2 +11 -0
- package/types/index.d.ts +732 -0
- package/types/tsconfig.json +14 -0
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const cst = require('../../constants.js')
|
|
4
|
+
const log = require('debug')('interactor:aggregator')
|
|
5
|
+
const Utility = require('../Utility.js')
|
|
6
|
+
const fclone = require('../../../fclone')
|
|
7
|
+
const Histogram = require('../utils/probes/Histogram')
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* # Data structure sent to interactor
|
|
12
|
+
*
|
|
13
|
+
* {
|
|
14
|
+
* 'process_name': {
|
|
15
|
+
* process : {}, // PM2 process meta data
|
|
16
|
+
* data : {
|
|
17
|
+
* routes : [ // array of all routes ordered by count
|
|
18
|
+
* {
|
|
19
|
+
* path: '/', // path of the route
|
|
20
|
+
* meta: {
|
|
21
|
+
* count: 50, // count of this route
|
|
22
|
+
* max: 300, // max latency of this route
|
|
23
|
+
* min: 50, // min latency of this route
|
|
24
|
+
* mean: 120 // mean latency of this route
|
|
25
|
+
* }
|
|
26
|
+
* variances: [{ // array of variance order by count
|
|
27
|
+
* spans : [
|
|
28
|
+
* ... // transactions
|
|
29
|
+
* ],
|
|
30
|
+
* count: 50, // count of this variance
|
|
31
|
+
* max: 300, // max latency of this variance
|
|
32
|
+
* min: 50, // min latency of this variance
|
|
33
|
+
* mean: 120 // mean latency of this variance
|
|
34
|
+
* }]
|
|
35
|
+
* }
|
|
36
|
+
* ],
|
|
37
|
+
* meta : {
|
|
38
|
+
* trace_count : 50, // trace number
|
|
39
|
+
* mean_latency : 40, // global app latency in ms
|
|
40
|
+
* http_meter : 30, // global app req per minutes
|
|
41
|
+
* db_meter : 20, // number of database transaction per min
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
module.exports = class TransactionAggregator {
|
|
49
|
+
constructor (pushInteractor) {
|
|
50
|
+
this.processes = {}
|
|
51
|
+
this.stackParser = pushInteractor._stackParser
|
|
52
|
+
this.pushInteractor = pushInteractor
|
|
53
|
+
|
|
54
|
+
this.LABELS = {
|
|
55
|
+
'HTTP_RESPONSE_CODE_LABEL_KEY': 'http/status_code',
|
|
56
|
+
'HTTP_URL_LABEL_KEY': 'http/url',
|
|
57
|
+
'HTTP_METHOD_LABEL_KEY': 'http/method',
|
|
58
|
+
'HTTP_RESPONSE_SIZE_LABEL_KEY': 'http/response/size',
|
|
59
|
+
'STACK_TRACE_DETAILS_KEY': 'stacktrace',
|
|
60
|
+
'ERROR_DETAILS_NAME': 'error/name',
|
|
61
|
+
'ERROR_DETAILS_MESSAGE': 'error/message',
|
|
62
|
+
'HTTP_SOURCE_IP': 'http/source/ip',
|
|
63
|
+
'HTTP_PATH_LABEL_KEY': 'http/path'
|
|
64
|
+
}
|
|
65
|
+
this.SPANS_DB = ['redis', 'mysql', 'pg', 'mongo', 'outbound_http']
|
|
66
|
+
this.REGEX_JSON_CLEANUP = /":(?!\[|{)\\"[^"]*\\"|":(["'])(?:(?=(\\?))\2.)*?\1|":(?!\[|{)[^,}\]]*|":\[[^{]*]/g
|
|
67
|
+
|
|
68
|
+
this.init()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* First method to call in real environment
|
|
73
|
+
* - Listen to restart event for initialization period
|
|
74
|
+
* - Clear aggregation on process stop
|
|
75
|
+
* - Launch worker to attach data to be pushed to KM
|
|
76
|
+
*/
|
|
77
|
+
init () {
|
|
78
|
+
// New Process Online, reset & wait a bit before processing
|
|
79
|
+
this.pushInteractor._ipm2.bus.on('process:event', (data) => {
|
|
80
|
+
if (data.event !== 'online' || !this.processes[data.process.name]) return false
|
|
81
|
+
|
|
82
|
+
let rev = (data.process.versioning && data.process.versioning.revision)
|
|
83
|
+
? data.process.versioning.revision : null
|
|
84
|
+
|
|
85
|
+
this.resetAggregation(data.process.name, {
|
|
86
|
+
rev: rev,
|
|
87
|
+
server: this.pushInteractor.opts.MACHINE_NAME
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// Process getting offline, delete aggregation
|
|
92
|
+
this.pushInteractor._ipm2.bus.on('process:event', (data) => {
|
|
93
|
+
if (data.event !== 'stop' || !this.processes[data.process.name]) return false
|
|
94
|
+
log('Deleting aggregation for %s', data.process.name)
|
|
95
|
+
delete this.processes[data.process.name]
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
this.launchWorker()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Reset aggregation for target app_name
|
|
103
|
+
*/
|
|
104
|
+
resetAggregation (appName, meta) {
|
|
105
|
+
log('Reseting agg for app:%s meta:%j', appName, meta)
|
|
106
|
+
|
|
107
|
+
if (this.processes[appName].initialization_timeout) {
|
|
108
|
+
log('Reseting initialization timeout app:%s', appName)
|
|
109
|
+
clearTimeout(this.processes[appName].initialization_timeout)
|
|
110
|
+
clearInterval(this.processes[appName].notifier)
|
|
111
|
+
this.processes[appName].notifier = null
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.processes[appName] = this.initializeRouteMeta({
|
|
115
|
+
name: appName,
|
|
116
|
+
rev: meta.rev,
|
|
117
|
+
server: meta.server
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
let start = Date.now()
|
|
121
|
+
this.processes[appName].notifier = setInterval(_ => {
|
|
122
|
+
let elapsed = Date.now() - start
|
|
123
|
+
// failsafe
|
|
124
|
+
if (elapsed / 1000 > cst.AGGREGATION_DURATION) {
|
|
125
|
+
clearInterval(this.processes[appName].notifier)
|
|
126
|
+
this.processes[appName].notifier = null
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let msg = {
|
|
130
|
+
data: {
|
|
131
|
+
learning_duration: cst.AGGREGATION_DURATION,
|
|
132
|
+
elapsed: elapsed
|
|
133
|
+
},
|
|
134
|
+
process: this.processes[appName].process
|
|
135
|
+
}
|
|
136
|
+
this.pushInteractor && this.pushInteractor.transport.send('axm:transaction:learning', msg)
|
|
137
|
+
}, 5000)
|
|
138
|
+
|
|
139
|
+
this.processes[appName].initialization_timeout = setTimeout(_ => {
|
|
140
|
+
log('Initialization timeout finished for app:%s', appName)
|
|
141
|
+
clearInterval(this.processes[appName].notifier)
|
|
142
|
+
this.processes[appName].notifier = null
|
|
143
|
+
this.processes[appName].initialization_timeout = null
|
|
144
|
+
}, cst.AGGREGATION_DURATION)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Clear aggregated data for all process
|
|
149
|
+
*/
|
|
150
|
+
clearData () {
|
|
151
|
+
Object.keys(this.processes).forEach((process) => {
|
|
152
|
+
this.resetAggregation(process, this.processes[process].process)
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Generate new entry for application
|
|
158
|
+
*
|
|
159
|
+
* @param {Object} process process meta
|
|
160
|
+
*/
|
|
161
|
+
initializeRouteMeta (process) {
|
|
162
|
+
if (process.pm_id) delete process.pm_id
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
routes: {},
|
|
166
|
+
meta: {
|
|
167
|
+
trace_count: 0,
|
|
168
|
+
http_meter: new Utility.EWMA(),
|
|
169
|
+
db_meter: new Utility.EWMA(),
|
|
170
|
+
histogram: new Histogram({ measurement: 'median' }),
|
|
171
|
+
db_histograms: {}
|
|
172
|
+
},
|
|
173
|
+
process: process
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
getAggregation () {
|
|
178
|
+
return this.processes
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
validateData (packet) {
|
|
182
|
+
if (!packet || !packet.data) {
|
|
183
|
+
log('Packet malformated', packet)
|
|
184
|
+
return false
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!packet.process) {
|
|
188
|
+
log('Got packet without process: %j', packet)
|
|
189
|
+
return false
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!packet.data.spans || !packet.data.spans[0]) {
|
|
193
|
+
log('Trace without spans: %s', Object.keys(packet.data))
|
|
194
|
+
return false
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (!packet.data.spans[0].labels) {
|
|
198
|
+
log('Trace spans without labels: %s', Object.keys(packet.data.spans))
|
|
199
|
+
return false
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return true
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Main method to aggregate and compute stats for traces
|
|
207
|
+
*
|
|
208
|
+
* @param {Object} packet
|
|
209
|
+
* @param {Object} packet.process process metadata
|
|
210
|
+
* @param {Object} packet.data trace
|
|
211
|
+
*/
|
|
212
|
+
aggregate (packet) {
|
|
213
|
+
if (this.validateData(packet) === false) return false
|
|
214
|
+
|
|
215
|
+
const newTrace = packet.data
|
|
216
|
+
const appName = packet.process.name
|
|
217
|
+
|
|
218
|
+
if (!this.processes[appName]) {
|
|
219
|
+
this.processes[appName] = this.initializeRouteMeta(packet.process)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let process = this.processes[appName]
|
|
223
|
+
|
|
224
|
+
// Get http path of current span
|
|
225
|
+
let path = newTrace.spans[0].labels[this.LABELS.HTTP_PATH_LABEL_KEY]
|
|
226
|
+
if (!path) return false
|
|
227
|
+
|
|
228
|
+
// Cleanup spans
|
|
229
|
+
this.censorSpans(newTrace.spans)
|
|
230
|
+
|
|
231
|
+
// remove spans with startTime == endTime
|
|
232
|
+
newTrace.spans = newTrace.spans.filter((span) => {
|
|
233
|
+
return span.endTime !== span.startTime
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
// compute duration of child spans
|
|
237
|
+
newTrace.spans.forEach((span) => {
|
|
238
|
+
span.mean = Math.round(new Date(span.endTime) - new Date(span.startTime))
|
|
239
|
+
delete span.endTime
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
// Update app meta (mean_latency, http_meter, db_meter, trace_count)
|
|
243
|
+
newTrace.spans.forEach((span) => {
|
|
244
|
+
if (!span.name || !span.kind) return false
|
|
245
|
+
|
|
246
|
+
if (span.kind === 'RPC_SERVER') {
|
|
247
|
+
process.meta.histogram.update(span.mean)
|
|
248
|
+
return process.meta.http_meter.update()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Override outbount http queries for processing
|
|
252
|
+
if (span.labels && span.labels['http/method'] && span.labels['http/status_code']) {
|
|
253
|
+
span.labels['service'] = span.name
|
|
254
|
+
span.name = 'outbound_http'
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
for (let i = 0, len = this.SPANS_DB.length; i < len; i++) {
|
|
258
|
+
if (span.name.indexOf(this.SPANS_DB[i]) > -1) {
|
|
259
|
+
process.meta.db_meter.update()
|
|
260
|
+
if (!process.meta.db_histograms[this.SPANS_DB[i]]) {
|
|
261
|
+
process.meta.db_histograms[this.SPANS_DB[i]] = new Histogram({ measurement: 'mean' })
|
|
262
|
+
}
|
|
263
|
+
process.meta.db_histograms[this.SPANS_DB[i]].update(span.mean)
|
|
264
|
+
break
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
process.meta.trace_count++
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Handle traces aggregation
|
|
273
|
+
*/
|
|
274
|
+
if (path[0] === '/' && path !== '/') {
|
|
275
|
+
path = path.substr(1, path.length - 1)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
let matched = this.matchPath(path, process.routes)
|
|
279
|
+
|
|
280
|
+
if (!matched) {
|
|
281
|
+
process.routes[path] = []
|
|
282
|
+
this.mergeTrace(process.routes[path], newTrace, process)
|
|
283
|
+
} else {
|
|
284
|
+
this.mergeTrace(process.routes[matched], newTrace, process)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return this.processes
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Merge new trace and compute mean, min, max, count
|
|
292
|
+
*
|
|
293
|
+
* @param {Object} aggregated previous aggregated route
|
|
294
|
+
* @param {Object} trace
|
|
295
|
+
*/
|
|
296
|
+
mergeTrace (aggregated, trace, process) {
|
|
297
|
+
if (!aggregated || !trace) return
|
|
298
|
+
|
|
299
|
+
// if the trace doesn't any spans stop aggregation here
|
|
300
|
+
if (trace.spans.length === 0) return
|
|
301
|
+
|
|
302
|
+
// create data structure if needed
|
|
303
|
+
if (!aggregated.variances) aggregated.variances = []
|
|
304
|
+
if (!aggregated.meta) {
|
|
305
|
+
aggregated.meta = {
|
|
306
|
+
histogram: new Histogram({ measurement: 'median' }),
|
|
307
|
+
meter: new Utility.EWMA()
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
aggregated.meta.histogram.update(trace.spans[0].mean)
|
|
312
|
+
aggregated.meta.meter.update()
|
|
313
|
+
|
|
314
|
+
const merge = (variance) => {
|
|
315
|
+
// no variance found so its a new one
|
|
316
|
+
if (variance == null) {
|
|
317
|
+
delete trace.projectId
|
|
318
|
+
delete trace.traceId
|
|
319
|
+
trace.histogram = new Histogram({ measurement: 'median' })
|
|
320
|
+
trace.histogram.update(trace.spans[0].mean)
|
|
321
|
+
|
|
322
|
+
trace.spans.forEach((span) => {
|
|
323
|
+
span.histogram = new Histogram({ measurement: 'median' })
|
|
324
|
+
span.histogram.update(span.mean)
|
|
325
|
+
delete span.mean
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
// parse strackrace
|
|
329
|
+
this.parseStacktrace(trace.spans)
|
|
330
|
+
aggregated.variances.push(trace)
|
|
331
|
+
} else {
|
|
332
|
+
// check to see if request is anormally slow, if yes send it as inquisitor
|
|
333
|
+
if (trace.spans[0].mean > variance.histogram.percentiles([0.95])[0.95] &&
|
|
334
|
+
typeof pushInteractor !== 'undefined' && !process.initialization_timeout) {
|
|
335
|
+
// serialize and add metadata
|
|
336
|
+
this.parseStacktrace(trace.spans)
|
|
337
|
+
let data = {
|
|
338
|
+
trace: fclone(trace.spans),
|
|
339
|
+
variance: fclone(variance.spans.map((span) => {
|
|
340
|
+
return {
|
|
341
|
+
labels: span.labels,
|
|
342
|
+
kind: span.kind,
|
|
343
|
+
name: span.name,
|
|
344
|
+
startTime: span.startTime,
|
|
345
|
+
percentiles: {
|
|
346
|
+
p5: variance.histogram.percentiles([0.5])[0.5],
|
|
347
|
+
p95: variance.histogram.percentiles([0.95])[0.95]
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
})),
|
|
351
|
+
meta: {
|
|
352
|
+
value: trace.spans[0].mean,
|
|
353
|
+
percentiles: {
|
|
354
|
+
p5: variance.histogram.percentiles([0.5])[0.5],
|
|
355
|
+
p75: variance.histogram.percentiles([0.75])[0.75],
|
|
356
|
+
p95: variance.histogram.percentiles([0.95])[0.95],
|
|
357
|
+
p99: variance.histogram.percentiles([0.99])[0.99]
|
|
358
|
+
},
|
|
359
|
+
min: variance.histogram.getMin(),
|
|
360
|
+
max: variance.histogram.getMax(),
|
|
361
|
+
count: variance.histogram.getCount()
|
|
362
|
+
},
|
|
363
|
+
process: process.process
|
|
364
|
+
}
|
|
365
|
+
this.pushInteractor.transport.send('axm:transaction:outlier', data)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// variance found, merge spans
|
|
369
|
+
variance.histogram.update(trace.spans[0].mean)
|
|
370
|
+
|
|
371
|
+
// update duration of spans to be mean
|
|
372
|
+
this.updateSpanDuration(variance.spans, trace.spans, variance.count)
|
|
373
|
+
|
|
374
|
+
// delete stacktrace before merging
|
|
375
|
+
trace.spans.forEach((span) => {
|
|
376
|
+
delete span.labels.stacktrace
|
|
377
|
+
})
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// for every variance, check spans same variance
|
|
382
|
+
for (let i = 0; i < aggregated.variances.length; i++) {
|
|
383
|
+
if (this.compareList(aggregated.variances[i].spans, trace.spans)) {
|
|
384
|
+
return merge(aggregated.variances[i])
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
// else its a new variance
|
|
388
|
+
return merge(null)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Parkour simultaneously both spans list to update value of the first one using value of the second one
|
|
393
|
+
* The first should be variance already aggregated for which we want to merge the second one
|
|
394
|
+
* The second one is a new trace, so we need to re-compute mean/min/max time for each spans
|
|
395
|
+
*/
|
|
396
|
+
updateSpanDuration (spans, newSpans) {
|
|
397
|
+
for (let i = 0, len = spans.length; i < len; i++) {
|
|
398
|
+
if (!newSpans[i]) continue
|
|
399
|
+
spans[i].histogram.update(newSpans[i].mean)
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Compare two spans list by going down on each span and comparing child and attribute
|
|
405
|
+
*/
|
|
406
|
+
compareList (one, two) {
|
|
407
|
+
if (one.length !== two.length) return false
|
|
408
|
+
|
|
409
|
+
for (let i = 0, len = one; i < len; i++) {
|
|
410
|
+
if (one[i].name !== two[i].name) return false
|
|
411
|
+
if (one[i].kind !== two[i].kind) return false
|
|
412
|
+
if (!one[i].labels && two[i].labels) return false
|
|
413
|
+
if (one[i].labels && !two[i].labels) return false
|
|
414
|
+
if (one[i].labels.length !== two[i].labels.length) return false
|
|
415
|
+
}
|
|
416
|
+
return true
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Will return the route if we found an already matched route
|
|
421
|
+
*/
|
|
422
|
+
matchPath (path, routes) {
|
|
423
|
+
// empty route is / without the fist slash
|
|
424
|
+
if (!path || !routes) return false
|
|
425
|
+
if (path === '/') return routes[path] ? path : null
|
|
426
|
+
|
|
427
|
+
// remove the last slash if exist
|
|
428
|
+
if (path[path.length - 1] === '/') {
|
|
429
|
+
path = path.substr(0, path.length - 1)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// split to get array of segment
|
|
433
|
+
path = path.split('/')
|
|
434
|
+
|
|
435
|
+
// if the path has only one segment, we just need to compare the key
|
|
436
|
+
if (path.length === 1) return routes[path[0]] ? routes[path[0]] : null
|
|
437
|
+
|
|
438
|
+
// check in routes already stored for match
|
|
439
|
+
let keys = Object.keys(routes)
|
|
440
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
441
|
+
let route = keys[i]
|
|
442
|
+
let segments = route.split('/')
|
|
443
|
+
|
|
444
|
+
if (segments.length !== path.length) continue
|
|
445
|
+
|
|
446
|
+
for (let j = path.length - 1; j >= 0; j--) {
|
|
447
|
+
// different segment, try to find if new route or not
|
|
448
|
+
if (path[j] !== segments[j]) {
|
|
449
|
+
// if the aggregator already have matched that segment with a wildcard and the next segment is the same
|
|
450
|
+
if (this.isIdentifier(path[j]) && segments[j] === '*' && path[j - 1] === segments[j - 1]) {
|
|
451
|
+
return segments.join('/')
|
|
452
|
+
// case a let in url match, so we continue because they must be other let in url
|
|
453
|
+
} else if (path[j - 1] !== undefined && path[j - 1] === segments[j - 1] && this.isIdentifier(path[j]) && this.isIdentifier(segments[j])) {
|
|
454
|
+
segments[j] = '*'
|
|
455
|
+
// update routes in cache
|
|
456
|
+
routes[segments.join('/')] = routes[route]
|
|
457
|
+
delete routes[keys[i]]
|
|
458
|
+
return segments.join('/')
|
|
459
|
+
} else {
|
|
460
|
+
break
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// if finish to iterate over segment of path, we must be on the same route
|
|
465
|
+
if (j === 0) return segments.join('/')
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
launchWorker () {
|
|
471
|
+
this._worker = setInterval(_ => {
|
|
472
|
+
let normalized = this.prepareAggregationforShipping()
|
|
473
|
+
Object.keys(normalized).forEach((key) => {
|
|
474
|
+
this.pushInteractor.transport.send('axm:transaction', normalized[key])
|
|
475
|
+
})
|
|
476
|
+
}, cst.TRACE_FLUSH_INTERVAL)
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Normalize aggregation
|
|
481
|
+
*/
|
|
482
|
+
prepareAggregationforShipping () {
|
|
483
|
+
let normalized = {}
|
|
484
|
+
|
|
485
|
+
// Iterate each applications
|
|
486
|
+
Object.keys(this.processes).forEach((appName) => {
|
|
487
|
+
let process = this.processes[appName]
|
|
488
|
+
let routes = process.routes
|
|
489
|
+
|
|
490
|
+
if (process.initialization_timeout) {
|
|
491
|
+
log('Waiting for app %s to be initialized', appName)
|
|
492
|
+
return null
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
normalized[appName] = {
|
|
496
|
+
data: {
|
|
497
|
+
routes: [],
|
|
498
|
+
meta: fclone({
|
|
499
|
+
trace_count: process.meta.trace_count,
|
|
500
|
+
http_meter: Math.round(process.meta.http_meter.rate(1000) * 100) / 100,
|
|
501
|
+
db_meter: Math.round(process.meta.db_meter.rate(1000) * 100) / 100,
|
|
502
|
+
http_percentiles: {
|
|
503
|
+
median: process.meta.histogram.percentiles([0.5])[0.5],
|
|
504
|
+
p95: process.meta.histogram.percentiles([0.95])[0.95],
|
|
505
|
+
p99: process.meta.histogram.percentiles([0.99])[0.99]
|
|
506
|
+
},
|
|
507
|
+
db_percentiles: {}
|
|
508
|
+
})
|
|
509
|
+
},
|
|
510
|
+
process: process.process
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// compute percentiles for each db spans if they exist
|
|
514
|
+
this.SPANS_DB.forEach((name) => {
|
|
515
|
+
let histogram = process.meta.db_histograms[name]
|
|
516
|
+
if (!histogram) return
|
|
517
|
+
normalized[appName].data.meta.db_percentiles[name] = fclone(histogram.percentiles([0.5])[0.5])
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
Object.keys(routes).forEach((path) => {
|
|
521
|
+
let data = routes[path]
|
|
522
|
+
|
|
523
|
+
// hard check for invalid data
|
|
524
|
+
if (!data.variances || data.variances.length === 0) return
|
|
525
|
+
|
|
526
|
+
// get top 5 variances of the same route
|
|
527
|
+
const variances = data.variances.sort((a, b) => {
|
|
528
|
+
return b.count - a.count
|
|
529
|
+
}).slice(0, 5)
|
|
530
|
+
|
|
531
|
+
// create a copy without reference to stored one
|
|
532
|
+
let routeCopy = {
|
|
533
|
+
path: path === '/' ? '/' : '/' + path,
|
|
534
|
+
meta: fclone({
|
|
535
|
+
min: data.meta.histogram.getMin(),
|
|
536
|
+
max: data.meta.histogram.getMax(),
|
|
537
|
+
count: data.meta.histogram.getCount(),
|
|
538
|
+
meter: Math.round(data.meta.meter.rate(1000) * 100) / 100,
|
|
539
|
+
median: data.meta.histogram.percentiles([0.5])[0.5],
|
|
540
|
+
p95: data.meta.histogram.percentiles([0.95])[0.95]
|
|
541
|
+
}),
|
|
542
|
+
variances: []
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
variances.forEach((variance) => {
|
|
546
|
+
// hard check for invalid data
|
|
547
|
+
if (!variance.spans || variance.spans.length === 0) return
|
|
548
|
+
|
|
549
|
+
// deep copy of variances data
|
|
550
|
+
let tmp = fclone({
|
|
551
|
+
spans: [],
|
|
552
|
+
count: variance.histogram.getCount(),
|
|
553
|
+
min: variance.histogram.getMin(),
|
|
554
|
+
max: variance.histogram.getMax(),
|
|
555
|
+
median: variance.histogram.percentiles([0.5])[0.5],
|
|
556
|
+
p95: variance.histogram.percentiles([0.95])[0.95]
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
// get data for each span
|
|
560
|
+
variance.spans.forEach((span) => {
|
|
561
|
+
tmp.spans.push(fclone({
|
|
562
|
+
name: span.name,
|
|
563
|
+
labels: span.labels,
|
|
564
|
+
kind: span.kind,
|
|
565
|
+
startTime: span.startTime,
|
|
566
|
+
min: span.histogram.getMin(),
|
|
567
|
+
max: span.histogram.getMax(),
|
|
568
|
+
median: span.histogram.percentiles([0.5])[0.5]
|
|
569
|
+
}))
|
|
570
|
+
})
|
|
571
|
+
// push serialized into normalized data
|
|
572
|
+
routeCopy.variances.push(tmp)
|
|
573
|
+
})
|
|
574
|
+
// push the route into normalized data
|
|
575
|
+
normalized[appName].data.routes.push(routeCopy)
|
|
576
|
+
})
|
|
577
|
+
})
|
|
578
|
+
|
|
579
|
+
return normalized
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Check if the string can be a id of some sort
|
|
584
|
+
*
|
|
585
|
+
* @param {String} id
|
|
586
|
+
*/
|
|
587
|
+
isIdentifier (id) {
|
|
588
|
+
id = typeof (id) !== 'string' ? id + '' : id
|
|
589
|
+
|
|
590
|
+
// uuid v1/v4 with/without dash
|
|
591
|
+
if (id.match(/[0-9a-f]{8}-[0-9a-f]{4}-[14][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{12}[14][0-9a-f]{19}/i)) {
|
|
592
|
+
return true
|
|
593
|
+
// if number
|
|
594
|
+
} else if (id.match(/\d+/)) {
|
|
595
|
+
return true
|
|
596
|
+
// if suit of nbr/letters
|
|
597
|
+
} else if (id.match(/[0-9]+[a-z]+|[a-z]+[0-9]+/)) {
|
|
598
|
+
return true
|
|
599
|
+
// if match pattern with multiple char spaced by . - _ @
|
|
600
|
+
} else if (id.match(/((?:[0-9a-zA-Z]+[@\-_.][0-9a-zA-Z]+|[0-9a-zA-Z]+[@\-_.]|[@\-_.][0-9a-zA-Z]+)+)/)) {
|
|
601
|
+
return true
|
|
602
|
+
}
|
|
603
|
+
return false
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Cleanup trace data
|
|
608
|
+
* - delete result(s)
|
|
609
|
+
* - replace labels value with a question mark
|
|
610
|
+
*
|
|
611
|
+
* @param {Object} spans list of span for a trace
|
|
612
|
+
*/
|
|
613
|
+
censorSpans (spans) {
|
|
614
|
+
if (!spans) return log('spans is null')
|
|
615
|
+
if (cst.DEBUG) return
|
|
616
|
+
|
|
617
|
+
spans.forEach((span) => {
|
|
618
|
+
if (!span.labels) return
|
|
619
|
+
|
|
620
|
+
delete span.labels.results
|
|
621
|
+
delete span.labels.result
|
|
622
|
+
delete span.spanId
|
|
623
|
+
delete span.parentSpanId
|
|
624
|
+
delete span.labels.values
|
|
625
|
+
|
|
626
|
+
Object.keys(span.labels).forEach((key) => {
|
|
627
|
+
if (typeof (span.labels[key]) === 'string' && key !== 'stacktrace') {
|
|
628
|
+
span.labels[key] = span.labels[key].replace(this.REGEX_JSON_CLEANUP, '\": \"?\"') // eslint-disable-line
|
|
629
|
+
}
|
|
630
|
+
})
|
|
631
|
+
})
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Parse stackrace of spans to extract and normalize data
|
|
636
|
+
*
|
|
637
|
+
* @param {Object} spans list of span for a trace
|
|
638
|
+
*/
|
|
639
|
+
parseStacktrace (spans) {
|
|
640
|
+
if (!spans) return log('spans is null')
|
|
641
|
+
|
|
642
|
+
spans.forEach((span) => {
|
|
643
|
+
// if empty make sure that it doesnt exist
|
|
644
|
+
if (!span ||
|
|
645
|
+
!span.labels ||
|
|
646
|
+
!span.labels.stacktrace ||
|
|
647
|
+
typeof (span.labels.stacktrace) !== 'string') return
|
|
648
|
+
|
|
649
|
+
// you never know what come through that door
|
|
650
|
+
try {
|
|
651
|
+
span.labels.stacktrace = JSON.parse(span.labels.stacktrace)
|
|
652
|
+
} catch (e) {
|
|
653
|
+
return
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (!span.labels.stacktrace || !(span.labels.stacktrace.stack_frame instanceof Array)) return
|
|
657
|
+
// parse the stacktrace
|
|
658
|
+
let result = this.stackParser.parse(span.labels.stacktrace.stack_frame)
|
|
659
|
+
if (result) {
|
|
660
|
+
span.labels['source/file'] = result.callsite || undefined
|
|
661
|
+
span.labels['source/context'] = result.context || undefined
|
|
662
|
+
}
|
|
663
|
+
})
|
|
664
|
+
|
|
665
|
+
spans.forEach((span) => {
|
|
666
|
+
if (!span || !span.labels) return
|
|
667
|
+
delete span.labels.stacktrace
|
|
668
|
+
})
|
|
669
|
+
}
|
|
670
|
+
}
|