Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always disable library on unsupported Node.js versions #225

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .yarn/versions/7b6965df.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
releases:
"@solarwinds-apm/sdk": minor
solarwinds-apm: patch
3 changes: 3 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

import { metrics, oboe } from "@solarwinds-apm/bindings"

import { version } from "../package.json"
import { CompoundSpanProcessor } from "./compound-processor"
import { type SwConfiguration } from "./config"
import { setTransactionName, waitUntilReady } from "./context"
Expand All @@ -37,6 +38,8 @@ import { SwTraceContextOptionsPropagator } from "./trace-context-options-propaga
import { SwTraceOptionsResponsePropagator } from "./trace-options-response-propagator"
import { SwTransactionNameProcessor } from "./transaction-name-processor"

export const VERSION = version

export const OBOE_ERROR: Error | false = oboe instanceof Error ? oboe : false
export const METRICS_ERROR: Error | false =
metrics instanceof Error ? metrics : false
Expand Down
18 changes: 13 additions & 5 deletions packages/solarwinds-apm/src/index.cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ limitations under the License.
*/

import { init } from "./init.js"
import { setter } from "./symbols.js"
import { versionCheck } from "./version.js"

try {
init().catch((err) => {
// init only once
const setInit = setter("init")
if (setInit && versionCheck()) {
setInit()

try {
init().catch((err) => {
console.warn(err)
})
} catch (err) {
console.warn(err)
})
} catch (err) {
console.warn(err)
}
}

export * from "./api.js"
37 changes: 22 additions & 15 deletions packages/solarwinds-apm/src/index.es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,28 @@ import semver from "semver"

import { init } from "./init.js"
import { setter } from "./symbols.js"

// register only once
const setRegister = setter("register")
if (
setRegister &&
semver.satisfies(process.versions.node, "^18.19.0 || >=20.6.0")
) {
setRegister()
module.register("./hooks.es.js", import.meta.url)
}

try {
await init()
} catch (err) {
console.warn(err)
import { versionCheck } from "./version.js"

// init only once
const setInit = setter("init")
if (setInit && versionCheck()) {
setInit()

// register only once
const setRegister = setter("register")
if (
setRegister &&
semver.satisfies(process.versions.node, "^18.19.0 || >=20.6.0")
) {
setRegister()
module.register("./hooks.es.js", import.meta.url)
}

try {
await init()
} catch (err) {
console.warn(err)
}
}

export * from "./api.js"
20 changes: 0 additions & 20 deletions packages/solarwinds-apm/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,15 @@ import {
} from "@solarwinds-apm/instrumentations"
import { IS_SERVERLESS } from "@solarwinds-apm/module"
import * as sdk from "@solarwinds-apm/sdk"
import * as semver from "semver"

import { version } from "../package.json"
import {
type ExtendedSwConfiguration,
printError,
readConfig,
} from "./config.js"
import { setter } from "./symbols.js"

export async function init() {
// init only once
const setInit = setter("init")
if (!setInit) return
setInit()

const nodeVersion = semver.parse(process.versions.node)!.major
if (nodeVersion < 16) {
console.warn(
"The current Node.js version is not supported, the instrumentation library may not work as expected.",
)
}
if (nodeVersion < 18) {
console.warn(
"The current Node.js version has reached End Of Life at the time the library was published, which means it no longer receives security updates.",
"SolarWinds STRONGLY RECOMMENDS upgrading to a supported Node.js version and staying up to date with its support policy at https://nodejs.org/about/previous-releases",
)
}

let config: ExtendedSwConfiguration
try {
const configOrPromise = readConfig()
Expand Down
57 changes: 57 additions & 0 deletions packages/solarwinds-apm/src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
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.
*/

import { VERSION as OTEL_VERSION } from "@opentelemetry/core"
import { VERSION as SDK_VERSION } from "@solarwinds-apm/sdk"
import * as semver from "semver"

import { version as VERSION } from "../package.json"

const NODE_VERSION = process.versions.node

const MINIMUM_SUPPORTED = "16.13.0"
const MINIMUM_LTS = "18.0.0"

export function versionCheck(): boolean {
console.log(
[
`Node.js ${NODE_VERSION}`,
`solarwinds-apm ${VERSION}`,
`@solarwinds-apm/sdk ${SDK_VERSION}`,
`@opentelemetry/core ${OTEL_VERSION}`,
].join("\n"),
)

try {
let supported = true
if (semver.lt(NODE_VERSION, MINIMUM_SUPPORTED)) {
console.warn(
"The current Node.js version is not supported and the instrumentation library will be disabled.",
`The minimum supported version is ${MINIMUM_SUPPORTED}`,
)
supported = false
}
if (semver.lt(NODE_VERSION, MINIMUM_LTS)) {
console.warn(
"The current Node.js version has reached End Of Life at the time the library was published, which means it no longer receives security updates.",
"SolarWinds STRONGLY RECOMMENDS upgrading to a supported Node.js version and staying up to date with its support policy at https://nodejs.org/about/previous-releases",
)
}
return supported
} catch {
return false
}
}
Loading