diff --git a/client_test.go b/client_test.go index 662687f6..58dcaaca 100644 --- a/client_test.go +++ b/client_test.go @@ -581,39 +581,40 @@ func TestBeforeSendTransactionIsCalled(t *testing.T) { } func TestIgnoreErrors(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { ignoreErrors []string message string expectDrop bool }{ - { - name: "No Match", + "No Match": { message: "Foo", ignoreErrors: []string{"Bar", "Baz"}, expectDrop: false, }, - { - name: "Partial Match", + "Partial Match": { message: "FooBar", ignoreErrors: []string{"Foo", "Baz"}, expectDrop: true, }, - { - name: "Exact Match", + "Exact Match": { message: "Foo Bar", ignoreErrors: []string{"\\bFoo\\b", "Baz"}, expectDrop: true, }, - { - name: "Wildcard Match", + "Wildcard Match": { message: "Foo", ignoreErrors: []string{"F*", "Bar"}, expectDrop: true, }, + "Match string but not pattern": { + message: "(Foo)", + ignoreErrors: []string{"(Foo)"}, + expectDrop: true, + }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + + for name, tt := range tests { + t.Run(name, func(t *testing.T) { scope := &ScopeMock{} transport := &TransportMock{} client, err := NewClient(ClientOptions{ @@ -628,46 +629,47 @@ func TestIgnoreErrors(t *testing.T) { dropped := transport.lastEvent == nil if !(tt.expectDrop == dropped) { - t.Error("expected event to be dropped") + t.Errorf("expected event to be dropped") } }) } } func TestIgnoreTransactions(t *testing.T) { - tests := []struct { - name string + tests := map[string]struct { ignoreTransactions []string transaction string expectDrop bool }{ - { - name: "No Match", + "No Match": { transaction: "Foo", ignoreTransactions: []string{"Bar", "Baz"}, expectDrop: false, }, - { - name: "Partial Match", + "Partial Match": { transaction: "FooBar", ignoreTransactions: []string{"Foo", "Baz"}, expectDrop: true, }, - { - name: "Exact Match", + "Exact Match": { transaction: "Foo Bar", ignoreTransactions: []string{"\\bFoo\\b", "Baz"}, expectDrop: true, }, - { - name: "Wildcard Match", + "Wildcard Match": { transaction: "Foo", ignoreTransactions: []string{"F*", "Bar"}, expectDrop: true, }, + "Match string but not pattern": { + transaction: "(Foo)", + ignoreTransactions: []string{"(Foo)"}, + expectDrop: true, + }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + + for name, tt := range tests { + t.Run(name, func(t *testing.T) { transport := &TransportMock{} ctx := NewTestContext(ClientOptions{ EnableTracing: true, @@ -683,7 +685,7 @@ func TestIgnoreTransactions(t *testing.T) { dropped := transport.lastEvent == nil if !(tt.expectDrop == dropped) { - t.Error("expected event to be dropped") + t.Errorf("expected event to be dropped") } }) } diff --git a/integrations.go b/integrations.go index 4d76bef6..a8b2082a 100644 --- a/integrations.go +++ b/integrations.go @@ -140,7 +140,7 @@ func (iei *ignoreErrorsIntegration) processor(event *Event, _ *EventHint) *Event for _, suspect := range suspects { for _, pattern := range iei.ignoreErrors { - if pattern.Match([]byte(suspect)) { + if pattern.Match([]byte(suspect)) || strings.Contains(suspect, pattern.String()) { Logger.Printf("Event dropped due to being matched by `IgnoreErrors` option."+ "| Value matched: %s | Filter used: %s", suspect, pattern) return nil @@ -202,7 +202,7 @@ func (iei *ignoreTransactionsIntegration) processor(event *Event, _ *EventHint) } for _, pattern := range iei.ignoreTransactions { - if pattern.Match([]byte(suspect)) { + if pattern.Match([]byte(suspect)) || strings.Contains(suspect, pattern.String()) { Logger.Printf("Transaction dropped due to being matched by `IgnoreTransactions` option."+ "| Value matched: %s | Filter used: %s", suspect, pattern) return nil diff --git a/integrations_test.go b/integrations_test.go index bd463882..c43cea53 100644 --- a/integrations_test.go +++ b/integrations_test.go @@ -123,6 +123,7 @@ func TestIgnoreErrorsIntegration(t *testing.T) { ignoreErrors: []*regexp.Regexp{ regexp.MustCompile("foo"), regexp.MustCompile("(?i)bar"), + regexp.MustCompile("(hello)"), }, } @@ -153,6 +154,12 @@ func TestIgnoreErrorsIntegration(t *testing.T) { }}, } + toDrop := &Event{ + Exception: []Exception{{ + Value: "(hello)", + }}, + } + if iei.processor(dropped, &EventHint{}) != nil { t.Error("Event should be dropped") } @@ -172,6 +179,10 @@ func TestIgnoreErrorsIntegration(t *testing.T) { if iei.processor(alsoNotDropped, &EventHint{}) == nil { t.Error("Event should not be dropped") } + + if iei.processor(toDrop, &EventHint{}) != nil { + t.Error("Event should be dropped") + } } func TestIgnoreTransactionsIntegration(t *testing.T) { @@ -179,6 +190,7 @@ func TestIgnoreTransactionsIntegration(t *testing.T) { ignoreTransactions: []*regexp.Regexp{ regexp.MustCompile("foo"), regexp.MustCompile("(?i)bar"), + regexp.MustCompile("(hello)"), }, } @@ -194,6 +206,10 @@ func TestIgnoreTransactionsIntegration(t *testing.T) { Transaction: "dont", } + thisDroppedAsWell := &Event{ + Transaction: "(hello)", + } + if iei.processor(dropped, &EventHint{}) != nil { t.Error("Transaction should be dropped") } @@ -205,6 +221,10 @@ func TestIgnoreTransactionsIntegration(t *testing.T) { if iei.processor(notDropped, &EventHint{}) == nil { t.Error("Transaction should not be dropped") } + + if iei.processor(thisDroppedAsWell, &EventHint{}) != nil { + t.Error("Transaction should be dropped") + } } func TestContextifyFrames(t *testing.T) {