Skip to content

Commit 7139e55

Browse files
authored
feat: Remove IgnoreError and send sentry only on panics (#60)
We will be logging everything as log and moving log analysis to external tools such as jq. Also, for sentry we will be only looking for panics and not for incorrect classification as we dont classify anything anymore
1 parent 08d88fb commit 7139e55

File tree

3 files changed

+8
-45
lines changed

3 files changed

+8
-45
lines changed

plugins/source.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ type SourcePlugin struct {
2121
name string
2222
// Version of the plugin
2323
version string
24-
// Classify error and return it's severity and type
25-
ignoreError schema.IgnoreErrorFunc
2624
// Called upon configure call to validate and init configuration
2725
newExecutionClient SourceNewExecutionClientFunc
2826
// Tables is all tables supported by this source plugin
@@ -49,12 +47,6 @@ func WithSourceLogger(logger zerolog.Logger) SourceOption {
4947
}
5048
}
5149

52-
func WithClassifyError(ignoreError schema.IgnoreErrorFunc) SourceOption {
53-
return func(p *SourcePlugin) {
54-
p.ignoreError = ignoreError
55-
}
56-
}
57-
5850
// Add internal columns
5951
func addInternalColumns(tables []*schema.Table) {
6052
for _, table := range tables {
@@ -81,12 +73,6 @@ func NewSourcePlugin(name string, version string, tables []*schema.Table, newExe
8173
if err := p.validate(); err != nil {
8274
panic(err)
8375
}
84-
// if ignore error is not set on a table level set it with the plugin
85-
for _, table := range p.tables {
86-
if table.IgnoreError == nil && p.ignoreError != nil {
87-
table.IgnoreError = p.ignoreError
88-
}
89-
}
9076
return &p
9177
}
9278

@@ -162,10 +148,6 @@ func (p *SourcePlugin) Sync(ctx context.Context, spec specs.Source, res chan<- *
162148
if table.Multiplex != nil {
163149
clients = table.Multiplex(c)
164150
}
165-
// because table can't import sourceplugin we need to set classifyError if it is not set by table
166-
if table.IgnoreError == nil {
167-
table.IgnoreError = p.ignoreError
168-
}
169151
// we call this here because we dont know when the following goroutine will be called and we do want an order
170152
// of table by table
171153
// totalClients := len(clients)

schema/table.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ type TableResolver func(ctx context.Context, meta ClientMeta, parent *Resource,
2424

2525
type RowResolver func(ctx context.Context, meta ClientMeta, resource *Resource) error
2626

27-
// Classify error and return it's severity and type
28-
type IgnoreErrorFunc func(err error) (bool, string)
29-
3027
type Tables []*Table
3128

3229
type Table struct {
@@ -40,8 +37,6 @@ type Table struct {
4037
Relations Tables `json:"relations"`
4138
// Resolver is the main entry point to fetching table data and
4239
Resolver TableResolver `json:"-"`
43-
// IgnoreError is a function that classifies error and returns it's severity and type
44-
IgnoreError IgnoreErrorFunc `json:"-"`
4540
// Multiplex returns re-purposed meta clients. The sdk will execute the table with each of them
4641
Multiplex func(meta ClientMeta) []ClientMeta `json:"-"`
4742
// PostResourceResolver is called after all columns have been resolved, but before the Resource is sent to be inserted. The ordering of resolvers is:
@@ -162,34 +157,23 @@ func (t Table) Resolve(ctx context.Context, meta ClientMeta, syncTime time.Time,
162157
go func() {
163158
defer func() {
164159
if err := recover(); err != nil {
160+
sentry.WithScope(func(scope *sentry.Scope) {
161+
scope.SetTag("table", t.Name)
162+
sentry.CurrentHub().Recover(err)
163+
})
165164
stack := string(debug.Stack())
166165
meta.Logger().Error().Interface("error", err).Str("table_name", t.Name).TimeDiff("duration", time.Now(), startTime).Str("stack", stack).Msg("table resolver finished with panic")
167166
}
168167
close(res)
169168
}()
170169
meta.Logger().Debug().Str("table_name", t.Name).Msg("table resolver started")
171170
if err := t.Resolver(ctx, meta, parent, res); err != nil {
172-
if t.IgnoreError != nil {
173-
if ignore, errType := t.IgnoreError(err); ignore {
174-
meta.Logger().Debug().Stack().Str("table_name", t.Name).TimeDiff("duration", time.Now(), startTime).Str("error_type", errType).Err(err).Msg("table resolver finished with error")
175-
return
176-
}
177-
}
178-
sentry.WithScope(func(scope *sentry.Scope) {
179-
scope.SetTag("table", t.Name)
180-
scope.SetLevel(sentry.LevelError)
181-
sentry.CaptureMessage(err.Error())
182-
})
183171
meta.Logger().Error().Str("table_name", t.Name).TimeDiff("duration", time.Now(), startTime).Err(err).Msg("table resolver finished with error")
184172
return
185173
}
186174
meta.Logger().Debug().Str("table_name", t.Name).TimeDiff("duration", time.Now(), startTime).Msg("table resolver finished successfully")
187175
}()
188176
totalResources := 0
189-
// we want to check for data integrity
190-
// in the future we can do that as an optinoal feature via a flag
191-
// pks := map[string]bool{}
192-
// each result is an array of interface{}
193177
for elem := range res {
194178
objects := helpers.InterfaceSlice(elem)
195179
if len(objects) == 0 {
@@ -214,11 +198,6 @@ func (t Table) Resolve(ctx context.Context, meta ClientMeta, syncTime time.Time,
214198
meta.Logger().Trace().Str("table_name", t.Name).Msg("post resource resolver finished successfully")
215199
}
216200
}
217-
// if pks[resource.PrimaryKeyValue()] {
218-
// meta.Logger().Error().Str("table_name", t.Name).Str("primary_key", resource.PrimaryKeyValue()).Msg("duplicate primary key found")
219-
// } else {
220-
// pks[resource.PrimaryKeyValue()] = true
221-
// }
222201
resolvedResources <- resource
223202
for _, rel := range t.Relations {
224203
totalResources += rel.Resolve(ctx, meta, syncTime, resource, resolvedResources)

serve/serve.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ func newCmdServe(opts Options) *cobra.Command {
9696

9797
if !noSentry && version != "development" {
9898
err = sentry.Init(sentry.ClientOptions{
99-
Dsn: opts.SentryDsn,
100-
Release: opts.SourcePlugin.Version(),
99+
Dsn: opts.SentryDsn,
100+
Debug: false,
101+
AttachStacktrace: true,
102+
Release: opts.SourcePlugin.Version(),
101103
// https://docs.sentry.io/platforms/go/configuration/options/#removing-default-integrations
102104
Integrations: func(integrations []sentry.Integration) []sentry.Integration {
103105
var filteredIntegrations []sentry.Integration

0 commit comments

Comments
 (0)