diff --git a/README.md b/README.md index b29ce48..7e06c87 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ import ( func main() { z := zapper.New(false) - if err := z.NewCore(zapper.SentryCore(os.Getenv("DSN"), "test", nil)); err != nil { + if err := z.NewCore(zapper.SentryCore(os.Getenv("DSN"), "test", zapper.DEVELOPMENT, nil)); err != nil { log.Fatal(err) } diff --git a/_example/sentry/main.go b/_example/sentry/main.go index 6b4aea1..372140e 100644 --- a/_example/sentry/main.go +++ b/_example/sentry/main.go @@ -8,7 +8,7 @@ import ( func main() { z := zapper.New(false) - if err := z.NewCore(zapper.SentryCore(os.Getenv("DSN"), "test", nil)); err != nil { + if err := z.NewCore(zapper.SentryCore(os.Getenv("DSN"), "test", zapper.DEVELOPMENT, nil)); err != nil { log.Fatal(err) } diff --git a/cores.go b/cores.go index 99496d4..1087be9 100644 --- a/cores.go +++ b/cores.go @@ -17,7 +17,10 @@ import ( //go:generate stringer -type=coreType -type coreType int +type ( + coreType int + SentryEnvironment int +) const ( CONSOLE coreType = iota @@ -26,6 +29,11 @@ const ( JSON ) +const ( + DEVELOPMENT SentryEnvironment = iota // DEVELOPMENT application environment + PRODUCTION // PRODUCTION application environment +) + // Rotation config log file rotation in log path type Rotation struct { MaxAge int // MaxAge is the maximum number of days to retain old log files based on the timestamp encoded in their filename. Note that a day is defined as 24 hours and may not exactly correspond to calendar days due to daylight savings, leap seconds, etc. The default is not to remove old log files based on age. @@ -69,7 +77,7 @@ func ConsoleWriterCore(colorable bool) Core { } // SentryCore send log into sentry service -func SentryCore(dsn string, serverName string, cfg *SentryConfig) Core { +func SentryCore(dsn string, serverName string, environment SentryEnvironment, cfg *SentryConfig) Core { if cfg == nil { cfg = _defaultSentryConfig() } @@ -82,7 +90,7 @@ func SentryCore(dsn string, serverName string, cfg *SentryConfig) Core { Debug: cfg.Debug, EnableTracing: cfg.EnableTracing, TracesSampleRate: 1.0, - Environment: cfg.Environment, + Environment: environment.String(), Dist: cfg.Dist, MaxBreadcrumbs: cfg.MaxBreadcrumbs, MaxSpans: cfg.MaxSpans, @@ -162,6 +170,17 @@ func JsonWriterCore(logPath, fileExtension string, rotation *Rotation) Core { }) } +func (e SentryEnvironment) String() string { + switch e { + case DEVELOPMENT: + return "Development" + case PRODUCTION: + return "Production" + default: + return "Development" + } +} + func (z *core) init(zapper *Zap) error { c, err := z.do(zapper) if err != nil {