Skip to content

Commit

Permalink
Merge pull request #14 from kronostechnologies/add_sentry_cron
Browse files Browse the repository at this point in the history
Add sentry SDK and configure sentry cron
  • Loading branch information
mcantinqc authored Feb 16, 2024
2 parents 794ae3a + eb85c2d commit 579d863
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ LOG_CLEAN=true
MYSQL_HOST=
MYSQL_USER=
MYSQL_PWD=
SENTRY_DSN=
SENTRY_MONITOR_SLUG=mysql2s3
ENVIRONMENT=staging
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ These are the permissions needed for this container to successfully backup your
| MYSQL_HOST | | MySQL hostname |
| MYSQL_USER | | MySQL username |
| MYSQL_PWD | | MySQL password |
| ENVIRONMENT | | Environment name (ex. staging, ca-accp, ca-prod...) |
| SENTRY_DSN | | Sentry DSN, connection informations. |
| SENTRY_MONITOR_SLUG | | Name of Sentry cron project, required if SENTRY_DSN is set |
41 changes: 41 additions & 0 deletions mysql2s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const lzma = require('lzma-native');
const zlib = require('zlib');
const stream = require('stream');
const mysql = require('mysql');
const sentry = require("@sentry/node");

const winston = require('winston');

Expand All @@ -29,6 +30,7 @@ let bytes = 0;

const config = {
concurrency: process.env.CONCURRENCY,
environment: process.env.ENVIRONMENT || '',
backup: {
mysql: {
host: process.env.MYSQL_HOST,
Expand All @@ -46,26 +48,65 @@ const config = {
type: process.env.COMPRESSION_TYPE,
level: process.env.COMPRESSION_LEVEL,
threads: process.env.COMPRESSION_THREADS,
},
sentry: {
dsn: process.env.SENTRY_DSN,
monitor_slug: process.env.SENTRY_MONITOR_SLUG,
}
}
};

if (config.sentry.dsn) {
if (!config.sentry.monitor_slug) {
throw new Error("SENTRY_MONITOR_SLUG is required when SENTRY_DSN is set");
}
sentry.init({
dsn: config.sentry.dsn,
environment: config.environment,
tracesSampleRate: 0.0,
});
}

const start = async () => {
let checkInId;
try {
logger.info('Starting backup');
logger.debug('### ENVIRONMENT ###');
logger.debug(_cleanSensitiveEnvInformation(process.env));
logger.debug('#####################');

if (config.sentry.dsn) {
checkInId = sentry.captureCheckIn({
monitorSlug: config.sentry.monitor_slug,
status: "in_progress",
});
}

const databases = await _getDatabases(config.backup.mysql);
await _launchConcurrentBackups(databases, config);
logger.info('Backup successful');

if (config.sentry.dsn) {
sentry.captureCheckIn({
checkInId,
monitorSlug: config.sentry.monitor_slug,
status: "ok",
});
}
}
catch(e) {
process.exitCode = 1;
logger.error(`Backup failed: ${e}`)
if (e.stack) {
logger.debug(e.stack);
}
if (config.sentry.dsn && checkInId) {
sentry.captureCheckIn({
checkInId,
monitorSlug: config.sentry.monitor_slug,
status: "error",
});
}
}
};

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"homepage": "https://github.com/kronostechnologies/docker-mysql2s3#readme",
"dependencies": {
"@sentry/node": "^7.101.1",
"aws-sdk": "^2.88.0",
"dateformat": "^4.5.1",
"dotenv": "^8.2.0",
Expand Down
39 changes: 39 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,45 @@
enabled "2.0.x"
kuler "^2.0.0"

"@sentry-internal/[email protected]":
version "7.101.1"
resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.101.1.tgz#9504e29c3c2c3ef5f652777e487b596cf8f78e1a"
integrity sha512-ihjWG8x4x0ozx6t+EHoXLKbsPrgzYLCpeBLWyS+M6n3hn6cmHM76c8nZw3ldhUQi5UYL3LFC/JZ50b4oSxtlrg==
dependencies:
"@sentry/core" "7.101.1"
"@sentry/types" "7.101.1"
"@sentry/utils" "7.101.1"

"@sentry/[email protected]":
version "7.101.1"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.101.1.tgz#929841b7734129803b6dcd4d16bf0d3f53af4657"
integrity sha512-XSmXXeYT1d4O14eDF3OXPJFUgaN2qYEeIGUztqPX9nBs9/ij8y/kZOayFqlIMnfGvjOUM+63sy/2xDBOpFn6ug==
dependencies:
"@sentry/types" "7.101.1"
"@sentry/utils" "7.101.1"

"@sentry/node@^7.101.1":
version "7.101.1"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.101.1.tgz#d652503002be921be5ca042a3ef7457d309cdfa9"
integrity sha512-iXSxUT6Zbt/KUY0+fRcW5II6Tgp2zdTfhBW+fQuDt/UUZt7Ypvb+6n4U2oom3LJfttmD7mdjQuT4+vsNImDjTQ==
dependencies:
"@sentry-internal/tracing" "7.101.1"
"@sentry/core" "7.101.1"
"@sentry/types" "7.101.1"
"@sentry/utils" "7.101.1"

"@sentry/[email protected]":
version "7.101.1"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.101.1.tgz#7f936022d9b373f85ebf357634bf03a9e433a3d0"
integrity sha512-bwtkQvrCZ6JGc7vqX7TEAKBgkbQFORt84FFS3JQQb8G3efTt9fZd2ReY4buteKQdlALl8h1QWVngTLmI+kyUuw==

"@sentry/[email protected]":
version "7.101.1"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.101.1.tgz#97399b1e6a63a15e8f9fec5112ac4834239f1db6"
integrity sha512-Nrg0nrEI3nrOCd9SLJ/WGzxS5KMQE4cryLOvrDcHJRWpsSyGBF1hLLerk84Nsw/0myMsn7zTYU+xoq7idNsX5A==
dependencies:
"@sentry/types" "7.101.1"

abbrev@1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
Expand Down

0 comments on commit 579d863

Please sign in to comment.