File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -114,13 +114,15 @@ defmodule Sentry.Client do
114114 result_type = Keyword . get_lazy ( opts , :result , & Config . send_result / 0 )
115115 client = Keyword . get_lazy ( opts , :client , & Config . client / 0 )
116116 sample_rate = Keyword . get_lazy ( opts , :sample_rate , & Config . sample_rate / 0 )
117+ before_send = Keyword . get_lazy ( opts , :before_send , & Config . before_send / 0 )
117118
118119 request_retries =
119120 Keyword . get_lazy ( opts , :request_retries , fn ->
120121 Application . get_env ( :sentry , :request_retries , Transport . default_retries ( ) )
121122 end )
122123
123- with :ok <- sample_event ( sample_rate ) do
124+ with :ok <- sample_event ( sample_rate ) ,
125+ { :ok , % Transaction { } = transaction } <- maybe_call_before_send ( transaction , before_send ) do
124126 case encode_and_send ( transaction , result_type , client , request_retries ) do
125127 { :ok , id } ->
126128 { :ok , id }
@@ -132,6 +134,9 @@ defmodule Sentry.Client do
132134 :unsampled ->
133135 ClientReport.Sender . record_discarded_events ( :sample_rate , [ transaction ] )
134136 :unsampled
137+
138+ :excluded ->
139+ :excluded
135140 end
136141 end
137142
Original file line number Diff line number Diff line change @@ -304,5 +304,30 @@ defmodule SentryTest do
304304 test "sends client report when sample_rate is 0.0" , % { transaction: transaction } do
305305 assert :unsampled = Sentry . send_transaction ( transaction , sample_rate: 0.0 )
306306 end
307+
308+ test "supports before_send option" , % { bypass: bypass , transaction: transaction } do
309+ # Exclude transaction
310+ assert :excluded =
311+ Sentry . send_transaction ( transaction , before_send: fn _transaction -> false end )
312+
313+ # Modify transaction
314+ Bypass . expect_once ( bypass , "POST" , "/api/1/envelope/" , fn conn ->
315+ { :ok , body , conn } = Plug.Conn . read_body ( conn )
316+
317+ assert [ { headers , transaction_body } ] = decode_envelope! ( body )
318+ assert headers [ "type" ] == "transaction"
319+ assert transaction_body [ "transaction" ] == "modified-transaction"
320+
321+ Plug.Conn . send_resp ( conn , 200 , ~s< {"id": "340"}> )
322+ end )
323+
324+ assert { :ok , "340" } =
325+ Sentry . send_transaction (
326+ transaction ,
327+ before_send: fn transaction ->
328+ % { transaction | transaction: "modified-transaction" }
329+ end
330+ )
331+ end
307332 end
308333end
You can’t perform that action at this time.
0 commit comments