{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase                 #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE PatternSynonyms            #-}
{-# LANGUAGE RankNTypes                 #-}
{-# LANGUAGE StrictData                 #-}
{-# LANGUAGE TupleSections              #-}
{-# LANGUAGE ViewPatterns               #-}

module OpenTracing.Tags
    ( Tags(fromTags)
    , Tag
    , TagVal(..)
    , setTag
    , getTag
    , getTagReify

    -- * Standard span tags.
    -- | Refer to the [OpenTracing spec](https://github.com/opentracing/specification/blob/master/semantic_conventions.md#span-tags-table)
    -- for more info.
    , pattern ComponentKey
    , pattern DbInstanceKey
    , pattern DbStatementKey
    , pattern DbTypeKey
    , pattern DbUserKey
    , pattern ErrorKey
    , pattern HttpMethodKey
    , pattern HttpStatusCodeKey
    , pattern HttpUrlKey
    , pattern MessageBusDestinationKey
    , pattern PeerAddressKey
    , pattern PeerHostnameKey
    , pattern PeerIPv4Key
    , pattern PeerIPv6Key
    , pattern PeerPortKey
    , pattern PeerServiceKey
    , pattern SamplingPriorityKey
    , pattern SpanKindKey

    , pattern Component
    , pattern DbInstance
    , pattern DbStatement
    , pattern DbType
    , pattern DbUser
    , pattern Error
    , pattern HttpMethod
    , pattern HttpStatusCode
    , pattern HttpUrl
    , pattern MessageBusDestination
    , pattern PeerAddress
    , pattern PeerHostname
    , pattern PeerIPv4
    , pattern PeerIPv6
    , pattern PeerPort
    , pattern PeerService
    , pattern SamplingPriority
    , pattern SpanKind

    , _Component
    , _DbInstance
    , _DbStatement
    , _DbType
    , _DbUser
    , _Error
    , _HttpMethod
    , _HttpStatusCode
    , _HttpUrl
    , _MessageBusDestination
    , _PeerAddress
    , _PeerHostname
    , _PeerIPv4
    , _PeerIPv6
    , _PeerPort
    , _PeerService
    , _SamplingPriority
    , _SpanKind

    , SpanKinds(..)
    , spanKindLabel
    )
where

import           Control.Lens
import           Data.Aeson                  (ToJSON (..))
import           Data.Aeson.Encoding
import qualified Data.ByteString.Base64.Lazy as B64
import qualified Data.ByteString.Lazy        as Lazy
import           Data.HashMap.Strict         (HashMap)
import qualified Data.HashMap.Strict         as HashMap
import           Data.Int                    (Int64)
import           Data.Monoid                 (First)
import           Data.String                 (IsString)
import           Data.Text                   (Text)
import qualified Data.Text                   as Text
import           Data.Text.Encoding          (decodeUtf8, encodeUtf8)
import qualified Data.Text.Lazy.Encoding     as Lazy
import           Data.Word                   (Word8)
import           Network.HTTP.Types
import           OpenTracing.Types
import           Text.Read                   (readMaybe)

-- | Tags are structured data associated with a `OpenTracing.Span.Span`. They can give
-- a more complete picture of what a Span is doing than the operation alone. Tags
-- apply to the entire timerange of a Span. Use `OpenTracing.Log.LogField` for
-- events that refer to particular timestamp.
newtype Tags = Tags { Tags -> HashMap Text TagVal
fromTags :: HashMap Text TagVal }
    deriving (Tags -> Tags -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tags -> Tags -> Bool
$c/= :: Tags -> Tags -> Bool
== :: Tags -> Tags -> Bool
$c== :: Tags -> Tags -> Bool
Eq, Int -> Tags -> ShowS
[Tags] -> ShowS
Tags -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tags] -> ShowS
$cshowList :: [Tags] -> ShowS
show :: Tags -> String
$cshow :: Tags -> String
showsPrec :: Int -> Tags -> ShowS
$cshowsPrec :: Int -> Tags -> ShowS
Show, NonEmpty Tags -> Tags
Tags -> Tags -> Tags
forall b. Integral b => b -> Tags -> Tags
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> Tags -> Tags
$cstimes :: forall b. Integral b => b -> Tags -> Tags
sconcat :: NonEmpty Tags -> Tags
$csconcat :: NonEmpty Tags -> Tags
<> :: Tags -> Tags -> Tags
$c<> :: Tags -> Tags -> Tags
Semigroup, Semigroup Tags
Tags
[Tags] -> Tags
Tags -> Tags -> Tags
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [Tags] -> Tags
$cmconcat :: [Tags] -> Tags
mappend :: Tags -> Tags -> Tags
$cmappend :: Tags -> Tags -> Tags
mempty :: Tags
$cmempty :: Tags
Monoid, [Tags] -> Encoding
[Tags] -> Value
Tags -> Bool
Tags -> Encoding
Tags -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
omitField :: Tags -> Bool
$comitField :: Tags -> Bool
toEncodingList :: [Tags] -> Encoding
$ctoEncodingList :: [Tags] -> Encoding
toJSONList :: [Tags] -> Value
$ctoJSONList :: [Tags] -> Value
toEncoding :: Tags -> Encoding
$ctoEncoding :: Tags -> Encoding
toJSON :: Tags -> Value
$ctoJSON :: Tags -> Value
ToJSON)

-- | A Tag is a key:value pair
type Tag = (Text, TagVal)

data TagVal
    = BoolT   Bool
    | StringT Text
    | IntT    Int64
    | DoubleT Double
    | BinaryT Lazy.ByteString
    deriving (TagVal -> TagVal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagVal -> TagVal -> Bool
$c/= :: TagVal -> TagVal -> Bool
== :: TagVal -> TagVal -> Bool
$c== :: TagVal -> TagVal -> Bool
Eq, Int -> TagVal -> ShowS
[TagVal] -> ShowS
TagVal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagVal] -> ShowS
$cshowList :: [TagVal] -> ShowS
show :: TagVal -> String
$cshow :: TagVal -> String
showsPrec :: Int -> TagVal -> ShowS
$cshowsPrec :: Int -> TagVal -> ShowS
Show)

instance ToJSON TagVal where
    toJSON :: TagVal -> Value
toJSON (BoolT   Bool
x) = forall a. ToJSON a => a -> Value
toJSON Bool
x
    toJSON (StringT Text
x) = forall a. ToJSON a => a -> Value
toJSON Text
x
    toJSON (IntT    Int64
x) = forall a. ToJSON a => a -> Value
toJSON Int64
x
    toJSON (DoubleT Double
x) = forall a. ToJSON a => a -> Value
toJSON Double
x
    toJSON (BinaryT ByteString
x) = forall a. ToJSON a => a -> Value
toJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Lazy.decodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B64.encode forall a b. (a -> b) -> a -> b
$ ByteString
x

    toEncoding :: TagVal -> Encoding
toEncoding (BoolT   Bool
x) = forall a. ToJSON a => a -> Encoding
toEncoding Bool
x
    toEncoding (StringT Text
x) = forall a. ToJSON a => a -> Encoding
toEncoding Text
x
    toEncoding (IntT    Int64
x) = forall a. ToJSON a => a -> Encoding
toEncoding Int64
x
    toEncoding (DoubleT Double
x) = forall a. ToJSON a => a -> Encoding
toEncoding Double
x
    toEncoding (BinaryT ByteString
x) = forall a. ToJSON a => a -> Encoding
toEncoding forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Lazy.decodeUtf8 forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B64.encode forall a b. (a -> b) -> a -> b
$ ByteString
x

setTag :: Tag -> Tags -> Tags
setTag :: Tag -> Tags -> Tags
setTag (Text
k,TagVal
v) = HashMap Text TagVal -> Tags
Tags forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HashMap.insert Text
k TagVal
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tags -> HashMap Text TagVal
fromTags

getTag :: Text -> Tags -> Maybe TagVal
getTag :: Text -> Tags -> Maybe TagVal
getTag Text
k = forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup Text
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tags -> HashMap Text TagVal
fromTags

-- | Get a tag and attempt to convert it from a serialized format
getTagReify :: Getting (First b) Tag b -> Text -> Tags -> Maybe b
getTagReify :: forall b. Getting (First b) Tag b -> Text -> Tags -> Maybe b
getTagReify Getting (First b) Tag b
p Text
k Tags
ts = Text -> Tags -> Maybe TagVal
getTag Text
k Tags
ts forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall s (m :: * -> *) a.
MonadReader s m =>
Getting (First a) s a -> m (Maybe a)
preview Getting (First b) Tag b
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text
k,)

pattern
      ComponentKey
    , DbInstanceKey
    , DbStatementKey
    , DbTypeKey
    , DbUserKey
    , ErrorKey
    , HttpMethodKey
    , HttpStatusCodeKey
    , HttpUrlKey
    , MessageBusDestinationKey
    , PeerAddressKey
    , PeerHostnameKey
    , PeerIPv4Key
    , PeerIPv6Key
    , PeerPortKey
    , PeerServiceKey
    , SamplingPriorityKey
    , SpanKindKey
    :: forall a. (Eq a, IsString a) => a

pattern $bComponentKey :: forall a. (Eq a, IsString a) => a
$mComponentKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
ComponentKey             = "component"
pattern $bDbInstanceKey :: forall a. (Eq a, IsString a) => a
$mDbInstanceKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
DbInstanceKey            = "db.instance"
pattern $bDbStatementKey :: forall a. (Eq a, IsString a) => a
$mDbStatementKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
DbStatementKey           = "db.statement"
pattern $bDbTypeKey :: forall a. (Eq a, IsString a) => a
$mDbTypeKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
DbTypeKey                = "db.type"
pattern $bDbUserKey :: forall a. (Eq a, IsString a) => a
$mDbUserKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
DbUserKey                = "db.user"
pattern $bErrorKey :: forall a. (Eq a, IsString a) => a
$mErrorKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
ErrorKey                 = "error"
pattern $bHttpMethodKey :: forall a. (Eq a, IsString a) => a
$mHttpMethodKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
HttpMethodKey            = "http.method"
pattern $bHttpStatusCodeKey :: forall a. (Eq a, IsString a) => a
$mHttpStatusCodeKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
HttpStatusCodeKey        = "http.status_code"
pattern $bHttpUrlKey :: forall a. (Eq a, IsString a) => a
$mHttpUrlKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
HttpUrlKey               = "http.url"
pattern $bMessageBusDestinationKey :: forall a. (Eq a, IsString a) => a
$mMessageBusDestinationKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
MessageBusDestinationKey = "message_bus.destination"
pattern $bPeerAddressKey :: forall a. (Eq a, IsString a) => a
$mPeerAddressKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
PeerAddressKey           = "peer.address"
pattern $bPeerHostnameKey :: forall a. (Eq a, IsString a) => a
$mPeerHostnameKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
PeerHostnameKey          = "peer.hostname"
pattern $bPeerIPv4Key :: forall a. (Eq a, IsString a) => a
$mPeerIPv4Key :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
PeerIPv4Key              = "peer.ipv4"
pattern $bPeerIPv6Key :: forall a. (Eq a, IsString a) => a
$mPeerIPv6Key :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
PeerIPv6Key              = "peer.ipv6"
pattern $bPeerPortKey :: forall a. (Eq a, IsString a) => a
$mPeerPortKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
PeerPortKey              = "peer.port"
pattern $bPeerServiceKey :: forall a. (Eq a, IsString a) => a
$mPeerServiceKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
PeerServiceKey           = "peer.service"
pattern $bSamplingPriorityKey :: forall a. (Eq a, IsString a) => a
$mSamplingPriorityKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
SamplingPriorityKey      = "sampling.priority"
pattern $bSpanKindKey :: forall a. (Eq a, IsString a) => a
$mSpanKindKey :: forall {r} {a}.
(Eq a, IsString a) =>
a -> ((# #) -> r) -> ((# #) -> r) -> r
SpanKindKey              = "span.kind"

_Component :: Prism' Tag Text
_Component :: Prism' Tag Text
_Component = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
ComponentKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
ComponentKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern Component :: Text -> Tag
pattern $bComponent :: Text -> Tag
$mComponent :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
Component v <- (preview _Component -> Just v) where
    Component Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_Component Text
v

_DbInstance :: Prism' Tag Text
_DbInstance :: Prism' Tag Text
_DbInstance = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
DbInstanceKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
DbInstanceKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern DbInstance :: Text -> Tag
pattern $bDbInstance :: Text -> Tag
$mDbInstance :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
DbInstance v <- (preview _DbInstance -> Just v) where
    DbInstance Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_DbInstance Text
v

_DbStatement :: Prism' Tag Text
_DbStatement :: Prism' Tag Text
_DbStatement = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
DbStatementKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
DbStatementKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern DbStatement :: Text -> Tag
pattern $bDbStatement :: Text -> Tag
$mDbStatement :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
DbStatement v <- (preview _DbStatement -> Just v) where
    DbStatement Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_DbStatement Text
v

_DbType :: Prism' Tag Text
_DbType :: Prism' Tag Text
_DbType = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
DbTypeKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
DbTypeKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern DbType :: Text -> Tag
pattern $bDbType :: Text -> Tag
$mDbType :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
DbType v <- (preview _DbType -> Just v) where
    DbType Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_DbType Text
v

_DbUser :: Prism' Tag Text
_DbUser :: Prism' Tag Text
_DbUser = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
DbUserKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
DbUserKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern DbUser :: Text -> Tag
pattern $bDbUser :: Text -> Tag
$mDbUser :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
DbUser v <- (preview _DbUser -> Just v) where
    DbUser Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_DbUser Text
v

_Error :: Prism' Tag Bool
_Error :: Prism' Tag Bool
_Error = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
ErrorKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> TagVal
BoolT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, BoolT Bool
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
ErrorKey -> forall a. a -> Maybe a
Just Bool
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern Error :: Bool -> Tag
pattern $bError :: Bool -> Tag
$mError :: forall {r}. Tag -> (Bool -> r) -> ((# #) -> r) -> r
Error v <- (preview _Error -> Just v) where
    Error Bool
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Bool
_Error Bool
v

_HttpUrl :: Prism' Tag Text
_HttpUrl :: Prism' Tag Text
_HttpUrl = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
HttpUrlKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
HttpUrlKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern HttpUrl :: Text -> Tag
pattern $bHttpUrl :: Text -> Tag
$mHttpUrl :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
HttpUrl v <- (preview _HttpUrl -> Just v) where
    HttpUrl Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_HttpUrl Text
v

_MessageBusDestination :: Prism' Tag Text
_MessageBusDestination :: Prism' Tag Text
_MessageBusDestination = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
MessageBusDestinationKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
MessageBusDestinationKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern MessageBusDestination :: Text -> Tag
pattern $bMessageBusDestination :: Text -> Tag
$mMessageBusDestination :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
MessageBusDestination v <- (preview _MessageBusDestination -> Just v) where
    MessageBusDestination Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_MessageBusDestination Text
v

_PeerAddress :: Prism' Tag Text
_PeerAddress :: Prism' Tag Text
_PeerAddress = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
PeerAddressKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
PeerAddressKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern PeerAddress :: Text -> Tag
pattern $bPeerAddress :: Text -> Tag
$mPeerAddress :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
PeerAddress v <- (preview _PeerAddress -> Just v) where
    PeerAddress Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_PeerAddress Text
v

_PeerHostname :: Prism' Tag Text
_PeerHostname :: Prism' Tag Text
_PeerHostname = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
PeerHostnameKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
PeerHostnameKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern PeerHostname :: Text -> Tag
pattern $bPeerHostname :: Text -> Tag
$mPeerHostname :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
PeerHostname v <- (preview _PeerHostname -> Just v) where
    PeerHostname Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_PeerHostname Text
v

_PeerService :: Prism' Tag Text
_PeerService :: Prism' Tag Text
_PeerService = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
PeerServiceKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
v) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
PeerServiceKey -> forall a. a -> Maybe a
Just Text
v
    Tag
_ -> forall a. Maybe a
Nothing

pattern PeerService :: Text -> Tag
pattern $bPeerService :: Text -> Tag
$mPeerService :: forall {r}. Tag -> (Text -> r) -> ((# #) -> r) -> r
PeerService v <- (preview _PeerService -> Just v) where
    PeerService Text
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Text
_PeerService Text
v

_HttpMethod :: Prism' Tag Method
_HttpMethod :: Prism' Tag Method
_HttpMethod = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
HttpMethodKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT forall b c a. (b -> c) -> (a -> b) -> a -> c
. Method -> Text
decodeUtf8) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT (Text -> Method
encodeUtf8 -> Method
x)) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
HttpMethodKey ->
        forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a b. a -> b -> a
const forall a. Maybe a
Nothing) (forall a b. a -> b -> a
const (forall a. a -> Maybe a
Just Method
x)) forall a b. (a -> b) -> a -> b
$ Method -> Either Method StdMethod
parseMethod Method
x
    Tag
_ -> forall a. Maybe a
Nothing

pattern HttpMethod :: Method -> Tag
pattern $bHttpMethod :: Method -> Tag
$mHttpMethod :: forall {r}. Tag -> (Method -> r) -> ((# #) -> r) -> r
HttpMethod v <- (preview _HttpMethod -> Just v) where
    HttpMethod Method
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Method
_HttpMethod Method
v

_HttpStatusCode :: Prism' Tag Status
_HttpStatusCode :: Prism' Tag Status
_HttpStatusCode = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
HttpStatusCodeKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> TagVal
IntT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. Status -> Int
statusCode) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, IntT Int64
x) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
HttpStatusCodeKey -> forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ Int64
x
    Tag
_ -> forall a. Maybe a
Nothing

pattern HttpStatusCode :: Status -> Tag
pattern $bHttpStatusCode :: Status -> Tag
$mHttpStatusCode :: forall {r}. Tag -> (Status -> r) -> ((# #) -> r) -> r
HttpStatusCode v <- (preview _HttpStatusCode -> Just v) where
    HttpStatusCode Status
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Status
_HttpStatusCode Status
v

_PeerIPv4 :: Prism' Tag IPv4
_PeerIPv4 :: Prism' Tag IPv4
_PeerIPv4 = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
PeerIPv4Key,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
x) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
PeerIPv4Key -> forall a. Read a => String -> Maybe a
readMaybe (Text -> String
Text.unpack Text
x)
    Tag
_ -> forall a. Maybe a
Nothing

pattern PeerIPv4 :: IPv4 -> Tag
pattern $bPeerIPv4 :: IPv4 -> Tag
$mPeerIPv4 :: forall {r}. Tag -> (IPv4 -> r) -> ((# #) -> r) -> r
PeerIPv4 v <- (preview _PeerIPv4 -> Just v) where
    PeerIPv4 IPv4
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag IPv4
_PeerIPv4 IPv4
v

_PeerIPv6 :: Prism' Tag IPv6
_PeerIPv6 :: Prism' Tag IPv6
_PeerIPv6 = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
PeerIPv6Key,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
Text.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
x) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
PeerIPv6Key -> forall a. Read a => String -> Maybe a
readMaybe (Text -> String
Text.unpack Text
x)
    Tag
_ -> forall a. Maybe a
Nothing

pattern PeerIPv6 :: IPv6 -> Tag
pattern $bPeerIPv6 :: IPv6 -> Tag
$mPeerIPv6 :: forall {r}. Tag -> (IPv6 -> r) -> ((# #) -> r) -> r
PeerIPv6 v <- (preview _PeerIPv6 -> Just v) where
    PeerIPv6 IPv6
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag IPv6
_PeerIPv6 IPv6
v

_PeerPort :: Prism' Tag Port
_PeerPort :: Prism' Tag Port
_PeerPort = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
PeerPortKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> TagVal
IntT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. Port -> Word16
fromPort) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, IntT Int64
x) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
PeerPortKey -> forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ Int64
x
    Tag
_ -> forall a. Maybe a
Nothing

pattern PeerPort :: Port -> Tag
pattern $bPeerPort :: Port -> Tag
$mPeerPort :: forall {r}. Tag -> (Port -> r) -> ((# #) -> r) -> r
PeerPort v <- (preview _PeerPort -> Just v) where
    PeerPort Port
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Port
_PeerPort Port
v

_SamplingPriority :: Prism' Tag Word8
_SamplingPriority :: Prism' Tag Word8
_SamplingPriority = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
SamplingPriorityKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> TagVal
IntT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, IntT Int64
x) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
SamplingPriorityKey -> forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ Int64
x
    Tag
_ -> forall a. Maybe a
Nothing

pattern SamplingPriority :: Word8 -> Tag
pattern $bSamplingPriority :: Word8 -> Tag
$mSamplingPriority :: forall {r}. Tag -> (Word8 -> r) -> ((# #) -> r) -> r
SamplingPriority v <- (preview _SamplingPriority -> Just v) where
    SamplingPriority Word8
v = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag Word8
_SamplingPriority Word8
v

_SpanKind :: Prism' Tag SpanKinds
_SpanKind :: Prism' Tag SpanKinds
_SpanKind = forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ((forall a. (Eq a, IsString a) => a
SpanKindKey,) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TagVal
StringT forall b c a. (b -> c) -> (a -> b) -> a -> c
. SpanKinds -> Text
spanKindLabel) forall a b. (a -> b) -> a -> b
$ \case
    (Text
k, StringT Text
x) | Text
k forall a. Eq a => a -> a -> Bool
== forall a. (Eq a, IsString a) => a
SpanKindKey -> Text -> Maybe SpanKinds
fromSpanKindLabel Text
x
    Tag
_ -> forall a. Maybe a
Nothing

pattern SpanKind :: SpanKinds -> Tag
pattern $bSpanKind :: SpanKinds -> Tag
$mSpanKind :: forall {r}. Tag -> (SpanKinds -> r) -> ((# #) -> r) -> r
SpanKind v <- (preview _SpanKind -> Just v) where
    SpanKind = forall b (m :: * -> *) t. MonadReader b m => AReview t b -> m t
review Prism' Tag SpanKinds
_SpanKind

data SpanKinds
    = RPCClient
    | RPCServer
    | Producer
    | Consumer
    deriving (SpanKinds -> SpanKinds -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpanKinds -> SpanKinds -> Bool
$c/= :: SpanKinds -> SpanKinds -> Bool
== :: SpanKinds -> SpanKinds -> Bool
$c== :: SpanKinds -> SpanKinds -> Bool
Eq, Int -> SpanKinds -> ShowS
[SpanKinds] -> ShowS
SpanKinds -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpanKinds] -> ShowS
$cshowList :: [SpanKinds] -> ShowS
show :: SpanKinds -> String
$cshow :: SpanKinds -> String
showsPrec :: Int -> SpanKinds -> ShowS
$cshowsPrec :: Int -> SpanKinds -> ShowS
Show, Eq SpanKinds
SpanKinds -> SpanKinds -> Bool
SpanKinds -> SpanKinds -> Ordering
SpanKinds -> SpanKinds -> SpanKinds
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 :: SpanKinds -> SpanKinds -> SpanKinds
$cmin :: SpanKinds -> SpanKinds -> SpanKinds
max :: SpanKinds -> SpanKinds -> SpanKinds
$cmax :: SpanKinds -> SpanKinds -> SpanKinds
>= :: SpanKinds -> SpanKinds -> Bool
$c>= :: SpanKinds -> SpanKinds -> Bool
> :: SpanKinds -> SpanKinds -> Bool
$c> :: SpanKinds -> SpanKinds -> Bool
<= :: SpanKinds -> SpanKinds -> Bool
$c<= :: SpanKinds -> SpanKinds -> Bool
< :: SpanKinds -> SpanKinds -> Bool
$c< :: SpanKinds -> SpanKinds -> Bool
compare :: SpanKinds -> SpanKinds -> Ordering
$ccompare :: SpanKinds -> SpanKinds -> Ordering
Ord)

spanKindLabel :: SpanKinds -> Text
spanKindLabel :: SpanKinds -> Text
spanKindLabel SpanKinds
RPCClient = Text
"CLIENT"
spanKindLabel SpanKinds
RPCServer = Text
"SERVER"
spanKindLabel SpanKinds
Producer  = Text
"PRODUCER"
spanKindLabel SpanKinds
Consumer  = Text
"CONSUMER"

fromSpanKindLabel :: Text -> Maybe SpanKinds
fromSpanKindLabel :: Text -> Maybe SpanKinds
fromSpanKindLabel Text
"CLIENT"   = forall a. a -> Maybe a
Just SpanKinds
RPCClient
fromSpanKindLabel Text
"SERVER"   = forall a. a -> Maybe a
Just SpanKinds
RPCServer
fromSpanKindLabel Text
"PRODUCER" = forall a. a -> Maybe a
Just SpanKinds
Producer
fromSpanKindLabel Text
"CONSUMER" = forall a. a -> Maybe a
Just SpanKinds
Consumer
fromSpanKindLabel Text
_          = forall a. Maybe a
Nothing

instance ToJSON SpanKinds where
    toJSON :: SpanKinds -> Value
toJSON     = forall a. ToJSON a => a -> Value
toJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. SpanKinds -> Text
spanKindLabel
    toEncoding :: SpanKinds -> Encoding
toEncoding = forall a. Text -> Encoding' a
text   forall b c a. (b -> c) -> (a -> b) -> a -> c
. SpanKinds -> Text
spanKindLabel