@ailo/monitoring

Ailo TypeScript starter

Usage no npm install needed!

<script type="module">
  import ailoMonitoring from 'https://cdn.skypack.dev/@ailo/monitoring';
</script>

README

@ailo/monitoring

Utilities for setting up logging and tracing for Ailo node.js services.

Usage

yarn add @ailo/monitoring @sentry/node @sentry/apm
// src/common/config.ts
const ENV =
  process.env.ENV ||
  (process.env.NODE_ENV === "test" ? "test" : "local");
const SENTRY_ENV = process.env.SENTRY_ENV || ENV;

function parseIntVar(s: string | undefined): number | undefined {
  if (s || s === "0") {
    return parseInt(s, 10);
  }
  return undefined;
}

function parseBoolean(value: string | undefined): boolean | undefined {
  if (value === undefined || value === "") {
    return undefined;
  }
  return Boolean(value);
}

export const config = {
  ...,
  sentry: {
    enabled:
      parseBoolean(process.env.SENTRY_ENABLE) ??
      !["local", "test"].includes(ENV),
    environment: SENTRY_ENV,
    dsn:
      process.env.SENTRY_DSN || "https://abcd.ingest.sentry.io/1234",
    tracesSampleRate:
      parseIntVar(process.env.SENTRY_TRACES_SAMPLE_RATE) ??
      (ENV === "local" ? 1 : 0.01),
  },
};

// src/common/monitoring.ts
import { SentryMonitoring } from "@ailo/monitoring";
import { config } from "./config";

export const monitoring = new SentryMonitoring(config.sentry);

// src/app/app.ts
import "local/common/monitoring";

Development

yarn
yarn start

Testing

yarn lint # prettier and eslint
yarn test # unit tests
yarn test:watch # unit tests in watch mode

Releasing

Note: Releasing is done manually (CI isn't configured yet). Linters, tests, build and so on are run during each git push / yarn release.

yarn release # will automatically ask you about version bump, run tests and build, and push new version to git & npm