-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
182 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'rollbar/util' | ||
|
||
module Rollbar | ||
module Truncation | ||
class RemoveExtraStrategy | ||
include ::Rollbar::Truncation::Mixin | ||
|
||
def self.call(payload) | ||
new.call(payload) | ||
end | ||
|
||
def call(payload) | ||
body = payload['data']['body'] | ||
|
||
delete_message_extra(body) | ||
delete_trace_chain_extra(body) | ||
delete_trace_extra(body) | ||
|
||
dump(payload) | ||
end | ||
|
||
def delete_message_extra(body) | ||
body['message'].delete('extra') if body['message'] && body['message']['extra'] | ||
end | ||
|
||
def delete_trace_chain_extra(body) | ||
body['trace_chain'][0].delete('extra') if body['trace_chain'] && body['trace_chain'][0]['extra'] | ||
end | ||
|
||
def delete_trace_extra(body) | ||
body['trace'].delete('extra') if body['trace'] && body['trace']['extra'] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'rollbar/util' | ||
|
||
module Rollbar | ||
module Truncation | ||
class RemoveRequestStrategy | ||
include ::Rollbar::Truncation::Mixin | ||
|
||
def self.call(payload) | ||
new.call(payload) | ||
end | ||
|
||
def call(payload) | ||
data = payload['data'] | ||
|
||
data.delete('request') if data['request'] | ||
|
||
dump(payload) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
require 'spec_helper' | ||
require 'rollbar/truncation/remove_extra_strategy' | ||
|
||
describe Rollbar::Truncation::RemoveExtraStrategy do | ||
describe '.call' do | ||
let(:extra) { { 'bar' => 'baz' } } | ||
let(:request) { { 'baz' => 'fizz' } } | ||
|
||
context 'with message payload type' do | ||
let(:message_body) { { 'foo' => 'bar' } } | ||
|
||
let(:payload) do | ||
{ | ||
'data' => { | ||
'body' => { | ||
'message' => { | ||
'body' => message_body, | ||
'extra' => extra | ||
} | ||
}, | ||
'request' => request | ||
} | ||
} | ||
end | ||
|
||
it 'should truncate the extra data in the payload' do | ||
result = Rollbar::JSON.load(described_class.call(Rollbar::Util.deep_copy(payload))) | ||
|
||
expect(result['data']['body']['message']['extra']).to be_nil | ||
expect(result['data']['body']['message']['body']).to be_eql(message_body) | ||
expect(result['data']['request']).to be_eql(request) | ||
end | ||
end | ||
|
||
context 'with trace payload type' do | ||
let(:trace_frames) { { 'foo' => 'bar' } } | ||
|
||
let(:payload) do | ||
{ | ||
'data' => { | ||
'body' => { | ||
'trace' => { | ||
'frames' => trace_frames, | ||
'extra' => extra | ||
} | ||
}, | ||
'request' => request | ||
} | ||
} | ||
end | ||
|
||
it 'should truncate the extra data in the payload' do | ||
result = Rollbar::JSON.load(described_class.call(Rollbar::Util.deep_copy(payload))) | ||
|
||
expect(result['data']['body']['trace']['extra']).to be_nil | ||
expect(result['data']['body']['trace']['frames']).to be_eql(trace_frames) | ||
expect(result['data']['request']).to be_eql(request) | ||
end | ||
end | ||
|
||
context 'with trace_chain payload type' do | ||
let(:trace_frames) { { 'foo' => 'bar' } } | ||
|
||
let(:payload) do | ||
{ | ||
'data' => { | ||
'body' => { | ||
'trace_chain' => [{ | ||
'frames' => trace_frames, | ||
'extra' => extra | ||
}] | ||
}, | ||
'request' => request | ||
} | ||
} | ||
end | ||
|
||
it 'should truncate the extra data in the payload' do | ||
result = Rollbar::JSON.load(described_class.call(Rollbar::Util.deep_copy(payload))) | ||
|
||
expect(result['data']['body']['trace_chain'][0]['extra']).to be_nil | ||
expect(result['data']['body']['trace_chain'][0]['frames']).to be_eql(trace_frames) | ||
expect(result['data']['request']).to be_eql(request) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper' | ||
require 'rollbar/truncation/remove_request_strategy' | ||
|
||
describe Rollbar::Truncation::RemoveRequestStrategy do | ||
describe '.call' do | ||
let(:body) { { 'foo' => 'bar' } } | ||
let(:request) { { 'bar' => 'baz' } } | ||
let(:payload) do | ||
{ | ||
'data' => { | ||
'body' => body, | ||
'request' => request | ||
} | ||
} | ||
end | ||
|
||
it 'should truncate the request in the payload' do | ||
result = Rollbar::JSON.load(described_class.call(Rollbar::Util.deep_copy(payload))) | ||
|
||
expect(result['data']['body']).to be_eql(body) | ||
expect(result['data']['request']).to be_nil | ||
end | ||
end | ||
end |