module Patrol.Type.TraceContext where

import qualified Data.Aeson as Aeson
import qualified Data.Text as Text
import qualified Patrol.Extra.Aeson as Aeson
import qualified Patrol.Type.SpanStatus as SpanStatus

-- | <https://develop.sentry.dev/sdk/event-payloads/types/#tracecontext>
data TraceContext = TraceContext
  { TraceContext -> Maybe Int
exclusiveTime :: Maybe Int,
    TraceContext -> Text
op :: Text.Text,
    TraceContext -> Text
parentSpanId :: Text.Text,
    TraceContext -> Text
spanId :: Text.Text,
    TraceContext -> Maybe SpanStatus
status :: Maybe SpanStatus.SpanStatus,
    TraceContext -> Text
traceId :: Text.Text
  }
  deriving (TraceContext -> TraceContext -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TraceContext -> TraceContext -> Bool
$c/= :: TraceContext -> TraceContext -> Bool
== :: TraceContext -> TraceContext -> Bool
$c== :: TraceContext -> TraceContext -> Bool
Eq, Int -> TraceContext -> ShowS
[TraceContext] -> ShowS
TraceContext -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TraceContext] -> ShowS
$cshowList :: [TraceContext] -> ShowS
show :: TraceContext -> String
$cshow :: TraceContext -> String
showsPrec :: Int -> TraceContext -> ShowS
$cshowsPrec :: Int -> TraceContext -> ShowS
Show)

instance Aeson.ToJSON TraceContext where
  toJSON :: TraceContext -> Value
toJSON TraceContext
traceContext =
    [Pair] -> Value
Aeson.intoObject
      [ forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"exclusive_time" forall a b. (a -> b) -> a -> b
$ TraceContext -> Maybe Int
exclusiveTime TraceContext
traceContext,
        forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"op" forall a b. (a -> b) -> a -> b
$ TraceContext -> Text
op TraceContext
traceContext,
        forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"parent_span_id" forall a b. (a -> b) -> a -> b
$ TraceContext -> Text
parentSpanId TraceContext
traceContext,
        forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"span_id" forall a b. (a -> b) -> a -> b
$ TraceContext -> Text
spanId TraceContext
traceContext,
        forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"status" forall a b. (a -> b) -> a -> b
$ TraceContext -> Maybe SpanStatus
status TraceContext
traceContext,
        forall a. ToJSON a => String -> a -> Pair
Aeson.pair String
"trace_id" forall a b. (a -> b) -> a -> b
$ TraceContext -> Text
traceId TraceContext
traceContext
      ]

empty :: TraceContext
empty :: TraceContext
empty =
  TraceContext
    { exclusiveTime :: Maybe Int
exclusiveTime = forall a. Maybe a
Nothing,
      op :: Text
op = Text
Text.empty,
      parentSpanId :: Text
parentSpanId = Text
Text.empty,
      spanId :: Text
spanId = Text
Text.empty,
      status :: Maybe SpanStatus
status = forall a. Maybe a
Nothing,
      traceId :: Text
traceId = Text
Text.empty
    }