mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 06:12:55 +00:00
987a9e8707
* feat_: report panics to sentry * test_: sentry options, params and utils * feat_: toggle sentry with centralized metrics * test_: sentry init, report and close * refactor_: rename public api to generic * docs_: sentry * fix_: typo in internal/sentry/README.md Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com> * fix_: linter --------- Co-authored-by: osmaczko <33099791+osmaczko@users.noreply.github.com>
47 lines
919 B
Go
47 lines
919 B
Go
package sentry
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
)
|
|
|
|
const DefaultEnvVarDSN = "SENTRY_DSN_STATUS_GO"
|
|
const DefaultEnvVarEnvironment = "SENTRY_ENVIRONMENT"
|
|
|
|
type Option func(*sentry.ClientOptions)
|
|
|
|
func WithDSN(dsn string) Option {
|
|
return func(o *sentry.ClientOptions) {
|
|
o.Dsn = dsn
|
|
}
|
|
}
|
|
|
|
func WithEnvironmentDSN(name string) Option {
|
|
return WithDSN(os.Getenv(name))
|
|
}
|
|
|
|
func WithDefaultEnvironmentDSN() Option {
|
|
return WithEnvironmentDSN(DefaultEnvVarDSN)
|
|
}
|
|
|
|
func WithContext(name string, version string) Option {
|
|
return func(o *sentry.ClientOptions) {
|
|
if o.Tags == nil {
|
|
o.Tags = make(map[string]string)
|
|
}
|
|
o.Tags["context.name"] = name
|
|
o.Tags["context.version"] = version
|
|
}
|
|
}
|
|
|
|
func WithDefaultContext() Option {
|
|
return WithContext(DefaultContext(), DefaultContextVersion())
|
|
}
|
|
|
|
func applyOptions(cfg *sentry.ClientOptions, opts ...Option) {
|
|
for _, opt := range opts {
|
|
opt(cfg)
|
|
}
|
|
}
|