Skip to content

Commit fc3d430

Browse files
authored
Allow to specify sentry envionment and release. (#140)
1 parent 65d24fd commit fc3d430

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ time="2019-01-12T19:35:00+09:00" level=info msg="job succeeded" iteration=0 job.
254254

255255
### Sentry
256256

257-
Report errors to Sentry by passing a Sentry DSN:
257+
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.
258258

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

267270

271+
#### Additional Sentry Configuration
272+
273+
You can also specify the environment and release for Sentry to provide more context to the error reports:
274+
275+
Environment: Use the `-sentry-environment` flag or the `SENTRY_ENVIRONMENT` environment variable to set the environment tag in Sentry.
276+
277+
```
278+
$ ./supercronic -sentry-dsn YOUR_SENTRY_DSN -sentry-environment YOUR_ENVIRONMENT
279+
```
280+
281+
Release: Use the `-sentry-release` flag or the `SENTRY_RELEASE` environment variable to set the release tag in Sentry.
282+
283+
```
284+
$ ./supercronic -sentry-dsn YOUR_SENTRY_DSN -sentry-release YOUR_RELEASE
285+
```
286+
268287
## Questions and Support ###
269288

270289
Please feel free to open an issue in this repository if you have any question

main.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@ func main() {
4040
splitLogs := flag.Bool("split-logs", false, "split log output into stdout/stderr")
4141
passthroughLogs := flag.Bool("passthrough-logs", false, "passthrough logs from commands, do not wrap them in Supercronic logging")
4242
sentry := flag.String("sentry-dsn", "", "enable Sentry error logging, using provided DSN")
43+
sentryEnvironmentFlag := flag.String("sentry-environment", "", "specify the application's environment for Sentry error reporting")
44+
sentryReleaseFlag := flag.String("sentry-release", "", "specify the application's release version for Sentry error reporting")
4345
sentryAlias := flag.String("sentryDsn", "", "alias for sentry-dsn")
4446
overlapping := flag.Bool("overlapping", false, "enable tasks overlapping")
4547
flag.Parse()
4648

47-
var sentryDsn string
49+
var (
50+
sentryDsn string
51+
sentryEnvironment string
52+
sentryRelease string
53+
)
4854

4955
sentryDsn = os.Getenv("SENTRY_DSN")
56+
sentryEnvironment = os.Getenv("SENTRY_ENVIRONMENT")
57+
sentryRelease = os.Getenv("SENTRY_RELEASE")
5058

5159
if *sentryAlias != "" {
5260
sentryDsn = *sentryAlias
@@ -56,6 +64,14 @@ func main() {
5664
sentryDsn = *sentry
5765
}
5866

67+
if *sentryEnvironmentFlag != "" {
68+
sentryEnvironment = *sentryEnvironmentFlag
69+
}
70+
71+
if *sentryReleaseFlag != "" {
72+
sentryRelease = *sentryReleaseFlag
73+
}
74+
5975
if *debug {
6076
logrus.SetLevel(logrus.DebugLevel)
6177
}
@@ -100,6 +116,14 @@ func main() {
100116
sentryHook = sh
101117
}
102118

119+
if sentryEnvironment != "" {
120+
sh.SetEnvironment(sentryEnvironment)
121+
}
122+
123+
if sentryRelease != "" {
124+
sh.SetRelease(sentryRelease)
125+
}
126+
103127
if sentryHook != nil {
104128
logrus.StandardLogger().AddHook(sentryHook)
105129
}
@@ -120,7 +144,7 @@ func main() {
120144
}()
121145
}
122146

123-
for true {
147+
for {
124148
promMetrics.Reset()
125149

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

0 commit comments

Comments
 (0)