Skip to content

Commit

Permalink
match strings for ignoreErrors as well (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribice authored Apr 21, 2024
1 parent 7954115 commit 84427d8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 28 deletions.
54 changes: 28 additions & 26 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand All @@ -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")
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func TestIgnoreErrorsIntegration(t *testing.T) {
ignoreErrors: []*regexp.Regexp{
regexp.MustCompile("foo"),
regexp.MustCompile("(?i)bar"),
regexp.MustCompile("(hello)"),
},
}

Expand Down Expand Up @@ -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")
}
Expand All @@ -172,13 +179,18 @@ 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) {
iei := ignoreTransactionsIntegration{
ignoreTransactions: []*regexp.Regexp{
regexp.MustCompile("foo"),
regexp.MustCompile("(?i)bar"),
regexp.MustCompile("(hello)"),
},
}

Expand All @@ -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")
}
Expand All @@ -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) {
Expand Down

0 comments on commit 84427d8

Please sign in to comment.