@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,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const api = require('@opentelemetry/api')
|
|
18
|
+
const { hrTimeToMicroseconds } = require('@opentelemetry/core')
|
|
19
|
+
const zipkinTypes = require('./types')
|
|
20
|
+
|
|
21
|
+
const ZIPKIN_SPAN_KIND_MAPPING = {
|
|
22
|
+
[api.SpanKind.CLIENT]: zipkinTypes.SpanKind.CLIENT,
|
|
23
|
+
[api.SpanKind.SERVER]: zipkinTypes.SpanKind.SERVER,
|
|
24
|
+
[api.SpanKind.CONSUMER]: zipkinTypes.SpanKind.CONSUMER,
|
|
25
|
+
[api.SpanKind.PRODUCER]: zipkinTypes.SpanKind.PRODUCER,
|
|
26
|
+
// When absent, the span is local.
|
|
27
|
+
[api.SpanKind.INTERNAL]: undefined,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const defaultStatusCodeTagName = 'otel.status_code'
|
|
31
|
+
const defaultStatusErrorTagName = 'error'
|
|
32
|
+
|
|
33
|
+
// The PM2.io backend and frontend read the pre-stable HTTP semantic convention
|
|
34
|
+
// tags (http.method, http.status_code, http.target, ...). Newer
|
|
35
|
+
// @opentelemetry/instrumentation-http (>= 0.220.0) only emits the stable
|
|
36
|
+
// names, so we alias them back to the legacy ones.
|
|
37
|
+
const LEGACY_HTTP_TAG_ALIASES = {
|
|
38
|
+
'http.request.method': 'http.method',
|
|
39
|
+
'http.response.status_code': 'http.status_code',
|
|
40
|
+
'url.full': 'http.url',
|
|
41
|
+
'url.scheme': 'http.scheme',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _addLegacyHttpTags (tags) {
|
|
45
|
+
for (const stableName of Object.keys(LEGACY_HTTP_TAG_ALIASES)) {
|
|
46
|
+
const legacyName = LEGACY_HTTP_TAG_ALIASES[stableName]
|
|
47
|
+
if (tags[stableName] !== undefined && tags[legacyName] === undefined) {
|
|
48
|
+
tags[legacyName] = tags[stableName]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Legacy http.target is the path with the query string
|
|
52
|
+
if (tags['url.path'] !== undefined && tags['http.target'] === undefined) {
|
|
53
|
+
tags['http.target'] = tags['url.query'] !== undefined
|
|
54
|
+
? tags['url.path'] + '?' + tags['url.query']
|
|
55
|
+
: tags['url.path']
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Translate OpenTelemetry ReadableSpan to ZipkinSpan format
|
|
61
|
+
* @param span Span to be translated
|
|
62
|
+
*/
|
|
63
|
+
function toZipkinSpan (span, serviceName, statusCodeTagName, statusErrorTagName) {
|
|
64
|
+
const zipkinSpan = {
|
|
65
|
+
traceId: span.spanContext().traceId,
|
|
66
|
+
parentId: span.parentSpanId || (span.parentSpanContext && span.parentSpanContext.spanId),
|
|
67
|
+
name: span.name,
|
|
68
|
+
id: span.spanContext().spanId,
|
|
69
|
+
kind: ZIPKIN_SPAN_KIND_MAPPING[span.kind],
|
|
70
|
+
timestamp: hrTimeToMicroseconds(span.startTime),
|
|
71
|
+
duration: Math.round(hrTimeToMicroseconds(span.duration)),
|
|
72
|
+
localEndpoint: { serviceName },
|
|
73
|
+
tags: _toZipkinTags(span, statusCodeTagName, statusErrorTagName),
|
|
74
|
+
annotations: span.events.length
|
|
75
|
+
? _toZipkinAnnotations(span.events)
|
|
76
|
+
: undefined,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return zipkinSpan
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Converts OpenTelemetry Span properties to Zipkin Tags format. */
|
|
83
|
+
function _toZipkinTags (
|
|
84
|
+
{ attributes, resource, status, droppedAttributesCount, droppedEventsCount, droppedLinksCount },
|
|
85
|
+
statusCodeTagName,
|
|
86
|
+
statusErrorTagName
|
|
87
|
+
) {
|
|
88
|
+
const tags = {}
|
|
89
|
+
for (const key of Object.keys(attributes)) {
|
|
90
|
+
tags[key] = String(attributes[key])
|
|
91
|
+
}
|
|
92
|
+
_addLegacyHttpTags(tags)
|
|
93
|
+
if (status.code !== api.SpanStatusCode.UNSET) {
|
|
94
|
+
tags[statusCodeTagName] = String(api.SpanStatusCode[status.code])
|
|
95
|
+
}
|
|
96
|
+
if (status.code === api.SpanStatusCode.ERROR && status.message) {
|
|
97
|
+
tags[statusErrorTagName] = status.message
|
|
98
|
+
}
|
|
99
|
+
/* Add droppedAttributesCount as a tag */
|
|
100
|
+
if (droppedAttributesCount) {
|
|
101
|
+
tags['otel.dropped_attributes_count'] = String(droppedAttributesCount)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Add droppedEventsCount as a tag */
|
|
105
|
+
if (droppedEventsCount) {
|
|
106
|
+
tags['otel.dropped_events_count'] = String(droppedEventsCount)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Add droppedLinksCount as a tag */
|
|
110
|
+
if (droppedLinksCount) {
|
|
111
|
+
tags['otel.dropped_links_count'] = String(droppedLinksCount)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
Object.keys(resource.attributes).forEach(
|
|
115
|
+
name => (tags[name] = String(resource.attributes[name]))
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return tags
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Converts OpenTelemetry Events to Zipkin Annotations format.
|
|
123
|
+
*/
|
|
124
|
+
function _toZipkinAnnotations (events) {
|
|
125
|
+
return events.map(event => ({
|
|
126
|
+
timestamp: Math.round(hrTimeToMicroseconds(event.time)),
|
|
127
|
+
value: event.name,
|
|
128
|
+
}))
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = {
|
|
132
|
+
defaultStatusCodeTagName,
|
|
133
|
+
defaultStatusErrorTagName,
|
|
134
|
+
toZipkinSpan,
|
|
135
|
+
_toZipkinTags,
|
|
136
|
+
_toZipkinAnnotations,
|
|
137
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const SpanKind = {
|
|
18
|
+
CLIENT: 'CLIENT',
|
|
19
|
+
SERVER: 'SERVER',
|
|
20
|
+
CONSUMER: 'CONSUMER',
|
|
21
|
+
PRODUCER: 'PRODUCER',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = { SpanKind }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function prepareGetHeaders (getExportRequestHeaders) {
|
|
18
|
+
return function () {
|
|
19
|
+
return getExportRequestHeaders()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { prepareGetHeaders }
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { diag } = require('@opentelemetry/api')
|
|
18
|
+
const { ExportResultCode } = require('@opentelemetry/core')
|
|
19
|
+
const { prepareSend } = require('./platform/index')
|
|
20
|
+
const zipkinTypes = require('./types')
|
|
21
|
+
const {
|
|
22
|
+
toZipkinSpan,
|
|
23
|
+
defaultStatusCodeTagName,
|
|
24
|
+
defaultStatusErrorTagName,
|
|
25
|
+
} = require('./transform')
|
|
26
|
+
const { ATTR_SERVICE_NAME } = require('@opentelemetry/semantic-conventions')
|
|
27
|
+
const { prepareGetHeaders } = require('./utils')
|
|
28
|
+
const { ServiceManager } = require('../../serviceManager')
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Zipkin Exporter
|
|
32
|
+
*/
|
|
33
|
+
class CustomZipkinExporter {
|
|
34
|
+
constructor (config = {}) {
|
|
35
|
+
this.DEFAULT_SERVICE_NAME = 'OpenTelemetry Service'
|
|
36
|
+
this._urlStr = config.url || process.env.OTEL_EXPORTER_ZIPKIN_ENDPOINT || 'http://localhost:9411/api/v2/spans'
|
|
37
|
+
this.transport = ServiceManager.get('transport')
|
|
38
|
+
this._send = prepareSend(this.transport, config.headers)
|
|
39
|
+
this._serviceName = config.serviceName
|
|
40
|
+
this._statusCodeTagName =
|
|
41
|
+
config.statusCodeTagName || defaultStatusCodeTagName
|
|
42
|
+
this._statusDescriptionTagName =
|
|
43
|
+
config.statusDescriptionTagName || defaultStatusErrorTagName
|
|
44
|
+
this._isShutdown = false
|
|
45
|
+
this._sendingPromises = []
|
|
46
|
+
if (typeof config.getExportRequestHeaders === 'function') {
|
|
47
|
+
this._getHeaders = prepareGetHeaders(config.getExportRequestHeaders)
|
|
48
|
+
} else {
|
|
49
|
+
// noop
|
|
50
|
+
this._beforeSend = function () {}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Export spans.
|
|
56
|
+
*/
|
|
57
|
+
export (spans, resultCallback) {
|
|
58
|
+
if (spans.length === 0) {
|
|
59
|
+
return resultCallback({ code: ExportResultCode.SUCCESS })
|
|
60
|
+
}
|
|
61
|
+
const serviceName = String(
|
|
62
|
+
this._serviceName ||
|
|
63
|
+
spans[0].resource.attributes[ATTR_SERVICE_NAME] ||
|
|
64
|
+
this.DEFAULT_SERVICE_NAME
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
diag.debug('Zipkin exporter export')
|
|
68
|
+
if (this._isShutdown) {
|
|
69
|
+
setTimeout(() =>
|
|
70
|
+
resultCallback({
|
|
71
|
+
code: ExportResultCode.FAILED,
|
|
72
|
+
error: new Error('Exporter has been shutdown'),
|
|
73
|
+
}), 0
|
|
74
|
+
)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
const promise = new Promise(resolve => {
|
|
78
|
+
this._sendSpans(spans, serviceName, result => {
|
|
79
|
+
resolve()
|
|
80
|
+
resultCallback(result)
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
this._sendingPromises.push(promise)
|
|
85
|
+
const popPromise = () => {
|
|
86
|
+
const index = this._sendingPromises.indexOf(promise)
|
|
87
|
+
this._sendingPromises.splice(index, 1)
|
|
88
|
+
}
|
|
89
|
+
promise.then(popPromise, popPromise)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Shutdown exporter. Noop operation in this exporter.
|
|
94
|
+
*/
|
|
95
|
+
shutdown () {
|
|
96
|
+
diag.debug('Zipkin exporter shutdown')
|
|
97
|
+
this._isShutdown = true
|
|
98
|
+
return this.forceFlush()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Exports any pending spans in exporter
|
|
103
|
+
*/
|
|
104
|
+
forceFlush () {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
Promise.all(this._sendingPromises).then(() => {
|
|
107
|
+
resolve()
|
|
108
|
+
}, reject)
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* if user defines getExportRequestHeaders in config then this will be called
|
|
114
|
+
* every time before send, otherwise it will be replaced with noop in
|
|
115
|
+
* constructor
|
|
116
|
+
* @default noop
|
|
117
|
+
*/
|
|
118
|
+
_beforeSend () {
|
|
119
|
+
if (this._getHeaders) {
|
|
120
|
+
this._send = prepareSend(this.transport, this._getHeaders())
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Transform spans and sends to Zipkin service.
|
|
126
|
+
*/
|
|
127
|
+
_sendSpans (spans, serviceName, done) {
|
|
128
|
+
const zipkinSpans = spans.map(span =>
|
|
129
|
+
toZipkinSpan(
|
|
130
|
+
span,
|
|
131
|
+
String(
|
|
132
|
+
span.attributes[ATTR_SERVICE_NAME] ||
|
|
133
|
+
span.resource.attributes[ATTR_SERVICE_NAME] ||
|
|
134
|
+
serviceName
|
|
135
|
+
),
|
|
136
|
+
this._statusCodeTagName,
|
|
137
|
+
this._statusDescriptionTagName
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
this._beforeSend()
|
|
141
|
+
return this._send(zipkinSpans, (result) => {
|
|
142
|
+
if (done) {
|
|
143
|
+
return done(result)
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = { CustomZipkinExporter }
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const Configuration = require('./configuration')
|
|
4
|
+
const Debug = require('debug')
|
|
5
|
+
const { ServiceManager } = require('./serviceManager')
|
|
6
|
+
const { createTransport } = require('./services/transport')
|
|
7
|
+
const { FeatureManager } = require('./featureManager')
|
|
8
|
+
const { ActionService } = require('./services/actions')
|
|
9
|
+
const { MetricService, MetricType, MetricMeasurements } = require('./services/metrics')
|
|
10
|
+
const Meter = require('./utils/metrics/meter')
|
|
11
|
+
const Histogram = require('./utils/metrics/histogram')
|
|
12
|
+
const Gauge = require('./utils/metrics/gauge')
|
|
13
|
+
const Counter = require('./utils/metrics/counter')
|
|
14
|
+
const { EventsFeature } = require('./features/events')
|
|
15
|
+
const { TracingFeature } = require('./features/tracing')
|
|
16
|
+
const { canUseInspector } = require('./constants')
|
|
17
|
+
const { RuntimeStatsService } = require('./services/runtimeStats')
|
|
18
|
+
|
|
19
|
+
const defaultConfig = {
|
|
20
|
+
catchExceptions: true,
|
|
21
|
+
profiling: true,
|
|
22
|
+
metrics: {
|
|
23
|
+
v8: true,
|
|
24
|
+
network: false,
|
|
25
|
+
eventLoop: true,
|
|
26
|
+
runtime: true,
|
|
27
|
+
http: true
|
|
28
|
+
},
|
|
29
|
+
standalone: false,
|
|
30
|
+
apmOptions: undefined,
|
|
31
|
+
tracing: {
|
|
32
|
+
enabled: false,
|
|
33
|
+
outbound: false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class PMX {
|
|
38
|
+
|
|
39
|
+
constructor () {
|
|
40
|
+
this.initialConfig = undefined
|
|
41
|
+
this.featureManager = new FeatureManager()
|
|
42
|
+
this.transport = null
|
|
43
|
+
this.actionService = null
|
|
44
|
+
this.metricService = null
|
|
45
|
+
this.runtimeStatsService = null
|
|
46
|
+
this.logger = Debug('axm:main')
|
|
47
|
+
this.initialized = false
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Init the APM instance, you should *always* init it before using any method
|
|
52
|
+
*/
|
|
53
|
+
init (config) {
|
|
54
|
+
const callsite = (new Error().stack || '').split('\n')[2]
|
|
55
|
+
if (callsite && callsite.length > 0) {
|
|
56
|
+
this.logger(`init from ${callsite}`)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (this.initialized === true) {
|
|
60
|
+
this.logger(`Calling init but was already the case, destroying and recreating`)
|
|
61
|
+
this.destroy()
|
|
62
|
+
}
|
|
63
|
+
if (config === undefined) {
|
|
64
|
+
config = defaultConfig
|
|
65
|
+
}
|
|
66
|
+
if (!config.standalone) {
|
|
67
|
+
const autoStandalone = process.env.PM2_SECRET_KEY && process.env.PM2_PUBLIC_KEY && process.env.PM2_APP_NAME
|
|
68
|
+
config.standalone = !!autoStandalone
|
|
69
|
+
config.apmOptions = autoStandalone ? {
|
|
70
|
+
secretKey: process.env.PM2_SECRET_KEY,
|
|
71
|
+
publicKey: process.env.PM2_PUBLIC_KEY,
|
|
72
|
+
appName: process.env.PM2_APP_NAME
|
|
73
|
+
} : undefined
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Register the transport before any other service
|
|
77
|
+
this.transport = createTransport(config.standalone === true ? 'websocket' : 'ipc', config.apmOptions)
|
|
78
|
+
ServiceManager.set('transport', this.transport)
|
|
79
|
+
|
|
80
|
+
if (canUseInspector()) {
|
|
81
|
+
const Inspector = require('./services/inspector')
|
|
82
|
+
const inspectorService = new Inspector()
|
|
83
|
+
inspectorService.init()
|
|
84
|
+
ServiceManager.set('inspector', inspectorService)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// register the action service
|
|
88
|
+
this.actionService = new ActionService()
|
|
89
|
+
this.actionService.init()
|
|
90
|
+
ServiceManager.set('actions', this.actionService)
|
|
91
|
+
|
|
92
|
+
// register the metric service
|
|
93
|
+
this.metricService = new MetricService()
|
|
94
|
+
this.metricService.init()
|
|
95
|
+
ServiceManager.set('metrics', this.metricService)
|
|
96
|
+
|
|
97
|
+
this.runtimeStatsService = new RuntimeStatsService()
|
|
98
|
+
this.runtimeStatsService.init()
|
|
99
|
+
if (this.runtimeStatsService.isEnabled()) {
|
|
100
|
+
ServiceManager.set('runtimeStats', this.runtimeStatsService)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// init features
|
|
104
|
+
this.featureManager.init(config)
|
|
105
|
+
|
|
106
|
+
Configuration.init(config)
|
|
107
|
+
// save the configuration
|
|
108
|
+
this.initialConfig = config
|
|
109
|
+
this.initialized = true
|
|
110
|
+
|
|
111
|
+
return this
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Destroy the APM instance, every method will stop working afterwards
|
|
116
|
+
*/
|
|
117
|
+
destroy () {
|
|
118
|
+
this.logger('destroy')
|
|
119
|
+
this.featureManager.destroy()
|
|
120
|
+
|
|
121
|
+
if (this.actionService !== null) {
|
|
122
|
+
this.actionService.destroy()
|
|
123
|
+
}
|
|
124
|
+
if (this.transport !== null) {
|
|
125
|
+
this.transport.destroy()
|
|
126
|
+
}
|
|
127
|
+
if (this.metricService !== null) {
|
|
128
|
+
this.metricService.destroy()
|
|
129
|
+
}
|
|
130
|
+
if (this.runtimeStatsService !== null) {
|
|
131
|
+
this.runtimeStatsService.destroy()
|
|
132
|
+
}
|
|
133
|
+
const inspectorService = ServiceManager.get('inspector')
|
|
134
|
+
if (inspectorService !== undefined) {
|
|
135
|
+
inspectorService.destroy()
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Fetch current configuration of the APM
|
|
141
|
+
*/
|
|
142
|
+
getConfig () {
|
|
143
|
+
return this.initialConfig
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Notify an error to PM2 Plus/Enterprise, note that you can attach a context to it
|
|
148
|
+
* to provide more insight about the error
|
|
149
|
+
*/
|
|
150
|
+
notifyError (error, context) {
|
|
151
|
+
const notify = this.featureManager.get('notify')
|
|
152
|
+
return notify.notifyError(error, context)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Register metrics in bulk
|
|
157
|
+
*/
|
|
158
|
+
metrics (metric) {
|
|
159
|
+
|
|
160
|
+
const res = []
|
|
161
|
+
if (metric === undefined || metric === null) {
|
|
162
|
+
console.error(`Received empty metric to create`)
|
|
163
|
+
console.trace()
|
|
164
|
+
return []
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let metrics = !Array.isArray(metric) ? [ metric ] : metric
|
|
168
|
+
for (let metric of metrics) {
|
|
169
|
+
if (typeof metric.name !== 'string') {
|
|
170
|
+
console.error(`Trying to create a metrics without a name`, metric)
|
|
171
|
+
console.trace()
|
|
172
|
+
res.push({})
|
|
173
|
+
continue
|
|
174
|
+
}
|
|
175
|
+
if (metric.type === undefined) {
|
|
176
|
+
metric.type = MetricType.gauge
|
|
177
|
+
}
|
|
178
|
+
switch (metric.type) {
|
|
179
|
+
case MetricType.counter : {
|
|
180
|
+
res.push(this.counter(metric))
|
|
181
|
+
continue
|
|
182
|
+
}
|
|
183
|
+
case MetricType.gauge : {
|
|
184
|
+
res.push(this.gauge(metric))
|
|
185
|
+
continue
|
|
186
|
+
}
|
|
187
|
+
case MetricType.histogram : {
|
|
188
|
+
res.push(this.histogram(metric))
|
|
189
|
+
continue
|
|
190
|
+
}
|
|
191
|
+
case MetricType.meter : {
|
|
192
|
+
res.push(this.meter(metric))
|
|
193
|
+
continue
|
|
194
|
+
}
|
|
195
|
+
case MetricType.metric : {
|
|
196
|
+
res.push(this.gauge(metric))
|
|
197
|
+
continue
|
|
198
|
+
}
|
|
199
|
+
default: {
|
|
200
|
+
console.error(`Invalid metric type ${metric.type} for metric ${metric.name}`)
|
|
201
|
+
console.trace()
|
|
202
|
+
res.push({})
|
|
203
|
+
continue
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return res
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Create an histogram metric
|
|
213
|
+
*/
|
|
214
|
+
histogram (config) {
|
|
215
|
+
if (typeof config === 'string') {
|
|
216
|
+
config = {
|
|
217
|
+
name: config,
|
|
218
|
+
measurement: MetricMeasurements.mean
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (this.metricService === null) {
|
|
222
|
+
return console.trace(`Tried to register a metric without initializing @pm2/io`)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return this.metricService.histogram(config)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Create a gauge metric
|
|
230
|
+
*/
|
|
231
|
+
metric (config) {
|
|
232
|
+
if (typeof config === 'string') {
|
|
233
|
+
config = {
|
|
234
|
+
name: config
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (this.metricService === null) {
|
|
238
|
+
return console.trace(`Tried to register a metric without initializing @pm2/io`)
|
|
239
|
+
}
|
|
240
|
+
return this.metricService.metric(config)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Create a gauge metric
|
|
245
|
+
*/
|
|
246
|
+
gauge (config) {
|
|
247
|
+
if (typeof config === 'string') {
|
|
248
|
+
config = {
|
|
249
|
+
name: config
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (this.metricService === null) {
|
|
253
|
+
return console.trace(`Tried to register a metric without initializing @pm2/io`)
|
|
254
|
+
}
|
|
255
|
+
return this.metricService.metric(config)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Create a counter metric
|
|
260
|
+
*/
|
|
261
|
+
counter (config) {
|
|
262
|
+
if (typeof config === 'string') {
|
|
263
|
+
config = {
|
|
264
|
+
name: config
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (this.metricService === null) {
|
|
268
|
+
return console.trace(`Tried to register a metric without initializing @pm2/io`)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return this.metricService.counter(config)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Create a meter metric
|
|
276
|
+
*/
|
|
277
|
+
meter (config) {
|
|
278
|
+
if (typeof config === 'string') {
|
|
279
|
+
config = {
|
|
280
|
+
name: config
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (this.metricService === null) {
|
|
284
|
+
return console.trace(`Tried to register a metric without initializing @pm2/io`)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return this.metricService.meter(config)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Register a custom action that will be executed when the someone called
|
|
292
|
+
* it from the API
|
|
293
|
+
*/
|
|
294
|
+
action (name, opts, fn) {
|
|
295
|
+
// backward compatiblity
|
|
296
|
+
if (typeof name === 'object') {
|
|
297
|
+
const tmp = name
|
|
298
|
+
name = tmp.name
|
|
299
|
+
opts = tmp.options
|
|
300
|
+
fn = tmp.action
|
|
301
|
+
}
|
|
302
|
+
if (this.actionService === null) {
|
|
303
|
+
return console.trace(`Tried to register a action without initializing @pm2/io`)
|
|
304
|
+
}
|
|
305
|
+
return this.actionService.registerAction(name, opts, fn)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
onExit (callback) {
|
|
309
|
+
if (typeof callback === 'function') {
|
|
310
|
+
const handler = () => callback()
|
|
311
|
+
process.on('exit', handler)
|
|
312
|
+
process.on('SIGINT', () => { handler(); process.exit() })
|
|
313
|
+
process.on('SIGTERM', () => { handler(); process.exit() })
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Emit a custom event to Keymetrics
|
|
319
|
+
* @deprecated
|
|
320
|
+
*
|
|
321
|
+
* The feature has been removed from PM2 Plus and will be removed in future release
|
|
322
|
+
*/
|
|
323
|
+
emit (name, data) {
|
|
324
|
+
const events = this.featureManager.get('events')
|
|
325
|
+
return events.emit(name, data)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Get the tracing agent to add more information about traces
|
|
330
|
+
*/
|
|
331
|
+
getTracer () {
|
|
332
|
+
const tracing = this.featureManager.get('tracing')
|
|
333
|
+
return tracing.getTracer()
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
initModule (opts, cb) {
|
|
337
|
+
if (!opts) opts = {}
|
|
338
|
+
|
|
339
|
+
if (opts.reference) {
|
|
340
|
+
opts.name = opts.reference
|
|
341
|
+
delete opts.reference
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
opts = Object.assign({
|
|
345
|
+
widget: {}
|
|
346
|
+
}, opts)
|
|
347
|
+
|
|
348
|
+
opts.widget = Object.assign({
|
|
349
|
+
type : 'generic',
|
|
350
|
+
logo : 'https://app.keymetrics.io/img/logo/keymetrics-300.png',
|
|
351
|
+
theme : ['#111111', '#1B2228', '#807C7C', '#807C7C']
|
|
352
|
+
}, opts.widget)
|
|
353
|
+
|
|
354
|
+
opts.isModule = true
|
|
355
|
+
opts = Configuration.init(opts)
|
|
356
|
+
|
|
357
|
+
return typeof cb === 'function' ? cb(null, opts) : opts
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Return a custom express middleware that will send an error to the backend
|
|
362
|
+
* with all the details of the http request
|
|
363
|
+
*/
|
|
364
|
+
expressErrorHandler () {
|
|
365
|
+
const notify = this.featureManager.get('notify')
|
|
366
|
+
return notify.expressErrorHandler()
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Return a custom koa middleware that will send an error to the backend
|
|
371
|
+
* with all the details of the http request
|
|
372
|
+
*/
|
|
373
|
+
koaErrorHandler () {
|
|
374
|
+
const notify = this.featureManager.get('notify')
|
|
375
|
+
return notify.koaErrorHandler()
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
module.exports = PMX
|
|
380
|
+
module.exports.defaultConfig = defaultConfig
|