chore: Centralize env parsing, validation, defaults, and deprecation notices (#3487)
* chore: Centralize env parsing, defaults, deprecation * wip * test * test * tsc * docs, more validation * fix: Allow empty REDIS_URL (defaults to localhost) * test * fix: SLACK_MESSAGE_ACTIONS not bool * fix: Add SMTP port validation
This commit is contained in:
@@ -6,7 +6,8 @@ import Metrics from "@server/logging/metrics";
|
||||
import Sentry from "@server/logging/sentry";
|
||||
import * as Tracing from "./tracing";
|
||||
|
||||
const isProduction = env.NODE_ENV === "production";
|
||||
const isProduction = env.ENVIRONMENT === "production";
|
||||
|
||||
type LogCategory =
|
||||
| "lifecycle"
|
||||
| "hocuspocus"
|
||||
@@ -72,7 +73,7 @@ class Logger {
|
||||
warn(message: string, extra?: Extra) {
|
||||
Metrics.increment("logger.warning");
|
||||
|
||||
if (process.env.SENTRY_DSN) {
|
||||
if (env.SENTRY_DSN) {
|
||||
Sentry.withScope(function (scope) {
|
||||
scope.setLevel(Sentry.Severity.Warning);
|
||||
|
||||
@@ -104,7 +105,7 @@ class Logger {
|
||||
Metrics.increment("logger.error");
|
||||
Tracing.setError(error);
|
||||
|
||||
if (process.env.SENTRY_DSN) {
|
||||
if (env.SENTRY_DSN) {
|
||||
Sentry.withScope(function (scope) {
|
||||
scope.setLevel(Sentry.Severity.Error);
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import ddMetrics from "datadog-metrics";
|
||||
import env from "@server/env";
|
||||
|
||||
class Metrics {
|
||||
enabled = !!process.env.DD_API_KEY;
|
||||
enabled = !!env.DD_API_KEY;
|
||||
|
||||
constructor() {
|
||||
if (!this.enabled) {
|
||||
@@ -9,9 +10,9 @@ class Metrics {
|
||||
}
|
||||
|
||||
ddMetrics.init({
|
||||
apiKey: process.env.DD_API_KEY,
|
||||
apiKey: env.DD_API_KEY,
|
||||
prefix: "outline.",
|
||||
defaultTags: [`env:${process.env.DD_ENV || process.env.NODE_ENV}`],
|
||||
defaultTags: [`env:${process.env.DD_ENV ?? env.ENVIRONMENT}`],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export function requestErrorHandler(error: any, ctx: ContextWithState) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.SENTRY_DSN) {
|
||||
if (env.SENTRY_DSN) {
|
||||
Sentry.withScope(function (scope) {
|
||||
const requestId = ctx.headers["x-request-id"];
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { init, tracer, addTags, markAsError } from "@theo.gravity/datadog-apm";
|
||||
import env from "@server/env";
|
||||
|
||||
export * as APM from "@theo.gravity/datadog-apm";
|
||||
|
||||
// If the DataDog agent is installed and the DD_API_KEY environment variable is
|
||||
// in the environment then we can safely attempt to start the DD tracer
|
||||
if (process.env.DD_API_KEY) {
|
||||
if (env.DD_API_KEY) {
|
||||
init(
|
||||
{
|
||||
// SOURCE_COMMIT is used by Docker Hub
|
||||
@@ -13,7 +14,7 @@ if (process.env.DD_API_KEY) {
|
||||
service: process.env.DD_SERVICE || "outline",
|
||||
},
|
||||
{
|
||||
useMock: process.env.NODE_ENV === "test",
|
||||
useMock: env.ENVIRONMENT === "test",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user