Skip to content

Commit

Permalink
update: get environment as parameter sentry core
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad committed Mar 30, 2023
1 parent f02230b commit 5818fb0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion _example/sentry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
25 changes: 22 additions & 3 deletions cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import (

//go:generate stringer -type=coreType

type coreType int
type (
coreType int
SentryEnvironment int
)

const (
CONSOLE coreType = iota
Expand All @@ -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.
Expand Down Expand Up @@ -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()
}
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5818fb0

Please sign in to comment.