Skip to content

Commit

Permalink
Allow to specify sentry envionment and release. (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
imperiuse committed Nov 27, 2023
1 parent 65d24fd commit fc3d430
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ time="2019-01-12T19:35:00+09:00" level=info msg="job succeeded" iteration=0 job.

### Sentry

Report errors to Sentry by passing a Sentry DSN:
Supercronic offers integration with Sentry for real-time error tracking and reporting. This feature helps in identifying, triaging, and fixing crashes in your cron jobs.

#### Enabling Sentry

To enable Sentry reporting, configure the Sentry Data Source Name (DSN) e.g. use the `-sentry-dsn` argument when starting Supercronic
```
$ ./supercronic -sentry-dsn DSN
```
Expand All @@ -265,6 +268,22 @@ When a DSN is specified via both the environment variable and the command line p
the parameter's DSN has priority.


#### Additional Sentry Configuration

You can also specify the environment and release for Sentry to provide more context to the error reports:

Environment: Use the `-sentry-environment` flag or the `SENTRY_ENVIRONMENT` environment variable to set the environment tag in Sentry.

```
$ ./supercronic -sentry-dsn YOUR_SENTRY_DSN -sentry-environment YOUR_ENVIRONMENT
```

Release: Use the `-sentry-release` flag or the `SENTRY_RELEASE` environment variable to set the release tag in Sentry.

```
$ ./supercronic -sentry-dsn YOUR_SENTRY_DSN -sentry-release YOUR_RELEASE
```

## Questions and Support ###

Please feel free to open an issue in this repository if you have any question
Expand Down
28 changes: 26 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ func main() {
splitLogs := flag.Bool("split-logs", false, "split log output into stdout/stderr")
passthroughLogs := flag.Bool("passthrough-logs", false, "passthrough logs from commands, do not wrap them in Supercronic logging")
sentry := flag.String("sentry-dsn", "", "enable Sentry error logging, using provided DSN")
sentryEnvironmentFlag := flag.String("sentry-environment", "", "specify the application's environment for Sentry error reporting")
sentryReleaseFlag := flag.String("sentry-release", "", "specify the application's release version for Sentry error reporting")
sentryAlias := flag.String("sentryDsn", "", "alias for sentry-dsn")
overlapping := flag.Bool("overlapping", false, "enable tasks overlapping")
flag.Parse()

var sentryDsn string
var (
sentryDsn string
sentryEnvironment string
sentryRelease string
)

sentryDsn = os.Getenv("SENTRY_DSN")
sentryEnvironment = os.Getenv("SENTRY_ENVIRONMENT")
sentryRelease = os.Getenv("SENTRY_RELEASE")

if *sentryAlias != "" {
sentryDsn = *sentryAlias
Expand All @@ -56,6 +64,14 @@ func main() {
sentryDsn = *sentry
}

if *sentryEnvironmentFlag != "" {
sentryEnvironment = *sentryEnvironmentFlag
}

if *sentryReleaseFlag != "" {
sentryRelease = *sentryReleaseFlag
}

if *debug {
logrus.SetLevel(logrus.DebugLevel)
}
Expand Down Expand Up @@ -100,6 +116,14 @@ func main() {
sentryHook = sh
}

if sentryEnvironment != "" {
sh.SetEnvironment(sentryEnvironment)
}

if sentryRelease != "" {
sh.SetRelease(sentryRelease)
}

if sentryHook != nil {
logrus.StandardLogger().AddHook(sentryHook)
}
Expand All @@ -120,7 +144,7 @@ func main() {
}()
}

for true {
for {
promMetrics.Reset()

logrus.Infof("read crontab: %s", crontabFileName)
Expand Down

0 comments on commit fc3d430

Please sign in to comment.