Skip to content

Commit eabb0ff

Browse files
committed
Simplify client reports for dropped transactions
1 parent 285e641 commit eabb0ff

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

lib/sentry/client_report/sender.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ defmodule Sentry.ClientReport.Sender do
1717
GenServer.start_link(__MODULE__, nil, name: Keyword.get(opts, :name, __MODULE__))
1818
end
1919

20+
def record_discarded_events(reason, info, genserver \\ __MODULE__)
21+
22+
@spec record_discarded_events(atom(), String.t(), GenServer.server()) :: :ok
23+
def record_discarded_events(reason, data_category, genserver)
24+
when is_binary(data_category) do
25+
GenServer.cast(genserver, {:record_discarded_events, reason, data_category})
26+
end
27+
2028
@spec record_discarded_events(atom(), [item], GenServer.server()) :: :ok
2129
when item:
2230
Sentry.Attachment.t()
2331
| Sentry.CheckIn.t()
2432
| ClientReport.t()
2533
| Sentry.Event.t()
26-
| Sentry.Transaction.t()
27-
def record_discarded_events(reason, event_items, genserver \\ __MODULE__)
34+
def record_discarded_events(reason, event_items, genserver)
2835
when is_list(event_items) do
2936
# We silently ignore events whose reasons aren't valid because we have to add it to the allowlist in Snuba
3037
# https://develop.sentry.dev/sdk/client-reports/

lib/sentry/opentelemetry/sampler.ex

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if Code.ensure_loaded?(:otel_sampler) do
33
@moduledoc false
44

55
alias OpenTelemetry.{Span, Tracer}
6-
alias Sentry.{ClientReport, Transaction}
6+
alias Sentry.ClientReport
77

88
@behaviour :otel_sampler
99

@@ -50,7 +50,7 @@ if Code.ensure_loaded?(:otel_sampler) do
5050

5151
case result do
5252
{:drop, _, _} ->
53-
record_discarded_transaction(ctx)
53+
record_discarded_transaction()
5454
result
5555

5656
_ ->
@@ -119,21 +119,8 @@ if Code.ensure_loaded?(:otel_sampler) do
119119
end
120120
end
121121

122-
defp record_discarded_transaction(ctx) do
123-
span_id =
124-
case Tracer.current_span_ctx(ctx) do
125-
:undefined -> Sentry.UUID.uuid4_hex()
126-
span_ctx -> Span.span_id(span_ctx)
127-
end
128-
129-
transaction =
130-
Transaction.new(%{
131-
span_id: span_id,
132-
start_timestamp: System.system_time(:second),
133-
timestamp: System.system_time(:second)
134-
})
135-
136-
ClientReport.Sender.record_discarded_events(:sample_rate, [transaction])
122+
defp record_discarded_transaction() do
123+
ClientReport.Sender.record_discarded_events(:sample_rate, "transaction")
137124
end
138125
end
139126
end

0 commit comments

Comments
 (0)