Skip to content

Commit b82f55c

Browse files
committed
Move Span to Sentry.Interfaces
1 parent b470104 commit b82f55c

5 files changed

Lines changed: 69 additions & 32 deletions

File tree

lib/sentry/interfaces.ex

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,47 @@ defmodule Sentry.Interfaces do
267267
:stacktrace
268268
]
269269
end
270+
271+
defmodule Span do
272+
@moduledoc """
273+
The struct for the **span** interface.
274+
275+
See <https://develop.sentry.dev/sdk/event-payloads/spans>.
276+
"""
277+
278+
@moduledoc since: "11.0.0"
279+
280+
@typedoc since: "11.0.0"
281+
@type t() :: %__MODULE__{
282+
trace_id: String.t(),
283+
span_id: String.t(),
284+
start_timestamp: String.t(),
285+
timestamp: String.t(),
286+
parent_span_id: String.t(),
287+
description: String.t(),
288+
op: String.t(),
289+
status: String.t(),
290+
tags: map(),
291+
data: map(),
292+
origin: String.t()
293+
}
294+
295+
@enforce_keys [:trace_id, :span_id, :start_timestamp, :timestamp]
296+
297+
defstruct @enforce_keys ++
298+
[
299+
:parent_span_id,
300+
:description,
301+
:op,
302+
:status,
303+
:tags,
304+
:data,
305+
:origin
306+
]
307+
308+
@doc false
309+
def to_map(%__MODULE__{} = span) do
310+
Map.from_struct(span)
311+
end
312+
end
270313
end

lib/sentry/transaction.ex

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
defmodule Sentry.Transaction do
2-
@type t() :: %__MODULE__{}
2+
@moduledoc """
3+
The struct for the **transaction** interface.
34
4-
alias Sentry.{Config, UUID}
5+
See <https://develop.sentry.dev/sdk/event-payloads/transactions>.
6+
"""
7+
8+
@moduledoc since: "11.0.0"
9+
10+
@typedoc since: "11.0.0"
11+
12+
@type t() :: %__MODULE__{
13+
event_id: String.t(),
14+
environment: String.t(),
15+
transaction: String.t(),
16+
transaction_info: map(),
17+
contexts: map(),
18+
measurements: map(),
19+
type: String.t()
20+
}
21+
22+
alias Sentry.{Config, UUID, Interfaces.Span}
523

624
@enforce_keys [:event_id, :span_id, :spans, :environment]
725

@@ -24,7 +42,6 @@ defmodule Sentry.Transaction do
2442
)
2543
end
2644

27-
# Used to then encode the returned map to JSON.
2845
@doc false
2946
def to_map(%__MODULE__{} = transaction) do
3047
transaction_attrs =
@@ -41,32 +58,9 @@ defmodule Sentry.Transaction do
4158
{[root_span], child_spans} = Enum.split_with(transaction.spans, &is_nil(&1.parent_span_id))
4259

4360
root_span
44-
|> Sentry.Span.to_map()
45-
|> Map.put(:spans, Enum.map(child_spans, &Sentry.Span.to_map/1))
61+
|> Span.to_map()
62+
|> Map.put(:spans, Enum.map(child_spans, &Span.to_map/1))
4663
|> Map.drop([:description])
4764
|> Map.merge(transaction_attrs)
4865
end
4966
end
50-
51-
defmodule Sentry.Span do
52-
@moduledoc false
53-
54-
@enforce_keys [:trace_id, :span_id, :start_timestamp, :timestamp]
55-
56-
defstruct @enforce_keys ++
57-
[
58-
:parent_span_id,
59-
:description,
60-
:op,
61-
:status,
62-
:tags,
63-
:data,
64-
:origin
65-
]
66-
67-
# Used to then encode the returned map to JSON.
68-
@doc false
69-
def to_map(%__MODULE__{} = span) do
70-
Map.from_struct(span)
71-
end
72-
end

test/envelope_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ defmodule Sentry.EnvelopeTest do
118118
put_test_config(environment_name: "test")
119119

120120
root_span =
121-
%Sentry.Span{
121+
%Sentry.Interfaces.Span{
122122
start_timestamp: 1_588_601_261.481_961,
123123
timestamp: 1_588_601_261.488_901,
124124
description: "GET /sockjs-node/info",
@@ -137,7 +137,7 @@ defmodule Sentry.EnvelopeTest do
137137

138138
child_spans =
139139
[
140-
%Sentry.Span{
140+
%Sentry.Interfaces.Span{
141141
start_timestamp: 1_588_601_261.535_386,
142142
timestamp: 1_588_601_261.544_196,
143143
description: "Vue <App>",

test/sentry/client_report/sender_test.exs

Lines changed: 1 addition & 1 deletion
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, Transaction, Span}
7+
alias Sentry.{Event, Transaction, Interfaces.Span}
88

99
setup do
1010
original_retries =

test/sentry_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ defmodule SentryTest do
243243
span_id: "root-span",
244244
transaction: "test-transaction",
245245
spans: [
246-
%Sentry.Span{
246+
%Sentry.Interfaces.Span{
247247
span_id: "root-span",
248248
trace_id: "trace-id",
249249
start_timestamp: 1_234_567_891.123_456,

0 commit comments

Comments
 (0)