@@ -7,28 +7,54 @@ defmodule Sentry.Transaction do
77
88 @ moduledoc since: "11.0.0"
99
10+ alias Sentry . { Config , UUID , Interfaces.Span , Interfaces.SDK }
11+
1012 @ typedoc since: "11.0.0"
13+ @ type t ( ) :: % {
14+ # Required
15+ required ( :event_id ) => << _ :: 256 >> ,
16+ required ( :start_timestamp ) => String . t ( ) | number ( ) ,
17+ required ( :timestamp ) => String . t ( ) | number ( ) ,
18+ required ( :platform ) => :elixir ,
19+ required ( :contexts ) => % {
20+ required ( :trace ) => % {
21+ required ( :trace_id ) => String . t ( ) ,
22+ required ( :span_id ) => String . t ( ) ,
23+ optional ( :parent_span_id ) => String . t ( ) ,
24+ optional ( :op ) => String . t ( ) ,
25+ optional ( :description ) => String . t ( ) ,
26+ optional ( :status ) => String . t ( )
27+ }
28+ } ,
1129
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- }
30+ # Optional
31+ optional ( :environment ) => String . t ( ) ,
32+ optional ( :transaction ) => String . t ( ) ,
33+ optional ( :transaction_info ) => map ( ) ,
34+ optional ( :measurements ) => map ( ) ,
35+ optional ( :type ) => String . t ( ) ,
36+ optional ( :tags ) => map ( ) ,
37+ optional ( :data ) => map ( ) ,
2138
22- alias Sentry . { Config , UUID , Interfaces.Span }
39+ # Interfaces
40+ optional ( :spans ) => [ Span . t ( ) ] ,
41+ optional ( :sdk ) => SDK . t ( )
42+ }
2343
24- @ enforce_keys [ :event_id , :span_id , :spans , :environment ]
44+ @ enforce_keys [ :event_id , :span_id , :start_timestamp , :timestamp ]
2545
2646 defstruct @ enforce_keys ++
2747 [
48+ :spans ,
2849 :transaction ,
2950 :transaction_info ,
3051 :contexts ,
3152 :measurements ,
53+ :sdk ,
54+ :platform ,
55+ :environment ,
56+ :tags ,
57+ :data ,
3258 type: "transaction"
3359 ]
3460
@@ -43,24 +69,9 @@ defmodule Sentry.Transaction do
4369 end
4470
4571 @ doc false
46- def to_map ( % __MODULE__ { } = transaction ) do
47- transaction_attrs =
48- Map . take ( transaction , [
49- :event_id ,
50- :environment ,
51- :transaction ,
52- :transaction_info ,
53- :contexts ,
54- :measurements ,
55- :type
56- ] )
57-
58- { [ root_span ] , child_spans } = Enum . split_with ( transaction . spans , & is_nil ( & 1 . parent_span_id ) )
59-
60- root_span
61- |> Span . to_map ( )
62- |> Map . put ( :spans , Enum . map ( child_spans , & Span . to_map / 1 ) )
63- |> Map . drop ( [ :description ] )
64- |> Map . merge ( transaction_attrs )
72+ def to_payload ( % __MODULE__ { } = transaction ) do
73+ transaction
74+ |> Map . from_struct ( )
75+ |> Map . update ( :spans , [ ] , fn spans -> Enum . map ( spans , & Span . to_payload / 1 ) end )
6576 end
6677end
0 commit comments