{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module OpenTelemetry.SpanContext where

import Data.Hashable
import Data.Word
import GHC.Generics
import Text.Printf

newtype TraceId = TId Word64
  deriving (TraceId -> TraceId -> Bool
(TraceId -> TraceId -> Bool)
-> (TraceId -> TraceId -> Bool) -> Eq TraceId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TraceId -> TraceId -> Bool
$c/= :: TraceId -> TraceId -> Bool
== :: TraceId -> TraceId -> Bool
$c== :: TraceId -> TraceId -> Bool
Eq, Eq TraceId
Eq TraceId
-> (TraceId -> TraceId -> Ordering)
-> (TraceId -> TraceId -> Bool)
-> (TraceId -> TraceId -> Bool)
-> (TraceId -> TraceId -> Bool)
-> (TraceId -> TraceId -> Bool)
-> (TraceId -> TraceId -> TraceId)
-> (TraceId -> TraceId -> TraceId)
-> Ord TraceId
TraceId -> TraceId -> Bool
TraceId -> TraceId -> Ordering
TraceId -> TraceId -> TraceId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TraceId -> TraceId -> TraceId
$cmin :: TraceId -> TraceId -> TraceId
max :: TraceId -> TraceId -> TraceId
$cmax :: TraceId -> TraceId -> TraceId
>= :: TraceId -> TraceId -> Bool
$c>= :: TraceId -> TraceId -> Bool
> :: TraceId -> TraceId -> Bool
$c> :: TraceId -> TraceId -> Bool
<= :: TraceId -> TraceId -> Bool
$c<= :: TraceId -> TraceId -> Bool
< :: TraceId -> TraceId -> Bool
$c< :: TraceId -> TraceId -> Bool
compare :: TraceId -> TraceId -> Ordering
$ccompare :: TraceId -> TraceId -> Ordering
$cp1Ord :: Eq TraceId
Ord, (forall x. TraceId -> Rep TraceId x)
-> (forall x. Rep TraceId x -> TraceId) -> Generic TraceId
forall x. Rep TraceId x -> TraceId
forall x. TraceId -> Rep TraceId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TraceId x -> TraceId
$cfrom :: forall x. TraceId -> Rep TraceId x
Generic, Eq TraceId
Eq TraceId
-> (Int -> TraceId -> Int) -> (TraceId -> Int) -> Hashable TraceId
Int -> TraceId -> Int
TraceId -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: TraceId -> Int
$chash :: TraceId -> Int
hashWithSalt :: Int -> TraceId -> Int
$chashWithSalt :: Int -> TraceId -> Int
$cp1Hashable :: Eq TraceId
Hashable)

instance Show TraceId where
  show :: TraceId -> String
show (TId Word64
tid) = String -> Word64 -> String
forall r. PrintfType r => String -> r
printf String
"(TId 0x%x)" Word64
tid

newtype SpanId = SId Word64
  deriving (SpanId -> SpanId -> Bool
(SpanId -> SpanId -> Bool)
-> (SpanId -> SpanId -> Bool) -> Eq SpanId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpanId -> SpanId -> Bool
$c/= :: SpanId -> SpanId -> Bool
== :: SpanId -> SpanId -> Bool
$c== :: SpanId -> SpanId -> Bool
Eq, Eq SpanId
Eq SpanId
-> (SpanId -> SpanId -> Ordering)
-> (SpanId -> SpanId -> Bool)
-> (SpanId -> SpanId -> Bool)
-> (SpanId -> SpanId -> Bool)
-> (SpanId -> SpanId -> Bool)
-> (SpanId -> SpanId -> SpanId)
-> (SpanId -> SpanId -> SpanId)
-> Ord SpanId
SpanId -> SpanId -> Bool
SpanId -> SpanId -> Ordering
SpanId -> SpanId -> SpanId
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SpanId -> SpanId -> SpanId
$cmin :: SpanId -> SpanId -> SpanId
max :: SpanId -> SpanId -> SpanId
$cmax :: SpanId -> SpanId -> SpanId
>= :: SpanId -> SpanId -> Bool
$c>= :: SpanId -> SpanId -> Bool
> :: SpanId -> SpanId -> Bool
$c> :: SpanId -> SpanId -> Bool
<= :: SpanId -> SpanId -> Bool
$c<= :: SpanId -> SpanId -> Bool
< :: SpanId -> SpanId -> Bool
$c< :: SpanId -> SpanId -> Bool
compare :: SpanId -> SpanId -> Ordering
$ccompare :: SpanId -> SpanId -> Ordering
$cp1Ord :: Eq SpanId
Ord, (forall x. SpanId -> Rep SpanId x)
-> (forall x. Rep SpanId x -> SpanId) -> Generic SpanId
forall x. Rep SpanId x -> SpanId
forall x. SpanId -> Rep SpanId x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SpanId x -> SpanId
$cfrom :: forall x. SpanId -> Rep SpanId x
Generic, Eq SpanId
Eq SpanId
-> (Int -> SpanId -> Int) -> (SpanId -> Int) -> Hashable SpanId
Int -> SpanId -> Int
SpanId -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: SpanId -> Int
$chash :: SpanId -> Int
hashWithSalt :: Int -> SpanId -> Int
$chashWithSalt :: Int -> SpanId -> Int
$cp1Hashable :: Eq SpanId
Hashable)

instance Show SpanId where
  show :: SpanId -> String
show (SId Word64
sid) = String -> Word64 -> String
forall r. PrintfType r => String -> r
printf String
"(SId 0x%x)" Word64
sid

data SpanContext = SpanContext !SpanId !TraceId
  deriving (Int -> SpanContext -> ShowS
[SpanContext] -> ShowS
SpanContext -> String
(Int -> SpanContext -> ShowS)
-> (SpanContext -> String)
-> ([SpanContext] -> ShowS)
-> Show SpanContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpanContext] -> ShowS
$cshowList :: [SpanContext] -> ShowS
show :: SpanContext -> String
$cshow :: SpanContext -> String
showsPrec :: Int -> SpanContext -> ShowS
$cshowsPrec :: Int -> SpanContext -> ShowS
Show, SpanContext -> SpanContext -> Bool
(SpanContext -> SpanContext -> Bool)
-> (SpanContext -> SpanContext -> Bool) -> Eq SpanContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpanContext -> SpanContext -> Bool
$c/= :: SpanContext -> SpanContext -> Bool
== :: SpanContext -> SpanContext -> Bool
$c== :: SpanContext -> SpanContext -> Bool
Eq, Eq SpanContext
Eq SpanContext
-> (SpanContext -> SpanContext -> Ordering)
-> (SpanContext -> SpanContext -> Bool)
-> (SpanContext -> SpanContext -> Bool)
-> (SpanContext -> SpanContext -> Bool)
-> (SpanContext -> SpanContext -> Bool)
-> (SpanContext -> SpanContext -> SpanContext)
-> (SpanContext -> SpanContext -> SpanContext)
-> Ord SpanContext
SpanContext -> SpanContext -> Bool
SpanContext -> SpanContext -> Ordering
SpanContext -> SpanContext -> SpanContext
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SpanContext -> SpanContext -> SpanContext
$cmin :: SpanContext -> SpanContext -> SpanContext
max :: SpanContext -> SpanContext -> SpanContext
$cmax :: SpanContext -> SpanContext -> SpanContext
>= :: SpanContext -> SpanContext -> Bool
$c>= :: SpanContext -> SpanContext -> Bool
> :: SpanContext -> SpanContext -> Bool
$c> :: SpanContext -> SpanContext -> Bool
<= :: SpanContext -> SpanContext -> Bool
$c<= :: SpanContext -> SpanContext -> Bool
< :: SpanContext -> SpanContext -> Bool
$c< :: SpanContext -> SpanContext -> Bool
compare :: SpanContext -> SpanContext -> Ordering
$ccompare :: SpanContext -> SpanContext -> Ordering
$cp1Ord :: Eq SpanContext
Ord, (forall x. SpanContext -> Rep SpanContext x)
-> (forall x. Rep SpanContext x -> SpanContext)
-> Generic SpanContext
forall x. Rep SpanContext x -> SpanContext
forall x. SpanContext -> Rep SpanContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SpanContext x -> SpanContext
$cfrom :: forall x. SpanContext -> Rep SpanContext x
Generic)