|
99 | 99 | end |
100 | 100 | end |
101 | 101 | end |
| 102 | + |
| 103 | + describe "using config.before_send_log" do |
| 104 | + let(:transport) do |
| 105 | + Sentry.get_current_client.transport |
| 106 | + end |
| 107 | + |
| 108 | + before do |
| 109 | + perform_basic_setup do |config| |
| 110 | + config.enable_logs = true |
| 111 | + config.send_client_reports = send_client_reports |
| 112 | + config.max_log_events = 1 |
| 113 | + config.before_send_log = before_send_log |
| 114 | + end |
| 115 | + end |
| 116 | + |
| 117 | + context "when send_client_reports is turned off and the callback returns a log event" do |
| 118 | + let(:send_client_reports) { false } |
| 119 | + |
| 120 | + let(:before_send_log) do |
| 121 | + ->(log) { |
| 122 | + log.attributes["hello"] = "world" |
| 123 | + log |
| 124 | + } |
| 125 | + end |
| 126 | + |
| 127 | + it "sends processed log events" do |
| 128 | + Sentry.logger.info("Hello World", user_id: 125, action: "create") |
| 129 | + Sentry.logger.info("Hello World", user_id: 123, action: "create") |
| 130 | + Sentry.logger.info("Hello World", user_id: 127, action: "create") |
| 131 | + |
| 132 | + expect(sentry_logs.size).to be(3) |
| 133 | + |
| 134 | + log_event = sentry_logs.last |
| 135 | + |
| 136 | + expect(log_event[:attributes]["hello"]).to eql({ value: "world", type: "string" }) |
| 137 | + end |
| 138 | + end |
| 139 | + |
| 140 | + context "when send_client_reports is turned on and the callback returns a log event" do |
| 141 | + let(:send_client_reports) { true } |
| 142 | + |
| 143 | + let(:before_send_log) do |
| 144 | + ->(log) { |
| 145 | + if log.attributes[:user_id] == 123 |
| 146 | + log |
| 147 | + end |
| 148 | + } |
| 149 | + end |
| 150 | + |
| 151 | + it "records discarded events" do |
| 152 | + Sentry.logger.info("Hello World", user_id: 125, action: "create") |
| 153 | + Sentry.logger.info("Hello World", user_id: 123, action: "create") |
| 154 | + Sentry.logger.info("Hello World", user_id: 127, action: "create") |
| 155 | + |
| 156 | + expect(sentry_logs.size).to be(1) |
| 157 | + |
| 158 | + expect(transport.discarded_events).to include([:before_send, "log_item"] => 2) |
| 159 | + end |
| 160 | + end |
| 161 | + end |
102 | 162 | end |
103 | 163 | end |
0 commit comments