-
Notifications
You must be signed in to change notification settings - Fork 1
/
diagnostic.js
163 lines (140 loc) · 4.67 KB
/
diagnostic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
Copyright 2023-2024 SolarWinds Worldwide, LLC.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const path = require("path")
const fs = require("fs")
function packageJson(id) {
try {
const entry = require.resolve(id)
let directory = path.dirname(entry)
for (;;) {
try {
const file = path.join(directory, "package.json")
const contents = fs.readFileSync(file, { encoding: "utf-8" })
const json = JSON.parse(contents)
if ("name" in json && "version" in json) {
return json
}
} catch {
// try again
}
directory = path.dirname(directory)
}
} catch {
// no matching package
}
return null
}
function print(...vals) {
for (const val of vals) {
console.dir(val, {
depth: Infinity,
maxArrayLength: Infinity,
maxStringLength: Infinity,
})
}
}
const report = process.report.getReport()
const packages = [
"solarwinds-apm",
"@solarwinds-apm/sdk",
"@solarwinds-apm/bindings",
"solarwinds-apm-bindings",
"@opentelemetry/api",
"@opentelemetry/core",
"appoptics-apm",
"@appoptics/apm-bindings",
"appoptics-bindings",
].reduce((ps, p) => ({ ...ps, [p]: packageJson(p) }), {})
print(report, packages)
const installed = packages["solarwinds-apm"] != null
if (!installed) {
console.warn(
"The 'solarwinds-apm' package could not be found.",
"Is it installed and are you running this script from your application directory ?",
)
}
const appopticsInstalled = packages["appoptics-apm"] != null
if (appopticsInstalled) {
console.warn(
"The 'appoptics-apm' package was detected.",
"Make sure to uninstall it properly as it is not compatible with the 'solarwinds-apm' package.",
)
}
const platform = process.platform
if (platform !== "linux") {
console.warn(
`The current platform (${platform}) is not supported.`,
"'solarwinds-apm' currently only supports Linux.",
)
}
const arch = process.arch
if (arch !== "x64" && arch !== "arm64") {
console.warn(
`The current architecture (${arch}) is not supported.`,
"'solarwinds-apm' currently only supports x64 and arm64.",
)
}
const majorNodeVersion = Number.parseInt(process.versions.node.split(".")[0])
if (majorNodeVersion <= 14) {
console.warn(
`The current Node.js version (${process.version}) is no longer maintained and may be vulnerable.`,
"'solarwinds-apm' may not work properly and SolarWinds STRONGLY RECOMMENDS to upgrade to a maintained Node.js version.",
)
}
if (
process.versions.ares &&
process.env.GRPC_DNS_RESOLVER &&
process.env.GRPC_DNS_RESOLVER.toLowerCase() === "ares"
) {
console.warn(
`The current Node.js version (${process.version}) is incompatible with the c-ares gRPC DNS resolver which this application explicitly specifies.`,
"This can be fixed by unsetting the 'GRPC_DNS_RESOLVER' environment variable.",
)
}
if (installed) {
const version = packages["solarwinds-apm"].version
const majorVersion = Number.parseInt(version.split(".")[0])
const otelBased = majorVersion >= 14
if (otelBased) {
if (!["debug", "trace"].includes(process.env.SW_APM_LOG_LEVEL)) {
console.warn(
"The 'SW_APM_LOG_LEVEL' environment variable can be set to 'debug' to help with debugging issues.",
)
}
if (packages["@opentelemetry/api"] == null) {
console.warn(
"The '@opentelemetry/api' package could not be found.",
"Versions 14 and up of 'solarwinds-apm' require this package to be installed alongside them.",
)
}
} else {
if (
!process.env.SW_APM_LOG_SETTINGS ||
process.env.SW_APM_LOG_SETTINGS.indexOf("debug") === -1
) {
console.warn(
"The 'SW_APM_LOG_SETTINGS' environment variable can be set to 'error,warn,info,debug' to help with debugging issues.",
)
}
if (packages["@opentelemetry/api"] != null) {
console.warn(
"The '@opentelemetry/api' package was detected.",
`Only versions 14 and up of 'solarwinds-apm' support OpenTelemetry, but the currently installed version is ${version}.`,
)
}
}
}
console.warn(
"THE GENERATED REPORT CONTAINS A DUMP OF ALL ENVIRONMENT VARIABLES.",
"MAKE SURE TO REMOVE ANY SENSITIVE INFORMATION BEFORE TRANSMITTING IT.",
)