@@ -2,12 +2,42 @@ defmodule Sentry.Transaction do
22 @ moduledoc """
33 The struct for the **transaction** interface.
44
5- See <https://develop.sentry.dev/sdk/event-payloads/transactions >.
5+ See <https://develop.sentry.dev/sdk/data-model/ event-payloads/transaction/ >.
66 """
77
88 @ moduledoc since: "11.0.0"
99
10- alias Sentry . { Config , UUID , Interfaces.Span , Interfaces.SDK }
10+ alias Sentry . { Config , UUID , Interfaces , Interfaces.Span , Interfaces.SDK }
11+
12+ @ sdk % Interfaces.SDK {
13+ name: "sentry-elixir" ,
14+ version: Mix.Project . config ( ) [ :version ]
15+ }
16+
17+ @ typedoc """
18+ A map of measurements.
19+
20+ See
21+ [here](https://github.com/getsentry/sentry/blob/a8c960a933d2ded5225841573d8fc426a482ca9c/static/app/utils/discover/fields.tsx#L654-L676)
22+ for the list of supported keys (which could change in the future).
23+ """
24+ @ typedoc since: "11.0.0"
25+ @ type measurements ( ) :: % {
26+ optional ( key :: atom ( ) ) => % {
27+ required ( :value ) => number ( ) ,
28+ optional ( :unit ) => String . t ( )
29+ }
30+ }
31+
32+ @ typedoc """
33+ Transaction information.
34+
35+ Should only be set by integrations and not developers directly.
36+ """
37+ @ typedoc since: "11.0.0"
38+ @ type transaction_info ( ) :: % {
39+ required ( :source ) => String . t ( )
40+ }
1141
1242 @ typedoc since: "11.0.0"
1343 @ type t ( ) ::
@@ -16,7 +46,8 @@ defmodule Sentry.Transaction do
1646 event_id: UUID . t ( ) ,
1747 start_timestamp: String . t ( ) | number ( ) ,
1848 timestamp: String . t ( ) | number ( ) ,
19- platform: :elixir ,
49+ platform: String . t ( ) ,
50+ # See https://develop.sentry.dev/sdk/data-model/event-payloads/contexts/#trace-context
2051 contexts: % {
2152 required ( :trace ) => % {
2253 required ( :trace_id ) => String . t ( ) ,
@@ -31,9 +62,8 @@ defmodule Sentry.Transaction do
3162 # Optional
3263 environment: String . t ( ) ,
3364 transaction: String . t ( ) ,
34- transaction_info: map ( ) ,
35- measurements: map ( ) ,
36- type: String . t ( ) ,
65+ transaction_info: transaction_info ( ) ,
66+ measurements: measurements ( ) ,
3767 tags: map ( ) ,
3868 data: map ( ) ,
3969
@@ -55,8 +85,7 @@ defmodule Sentry.Transaction do
5585 :platform ,
5686 :environment ,
5787 :tags ,
58- :data ,
59- type: "transaction"
88+ :data
6089 ]
6190
6291 @ doc false
@@ -66,13 +95,16 @@ defmodule Sentry.Transaction do
6695 attrs
6796 |> Map . put ( :event_id , UUID . uuid4_hex ( ) )
6897 |> Map . put ( :environment , Config . environment_name ( ) )
98+ |> Map . put ( :sdk , @ sdk )
99+ |> Map . put ( :platform , "elixir" )
69100 )
70101 end
71102
72103 @ doc false
73104 def to_payload ( % __MODULE__ { } = transaction ) do
74105 transaction
75106 |> Map . from_struct ( )
76- |> Map . update ( :spans , [ ] , fn spans -> Enum . map ( spans , & Span . to_payload / 1 ) end )
107+ |> Map . put ( :type , "transaction" )
108+ |> update_in ( [ Access . key ( :spans , [ ] ) , Access . all ( ) ] , & Map . from_struct / 1 )
77109 end
78110end
0 commit comments