mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 07:35:09 +00:00
feat(aws-cloudwatch): added support for aws cloudwatch transport in pino
This commit is contained in:
@@ -89,6 +89,21 @@ export const getClientSecretGitLabLogin = async () =>
|
||||
export const getUrlGitLabLogin = async () =>
|
||||
(await client.getSecret("URL_GITLAB_LOGIN")).secretValue || GITLAB_URL;
|
||||
|
||||
export const getAwsCloudWatchLog = async () => {
|
||||
const logGroupName =
|
||||
(await client.getSecret("AWS_CLOUDWATCH_LOG_GROUP_NAME")).secretValue || "infisical-log-stream";
|
||||
const region = (await client.getSecret("AWS_CLOUDWATCH_LOG_REGION")).secretValue;
|
||||
const accessKeyId = (await client.getSecret("AWS_CLOUDWATCH_LOG_ACCESS_KEY_ID")).secretValue;
|
||||
const accessKeySecret = (await client.getSecret("AWS_CLOUDWATCH_LOG_ACCESS_KEY_SECRET"))
|
||||
.secretValue;
|
||||
const interval = parseInt(
|
||||
(await client.getSecret("AWS_CLOUDWATCH_LOG_INTERVAL")).secretValue || 1000,
|
||||
10
|
||||
);
|
||||
if (!region || !accessKeyId || !accessKeySecret) return;
|
||||
return { logGroupName, region, accessKeySecret, accessKeyId, interval };
|
||||
};
|
||||
|
||||
export const getPostHogHost = async () =>
|
||||
(await client.getSecret("POSTHOG_HOST")).secretValue || "https://app.posthog.com";
|
||||
export const getPostHogProjectApiKey = async () =>
|
||||
|
||||
@@ -5,7 +5,7 @@ import express from "express";
|
||||
require("express-async-errors");
|
||||
import helmet from "helmet";
|
||||
import cors from "cors";
|
||||
import { logger } from "./utils/logging";
|
||||
import { initLogger, logger } from "./utils/logging";
|
||||
import httpLogger from "pino-http";
|
||||
import { DatabaseService } from "./services";
|
||||
import { EELicenseService, GithubSecretScanningService } from "./ee/services";
|
||||
@@ -101,6 +101,7 @@ import { serverConfigInit } from "./config/serverConfig";
|
||||
let handler: null | any = null;
|
||||
|
||||
const main = async () => {
|
||||
await initLogger();
|
||||
const port = await getPort();
|
||||
|
||||
// initializing the database connection
|
||||
|
||||
@@ -1 +1 @@
|
||||
export { logger } from "./logger";
|
||||
export { logger, initLogger } from "./logger";
|
||||
|
||||
@@ -1,15 +1,56 @@
|
||||
import pino from "pino";
|
||||
import pino, { Logger } from "pino";
|
||||
import { getAwsCloudWatchLog, getNodeEnv } from "../../config";
|
||||
|
||||
export const logger = pino({
|
||||
level: process.env.PINO_LOG_LEVEL || "trace",
|
||||
timestamp: pino.stdTimeFunctions.isoTime,
|
||||
formatters: {
|
||||
bindings: (bindings) => {
|
||||
return {
|
||||
export let logger: Logger;
|
||||
|
||||
export const initLogger = async () => {
|
||||
const awsCloudWatchLogCfg = await getAwsCloudWatchLog();
|
||||
const nodeEnv = await getNodeEnv();
|
||||
const isProduction = nodeEnv === "production";
|
||||
const targets: pino.TransportMultiOptions["targets"][number][] = [
|
||||
isProduction
|
||||
? { level: "trace", target: "pino/file", options: {} }
|
||||
: {
|
||||
level: "info",
|
||||
target: "pino-pretty", // must be installed separately
|
||||
options: {
|
||||
colorize: true
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
if (awsCloudWatchLogCfg) {
|
||||
targets.push({
|
||||
target: "@serdnam/pino-cloudwatch-transport",
|
||||
level: "info",
|
||||
options: {
|
||||
logGroupName: awsCloudWatchLogCfg.logGroupName,
|
||||
logStreamName: awsCloudWatchLogCfg.logGroupName,
|
||||
awsRegion: awsCloudWatchLogCfg.region,
|
||||
awsAccessKeyId: awsCloudWatchLogCfg.accessKeyId,
|
||||
awsSecretAccessKey: awsCloudWatchLogCfg.accessKeySecret,
|
||||
interval: awsCloudWatchLogCfg.interval
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const transport = pino.transport({
|
||||
targets
|
||||
});
|
||||
|
||||
logger = pino(
|
||||
{
|
||||
level: process.env.PINO_LOG_LEVEL || "trace",
|
||||
formatters: {
|
||||
bindings: (bindings) => {
|
||||
return {
|
||||
pid: bindings.pid,
|
||||
hostname: bindings.hostname
|
||||
// node_version: process.version
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
transport
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user