Skip to content

Commit 83b0162

Browse files
committed
Support Transaction in client reports
1 parent 7490f9c commit 83b0162

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

lib/sentry/envelope.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,20 @@ defmodule Sentry.Envelope do
6363
Returns the "data category" of the envelope's contents (to be used in client reports and more).
6464
"""
6565
@doc since: "10.8.0"
66-
@spec get_data_category(Attachment.t() | CheckIn.t() | ClientReport.t() | Event.t()) ::
66+
@spec get_data_category(
67+
Attachment.t()
68+
| CheckIn.t()
69+
| ClientReport.t()
70+
| Event.t()
71+
| Transaction.t()
72+
) ::
6773
String.t()
6874
def get_data_category(%Attachment{}), do: "attachment"
6975
def get_data_category(%CheckIn{}), do: "monitor"
7076
def get_data_category(%ClientReport{}), do: "internal"
7177
def get_data_category(%Event{}), do: "error"
78+
# TODO: is this correct?
79+
def get_data_category(%Transaction{}), do: "error"
7280

7381
@doc """
7482
Encodes the envelope into its binary representation.

test/sentry/client_report/sender_test.exs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Sentry.ClientReportTest do
44
import Sentry.TestHelpers
55

66
alias Sentry.ClientReport.Sender
7-
alias Sentry.Event
7+
alias Sentry.{Event, Transaction}
88

99
setup do
1010
original_retries =
@@ -27,24 +27,28 @@ defmodule Sentry.ClientReportTest do
2727
%Event{
2828
event_id: Sentry.UUID.uuid4_hex(),
2929
timestamp: "2024-10-12T13:21:13"
30+
},
31+
%Transaction{
32+
event_id: Sentry.UUID.uuid4_hex(),
33+
timestamp: "2024-10-12T13:21:13"
3034
}
3135
]
3236

3337
assert :ok = Sender.record_discarded_events(:before_send, events, :test_client_report)
3438

35-
assert :sys.get_state(:test_client_report) == %{{:before_send, "error"} => 1}
39+
assert :sys.get_state(:test_client_report) == %{{:before_send, "error"} => 2}
3640

3741
assert :ok = Sender.record_discarded_events(:before_send, events, :test_client_report)
3842

39-
assert :sys.get_state(:test_client_report) == %{{:before_send, "error"} => 2}
43+
assert :sys.get_state(:test_client_report) == %{{:before_send, "error"} => 4}
4044

4145
assert :ok = Sender.record_discarded_events(:event_processor, events, :test_client_report)
4246
assert :ok = Sender.record_discarded_events(:network_error, events, :test_client_report)
4347

4448
assert :sys.get_state(:test_client_report) == %{
45-
{:before_send, "error"} => 2,
46-
{:event_processor, "error"} => 1,
47-
{:network_error, "error"} => 1
49+
{:before_send, "error"} => 4,
50+
{:event_processor, "error"} => 2,
51+
{:network_error, "error"} => 2
4852
}
4953

5054
send(Process.whereis(:test_client_report), :send_report)
@@ -56,9 +60,9 @@ defmodule Sentry.ClientReportTest do
5660
decode_envelope!(body)
5761

5862
assert client_report["discarded_events"] == [
59-
%{"reason" => "before_send", "category" => "error", "quantity" => 2},
60-
%{"reason" => "event_processor", "category" => "error", "quantity" => 1},
61-
%{"reason" => "network_error", "category" => "error", "quantity" => 1}
63+
%{"reason" => "before_send", "category" => "error", "quantity" => 4},
64+
%{"reason" => "event_processor", "category" => "error", "quantity" => 2},
65+
%{"reason" => "network_error", "category" => "error", "quantity" => 2}
6266
]
6367

6468
assert client_report["timestamp"] =~ ~r/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/

0 commit comments

Comments
 (0)