@@ -15,7 +15,8 @@ defmodule Sentry.Client do
1515 Interfaces ,
1616 LoggerUtils ,
1717 Transport ,
18- Options
18+ Options ,
19+ Transaction
1920 }
2021
2122 require Logger
@@ -91,6 +92,29 @@ defmodule Sentry.Client do
9192 end
9293 end
9394
95+ def send_transaction ( % Transaction { } = transaction , opts \\ [ ] ) do
96+ # opts = validate_options!(opts)
97+
98+ result_type = Keyword . get_lazy ( opts , :result , & Config . send_result / 0 )
99+ client = Keyword . get_lazy ( opts , :client , & Config . client / 0 )
100+
101+ request_retries =
102+ Keyword . get_lazy ( opts , :request_retries , fn ->
103+ Application . get_env ( :sentry , :request_retries , Transport . default_retries ( ) )
104+ end )
105+
106+ case encode_and_send ( transaction , result_type , client , request_retries ) do
107+ { :ok , id } ->
108+ { :ok , id }
109+
110+ { :error , { status , headers , body } } ->
111+ { :error , ClientError . server_error ( status , headers , body ) }
112+
113+ { :error , reason } ->
114+ { :error , ClientError . new ( reason ) }
115+ end
116+ end
117+
94118 defp sample_event ( sample_rate ) do
95119 cond do
96120 sample_rate == 1 -> :ok
@@ -189,6 +213,42 @@ defmodule Sentry.Client do
189213 end
190214 end
191215
216+ defp encode_and_send (
217+ % Transaction { } = transaction ,
218+ _result_type = :sync ,
219+ client ,
220+ request_retries
221+ ) do
222+ case Sentry.Test . maybe_collect ( transaction ) do
223+ :collected ->
224+ { :ok , "" }
225+
226+ :not_collecting ->
227+ send_result =
228+ transaction
229+ |> Envelope . from_transaction ( )
230+ |> Transport . encode_and_post_envelope ( client , request_retries )
231+
232+ send_result
233+ end
234+ end
235+
236+ defp encode_and_send (
237+ % Transaction { } = transaction ,
238+ _result_type = :none ,
239+ client ,
240+ _request_retries
241+ ) do
242+ case Sentry.Test . maybe_collect ( transaction ) do
243+ :collected ->
244+ { :ok , "" }
245+
246+ :not_collecting ->
247+ :ok = Transport.Sender . send_async ( client , transaction )
248+ { :ok , "" }
249+ end
250+ end
251+
192252 @ spec render_event ( Event . t ( ) ) :: map ( )
193253 def render_event ( % Event { } = event ) do
194254 json_library = Config . json_library ( )
@@ -209,6 +269,11 @@ defmodule Sentry.Client do
209269 |> update_if_present ( :threads , fn list -> Enum . map ( list , & render_thread / 1 ) end )
210270 end
211271
272+ @ spec render_transaction ( % Transaction { } ) :: map ( )
273+ def render_transaction ( % Transaction { } = transaction ) do
274+ Transaction . to_map ( transaction )
275+ end
276+
212277 defp render_exception ( % Interfaces.Exception { } = exception ) do
213278 exception
214279 |> Map . from_struct ( )
0 commit comments