Skip to content

Refactor New() function and use one config argument #51

@evalphobia

Description

@evalphobia

There are many New... method to create *SentryHook.
To scale configuration, add a config struct and use it in New() function.

For example below,

// something like this
type Config struct {
    Levels []logrus.Level
    StacktraceConfiguration

    DSN string
    Async bool
    Tags map[string]string
    Release string
    Environment string
    // etc...
}

func New(conf Config) (*SentryHook, error) {
    client, err := raven.NewWithTags(conf.DSN, conf.Tags)
    if err != nil {
        return nil, err
    }

    if conf.Release != "" {
        client.SetRelease(conf.Release)
    }
    if conf.Environment != "" {
        client.SetEnvironment(conf.Environment)
    }

    hook := &SentryHook{
        asynchronous: conf.Async,
    }
   // etc...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions