{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.XRay.Types.Trace
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.XRay.Types.Trace where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.XRay.Types.Segment

-- | A collection of segment documents with matching trace IDs.
--
-- /See:/ 'newTrace' smart constructor.
data Trace = Trace'
  { -- | LimitExceeded is set to true when the trace has exceeded one of the
    -- defined quotas. For more information about quotas, see
    -- <https://docs.aws.amazon.com/general/latest/gr/xray.html Amazon Web Services X-Ray endpoints and quotas>.
    Trace -> Maybe Bool
limitExceeded :: Prelude.Maybe Prelude.Bool,
    -- | The unique identifier for the request that generated the trace\'s
    -- segments and subsegments.
    Trace -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | Segment documents for the segments and subsegments that comprise the
    -- trace.
    Trace -> Maybe [Segment]
segments :: Prelude.Maybe [Segment],
    -- | The length of time in seconds between the start time of the root segment
    -- and the end time of the last segment that completed.
    Trace -> Maybe Double
duration :: Prelude.Maybe Prelude.Double
  }
  deriving (Trace -> Trace -> Bool
(Trace -> Trace -> Bool) -> (Trace -> Trace -> Bool) -> Eq Trace
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Trace -> Trace -> Bool
$c/= :: Trace -> Trace -> Bool
== :: Trace -> Trace -> Bool
$c== :: Trace -> Trace -> Bool
Prelude.Eq, ReadPrec [Trace]
ReadPrec Trace
Int -> ReadS Trace
ReadS [Trace]
(Int -> ReadS Trace)
-> ReadS [Trace]
-> ReadPrec Trace
-> ReadPrec [Trace]
-> Read Trace
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Trace]
$creadListPrec :: ReadPrec [Trace]
readPrec :: ReadPrec Trace
$creadPrec :: ReadPrec Trace
readList :: ReadS [Trace]
$creadList :: ReadS [Trace]
readsPrec :: Int -> ReadS Trace
$creadsPrec :: Int -> ReadS Trace
Prelude.Read, Int -> Trace -> ShowS
[Trace] -> ShowS
Trace -> String
(Int -> Trace -> ShowS)
-> (Trace -> String) -> ([Trace] -> ShowS) -> Show Trace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Trace] -> ShowS
$cshowList :: [Trace] -> ShowS
show :: Trace -> String
$cshow :: Trace -> String
showsPrec :: Int -> Trace -> ShowS
$cshowsPrec :: Int -> Trace -> ShowS
Prelude.Show, (forall x. Trace -> Rep Trace x)
-> (forall x. Rep Trace x -> Trace) -> Generic Trace
forall x. Rep Trace x -> Trace
forall x. Trace -> Rep Trace x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Trace x -> Trace
$cfrom :: forall x. Trace -> Rep Trace x
Prelude.Generic)

-- |
-- Create a value of 'Trace' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'limitExceeded', 'trace_limitExceeded' - LimitExceeded is set to true when the trace has exceeded one of the
-- defined quotas. For more information about quotas, see
-- <https://docs.aws.amazon.com/general/latest/gr/xray.html Amazon Web Services X-Ray endpoints and quotas>.
--
-- 'id', 'trace_id' - The unique identifier for the request that generated the trace\'s
-- segments and subsegments.
--
-- 'segments', 'trace_segments' - Segment documents for the segments and subsegments that comprise the
-- trace.
--
-- 'duration', 'trace_duration' - The length of time in seconds between the start time of the root segment
-- and the end time of the last segment that completed.
newTrace ::
  Trace
newTrace :: Trace
newTrace =
  Trace' :: Maybe Bool
-> Maybe Text -> Maybe [Segment] -> Maybe Double -> Trace
Trace'
    { $sel:limitExceeded:Trace' :: Maybe Bool
limitExceeded = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Trace' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:segments:Trace' :: Maybe [Segment]
segments = Maybe [Segment]
forall a. Maybe a
Prelude.Nothing,
      $sel:duration:Trace' :: Maybe Double
duration = Maybe Double
forall a. Maybe a
Prelude.Nothing
    }

-- | LimitExceeded is set to true when the trace has exceeded one of the
-- defined quotas. For more information about quotas, see
-- <https://docs.aws.amazon.com/general/latest/gr/xray.html Amazon Web Services X-Ray endpoints and quotas>.
trace_limitExceeded :: Lens.Lens' Trace (Prelude.Maybe Prelude.Bool)
trace_limitExceeded :: (Maybe Bool -> f (Maybe Bool)) -> Trace -> f Trace
trace_limitExceeded = (Trace -> Maybe Bool)
-> (Trace -> Maybe Bool -> Trace)
-> Lens Trace Trace (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Trace' {Maybe Bool
limitExceeded :: Maybe Bool
$sel:limitExceeded:Trace' :: Trace -> Maybe Bool
limitExceeded} -> Maybe Bool
limitExceeded) (\s :: Trace
s@Trace' {} Maybe Bool
a -> Trace
s {$sel:limitExceeded:Trace' :: Maybe Bool
limitExceeded = Maybe Bool
a} :: Trace)

-- | The unique identifier for the request that generated the trace\'s
-- segments and subsegments.
trace_id :: Lens.Lens' Trace (Prelude.Maybe Prelude.Text)
trace_id :: (Maybe Text -> f (Maybe Text)) -> Trace -> f Trace
trace_id = (Trace -> Maybe Text)
-> (Trace -> Maybe Text -> Trace)
-> Lens Trace Trace (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Trace' {Maybe Text
id :: Maybe Text
$sel:id:Trace' :: Trace -> Maybe Text
id} -> Maybe Text
id) (\s :: Trace
s@Trace' {} Maybe Text
a -> Trace
s {$sel:id:Trace' :: Maybe Text
id = Maybe Text
a} :: Trace)

-- | Segment documents for the segments and subsegments that comprise the
-- trace.
trace_segments :: Lens.Lens' Trace (Prelude.Maybe [Segment])
trace_segments :: (Maybe [Segment] -> f (Maybe [Segment])) -> Trace -> f Trace
trace_segments = (Trace -> Maybe [Segment])
-> (Trace -> Maybe [Segment] -> Trace)
-> Lens Trace Trace (Maybe [Segment]) (Maybe [Segment])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Trace' {Maybe [Segment]
segments :: Maybe [Segment]
$sel:segments:Trace' :: Trace -> Maybe [Segment]
segments} -> Maybe [Segment]
segments) (\s :: Trace
s@Trace' {} Maybe [Segment]
a -> Trace
s {$sel:segments:Trace' :: Maybe [Segment]
segments = Maybe [Segment]
a} :: Trace) ((Maybe [Segment] -> f (Maybe [Segment])) -> Trace -> f Trace)
-> ((Maybe [Segment] -> f (Maybe [Segment]))
    -> Maybe [Segment] -> f (Maybe [Segment]))
-> (Maybe [Segment] -> f (Maybe [Segment]))
-> Trace
-> f Trace
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Segment] [Segment] [Segment] [Segment]
-> Iso
     (Maybe [Segment])
     (Maybe [Segment])
     (Maybe [Segment])
     (Maybe [Segment])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Segment] [Segment] [Segment] [Segment]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The length of time in seconds between the start time of the root segment
-- and the end time of the last segment that completed.
trace_duration :: Lens.Lens' Trace (Prelude.Maybe Prelude.Double)
trace_duration :: (Maybe Double -> f (Maybe Double)) -> Trace -> f Trace
trace_duration = (Trace -> Maybe Double)
-> (Trace -> Maybe Double -> Trace)
-> Lens Trace Trace (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Trace' {Maybe Double
duration :: Maybe Double
$sel:duration:Trace' :: Trace -> Maybe Double
duration} -> Maybe Double
duration) (\s :: Trace
s@Trace' {} Maybe Double
a -> Trace
s {$sel:duration:Trace' :: Maybe Double
duration = Maybe Double
a} :: Trace)

instance Core.FromJSON Trace where
  parseJSON :: Value -> Parser Trace
parseJSON =
    String -> (Object -> Parser Trace) -> Value -> Parser Trace
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Trace"
      ( \Object
x ->
          Maybe Bool
-> Maybe Text -> Maybe [Segment] -> Maybe Double -> Trace
Trace'
            (Maybe Bool
 -> Maybe Text -> Maybe [Segment] -> Maybe Double -> Trace)
-> Parser (Maybe Bool)
-> Parser (Maybe Text -> Maybe [Segment] -> Maybe Double -> Trace)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LimitExceeded")
            Parser (Maybe Text -> Maybe [Segment] -> Maybe Double -> Trace)
-> Parser (Maybe Text)
-> Parser (Maybe [Segment] -> Maybe Double -> Trace)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Id")
            Parser (Maybe [Segment] -> Maybe Double -> Trace)
-> Parser (Maybe [Segment]) -> Parser (Maybe Double -> Trace)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Segment]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Segments" Parser (Maybe (Maybe [Segment]))
-> Maybe [Segment] -> Parser (Maybe [Segment])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Segment]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Double -> Trace)
-> Parser (Maybe Double) -> Parser Trace
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Duration")
      )

instance Prelude.Hashable Trace

instance Prelude.NFData Trace