Skip to content

Commit

Permalink
Keep only trace disabled option
Browse files Browse the repository at this point in the history
  • Loading branch information
anuptalwalkar committed Mar 3, 2017
1 parent 727fd01 commit 1f18d42
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
8 changes: 3 additions & 5 deletions ulog/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ logging:
dsn:
trace:
disabled: true
skip_frames: 10
context_lines: 15
`)
)

Expand All @@ -69,6 +67,7 @@ func TestSetLogger(t *testing.T) {
}

func TestConfigureLogger(t *testing.T) {
t.Parallel()
var logConfig Configuration
cfg := config.NewYAMLProviderFromBytes(_logyaml).Get("logging")
err := logConfig.Configure(cfg)
Expand All @@ -80,15 +79,14 @@ func TestConfigureLogger(t *testing.T) {
}

func TestConfigureSentryLogger(t *testing.T) {
t.Parallel()
var logConfig Configuration
cfg := config.NewYAMLProviderFromBytes(_sentryyaml).Get("logging")
err := logConfig.Configure(cfg)
require.NoError(t, err)
assert.NotNil(t, logConfig.Sentry)
assert.Equal(t, "", logConfig.Sentry.DSN)
assert.Equal(t, bool(true), logConfig.Sentry.Trace.Disabled)
assert.Equal(t, 10, *logConfig.Sentry.Trace.SkipFrames)
assert.Equal(t, 15, *logConfig.Sentry.Trace.ContextLines)
assert.Equal(t, true, logConfig.Sentry.Trace.Disabled)

logger, err := logConfig.Build()
require.NoError(t, err)
Expand Down
54 changes: 17 additions & 37 deletions ulog/sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ type client interface {
// Configuration is a minimal set of parameters for Sentry integration.
type Configuration struct {
DSN string `yaml:"DSN"`
Trace *struct {
Disabled bool
SkipFrames *int `yaml:"skip_frames"`
ContextLines *int `yaml:"context_lines"`
}
Trace trace
}

type trace struct {
Disabled bool
}

// Build uses the provided configuration to construct a Sentry-backed logging
Expand All @@ -81,35 +81,17 @@ func (c Configuration) Build() (zapcore.Core, error) {
type core struct {
client
zapcore.LevelEnabler
trace

traceEnabled bool
traceSkipFrames int
traceContextLines int
fields map[string]interface{}
fields map[string]interface{}
}

func newCore(cfg Configuration, c client, enab zapcore.LevelEnabler) *core {
sentryCore := &core{
client: c,
LevelEnabler: enab,
traceEnabled: true,
traceSkipFrames: _traceSkipFrames,
traceContextLines: _traceContextLines,
fields: make(map[string]interface{}),
}
t := cfg.Trace
if t == nil {
return sentryCore
}

if t.Disabled {
sentryCore.traceEnabled = false
}
if t.SkipFrames != nil {
sentryCore.traceSkipFrames = *t.SkipFrames
}
if t.ContextLines != nil {
sentryCore.traceContextLines = *t.ContextLines
client: c,
LevelEnabler: enab,
trace: cfg.Trace,
fields: make(map[string]interface{}),
}
return sentryCore
}
Expand All @@ -136,8 +118,8 @@ func (c *core) Write(ent zapcore.Entry, fs []zapcore.Field) error {
Extra: clone.fields,
}

if c.traceEnabled {
trace := raven.NewStacktrace(c.traceSkipFrames, c.traceContextLines, nil /* app prefixes */)
if !c.trace.Disabled {
trace := raven.NewStacktrace(_traceSkipFrames, _traceContextLines, nil /* app prefixes */)
if trace != nil {
packet.Interfaces = append(packet.Interfaces, trace)
}
Expand Down Expand Up @@ -173,11 +155,9 @@ func (c *core) with(fs []zapcore.Field) *core {
}

return &core{
client: c.client,
LevelEnabler: c.LevelEnabler,
traceEnabled: c.traceEnabled,
traceSkipFrames: c.traceSkipFrames,
traceContextLines: c.traceContextLines,
fields: m,
client: c.client,
LevelEnabler: c.LevelEnabler,
trace: c.trace,
fields: m,
}
}
4 changes: 4 additions & 0 deletions ulog/sentry/sentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func asCore(t testing.TB, iface zapcore.Core) *core {
}

func TestRavenSeverityMap(t *testing.T) {
t.Parallel()
tests := []struct {
z zapcore.Level
r raven.Severity
Expand All @@ -96,6 +97,7 @@ func TestRavenSeverityMap(t *testing.T) {
}

func TestCoreWith(t *testing.T) {
t.Parallel()
cfg := Configuration{
DSN: "testdsn",
}
Expand All @@ -122,6 +124,7 @@ func TestCoreWith(t *testing.T) {
}

func TestCoreCheck(t *testing.T) {
t.Parallel()
cfg := Configuration{
DSN: "testdsn",
}
Expand Down Expand Up @@ -163,6 +166,7 @@ func TestConfigWrite(t *testing.T) {
}

func TestConfigBuild(t *testing.T) {
t.Parallel()
broken := Configuration{DSN: "invalid"}
_, err := broken.Build()
assert.Error(t, err, "Expected invalid DSN to make config building fail.")
Expand Down

0 comments on commit 1f18d42

Please sign in to comment.