Skip to content

Commit

Permalink
the big cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-theriault-swi committed Oct 18, 2024
1 parent 592eefb commit d3f7aca
Show file tree
Hide file tree
Showing 144 changed files with 232 additions and 6,160 deletions.
6 changes: 0 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ updates:
patterns:
- "turbo"
- "typescript"
- "tslib"
- "zig-build"
- "rollup"
- "@rollup/*"
- "rollup-*"
update-types:
- minor
- patch
Expand All @@ -51,8 +47,6 @@ updates:
- "typescript-eslint"
- "@eslint/*"
- "eslint-*"
- "@typescript-eslint/*"
- "globals"
update-types:
- minor
- patch
Expand Down
8 changes: 2 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ This project aims to support all currently maintained and future LTS Node versio

When a new future LTS is released (any even-numbered Node versions) the project should be updated to support it so that by the time it becomes an LTS it has already been well-tested. In most cases this doesn't require any change apart from updating the Docker images. It is however possible, although unlikely, that a future release may break native code or a dependency, which should be kept in mind.

When a current LTS goes out of maintenance, support for it should be removed. This project should not support its dependents in using unsupported, potentially insecure Node versions. The version of `@types/node` depended on by all packages should be updated to the next LTS version, for instance going from `^14.0.0` to `^16.0.0`. The `target` in the [base tsconfig](./tsconfig.base.json) should be updated to the highest standard supported by the next LTS version (check [`node.green`](https://node.green) for this) and the same should be done for the `languageOptions` in the ESLint configuration package. The Docker images for the old LTS should be removed, and the distro versions used by the Docker images for the next LTS should be changed to the lowest supported versions if necessary, for instance removing `14-alpine3.12` and moving from `16-alpine` to `16-alpine:3.12`. All `package.json` `engines` fields should also be updated to the next LTS version.
When a version has been EOL for over a year, support for it should be removed. This project should not encourage customers to use unsupported, potentially insecure Node versions. The version of `@types/node` depended on by all packages should be updated to the next LTS version, for instance going from `^14.0.0` to `^16.0.0`. The `target` in the [base tsconfig](./tsconfig.base.json) should be updated to the highest standard supported by the next LTS version (check [`node.green`](https://node.green) for this). The Docker images for the old LTS should be removed, and the distro versions used by the Docker images for the next LTS should be changed to the lowest supported versions if necessary, for instance removing `14-alpine3.12` and moving from `16-alpine` to `16-alpine:3.12`. All `package.json` `engines` fields should also be updated to the next LTS version.

## Upgrading dependencies

Expand Down Expand Up @@ -99,11 +99,7 @@ This is especially important given this repo uses Turborepo to run commands in a

## ES Modules vs CommonJS

We explicitly aim to support ESM

Packages should optimally target both ESM and CJS unless they have a good reason not to, in which case they should target CJS only for compatibility. At the moment the two CJS-only packages are the SDK because it's internal and has a lot of stateful components, and the bindings because they are internal and `.node` files can't be imported from ESM.

Dual targeting is made simple by the project's [Rollup configuration](./packages/rollup-config/), which should work without being extended pretty much all the time. Files ending in `.es.{ts, js}` will only be included for ESM `.cjs.{ts, js}` only for CJS. We don't use `.m{ts, js}` and `.c{ts, js}` because they have poor TypeScript support (and I, the original author, think they are Ugly and Bad). Projects should always specify `"type": "module"` when dual targeting (or an explicit `"commonjs"`) in their `package.json`.
We target ESM wherever possible, but all public facing API functions must be callable from either ESM or CommonJS.

Internal code (like scripts and examples) should attempt to use ESM as much as possible unless they are meant to demonstrate usage of the library from CJS.

Expand Down
6 changes: 6 additions & 0 deletions examples/express-mysql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const process = require("node:process")

const express = require("express")
const mysql = require("mysql2")
const apm = require("solarwinds-apm")
const winston = require("winston")

const logger = winston.createLogger({
Expand Down Expand Up @@ -85,6 +86,11 @@ app.post("/", (req, res) => {
)
})

app.get("/error", () => {
apm.setTransactionName("woops")
throw new Error("woops")
})

app.get("/:id", (req, res) => {
const id = Number.parseInt(req.params.id)
if (!id || id < 0) {
Expand Down
6 changes: 6 additions & 0 deletions examples/fastify-postgres/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { env } from "node:process"

import pg from "@fastify/postgres"
import fastify from "fastify"
import { setTransactionName } from "solarwinds-apm"

const schema = `
CREATE TABLE IF NOT EXISTS items (
Expand Down Expand Up @@ -61,6 +62,11 @@ app.post(
},
)

app.get("/error", () => {
setTransactionName("woops")
throw new Error("woops")
})

app.get(
"/:id",
{
Expand Down
1 change: 1 addition & 0 deletions examples/fastify-postgres/solarwinds.apm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ limitations under the License.
export default {
insertTraceContextIntoQueries: true,
insertTraceContextIntoLogs: true,
exportLogsEnabled: true,
}
2 changes: 1 addition & 1 deletion examples/next-prisma/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
2 changes: 1 addition & 1 deletion examples/next-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"solarwinds-apm": "workspace:^"
},
"devDependencies": {
"@types/node": "^16.13.0",
"@types/node": "^18.19.0",
"@types/react": "^18.2.25",
"eslint": "^8.57.0",
"eslint-config-next": "^14.0.3",
Expand Down
1 change: 0 additions & 1 deletion packages/bindings/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
npm/*/oboe.node
npm/*/metrics.node
npm/*/liboboe.so

.cache/
Expand Down
82 changes: 18 additions & 64 deletions packages/bindings/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ const targets = [
cpu: "generic",
glibc: "2.27",
},
{
name: "linux-arm64-gnu-serverless",
oboe: "liboboe-1.0-lambda-aarch64.so",
target: "aarch64-linux-gnu",
cpu: "generic",
glibc: "2.27",
},
{
name: "linux-arm64-musl",
oboe: "liboboe-1.0-alpine-aarch64.so",
Expand All @@ -45,55 +38,38 @@ const targets = [
cpu: "x86_64_v3",
glibc: "2.27",
},
{
name: "linux-x64-gnu-serverless",
oboe: "liboboe-1.0-lambda-x86_64.so",
target: "x86_64-linux-gnu",
cpu: "x86_64_v3",
glibc: "2.27",
},
{
name: "linux-x64-musl",
oboe: "liboboe-1.0-alpine-x86_64.so",
target: "x86_64-linux-musl",
cpu: "x86_64_v3",
},
]
const configs = targets.flatMap(({ name, oboe, target, cpu, glibc }) => {
fs.copyFileSync(`oboe/${oboe}`, `npm/${name}/liboboe.so`)

// only build serverless api for serverless
const oboeSources = name.includes("serverless")
? [
"src/oboe/oboe.serverless.cc",
"src/oboe/oboe_api.cc",
"oboe/include/oboe_api.cpp",
]
: [
"src/oboe/oboe.cc",
"src/oboe/config.cc",
"src/oboe/context.cc",
"src/oboe/custom_metrics.cc",
"src/oboe/event.cc",
"src/oboe/metadata.cc",
"src/oboe/metric_tags.cc",
"src/oboe/reporter.cc",
"src/oboe/span.cc",
"oboe/include/oboe_api.cpp",
]
// optimize for size for serverless
const oboeMode = name.includes("serverless") ? "small" : "fast"
const configs = targets.map(({ name, oboe, target, cpu, glibc }) => {
fs.copyFileSync(`oboe/${oboe}`, `npm/${name}/liboboe.so`)

const oboeConfig = {
const config = {
target,
cpu,
glibc,
output: `npm/${name}/oboe.node`,
type: "shared",
mode: oboeMode,
mode: "fast",

sources: oboeSources,
napiVersion: 8,
sources: [
"src/oboe/oboe.cc",
"src/oboe/config.cc",
"src/oboe/context.cc",
"src/oboe/custom_metrics.cc",
"src/oboe/event.cc",
"src/oboe/metadata.cc",
"src/oboe/metric_tags.cc",
"src/oboe/reporter.cc",
"src/oboe/span.cc",
"oboe/include/oboe_api.cpp",
],
napiVersion: 9,
std: "c++17",
exceptions: true,

Expand All @@ -104,29 +80,7 @@ const configs = targets.flatMap(({ name, oboe, target, cpu, glibc }) => {

rpath: "$ORIGIN",
}

const metricsConfig = {
target,
cpu,
glibc,
output: `npm/${name}/metrics.node`,
type: "shared",

sources: ["src/metrics/metrics.cc"],
napiVersion: 8,
std: "c++17",
exceptions: true,

cflags: ["-Wall", "-Wextra", "-Werror"],
}

// don't build metrics for serverless
return name.includes("serverless")
? [[`${name}:oboe`, oboeConfig]]
: [
[`${name}:oboe`, oboeConfig],
[`${name}:metrics`, metricsConfig],
]
return [name, config]
})

build(Object.fromEntries(configs), __dirname, true)
Expand Down
2 changes: 1 addition & 1 deletion packages/bindings/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ limitations under the License.

const base = require("@solarwinds-apm/eslint-config")

module.exports = [...base({ allowDefaultProject: [] })]
module.exports = base({ allowDefaultProject: [] })
19 changes: 1 addition & 18 deletions packages/bindings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

const { IS_SERVERLESS } = require("@solarwinds-apm/module")

function triple() {
const platform = process.platform
const arch = process.arch
Expand All @@ -29,25 +27,10 @@ function triple() {
return `${platform}-${arch}`
}
}

function serverless() {
if (IS_SERVERLESS) {
return "-serverless"
} else {
return ""
}
}

const t = `${triple()}${serverless()}`
const t = triple()

try {
module.exports.oboe = require(`@solarwinds-apm/bindings-${t}/oboe.node`)
} catch (cause) {
module.exports.oboe = new Error(`unsupported platform ${t}`, { cause })
}

try {
module.exports.metrics = require(`@solarwinds-apm/bindings-${t}/metrics.node`)
} catch (cause) {
module.exports.metrics = new Error(`unsupported platform ${t}`, { cause })
}
33 changes: 0 additions & 33 deletions packages/bindings/npm/linux-arm64-gnu-serverless/package.json

This file was deleted.

3 changes: 1 addition & 2 deletions packages/bindings/npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
],
"files": [
"oboe.node",
"metrics.node",
"liboboe.so"
],
"publishConfig": {
"access": "public",
"provenance": true
},
"engines": {
"node": ">=16.13.0"
"node": "^18.19.0 || ^20.8.0 || >=22.0.0"
}
}
3 changes: 1 addition & 2 deletions packages/bindings/npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
],
"files": [
"oboe.node",
"metrics.node",
"liboboe.so"
],
"publishConfig": {
"access": "public",
"provenance": true
},
"engines": {
"node": ">=16.13.0"
"node": "^18.19.0 || ^20.8.0 || >=22.0.0"
}
}
33 changes: 0 additions & 33 deletions packages/bindings/npm/linux-x64-gnu-serverless/package.json

This file was deleted.

3 changes: 1 addition & 2 deletions packages/bindings/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
],
"files": [
"oboe.node",
"metrics.node",
"liboboe.so"
],
"publishConfig": {
"access": "public",
"provenance": true
},
"engines": {
"node": ">=16.13.0"
"node": "^18.19.0 || ^20.8.0 || >=22.0.0"
}
}
Loading

0 comments on commit d3f7aca

Please sign in to comment.