{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.XRay.Types.Trace where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | 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,
    -- | The unique identifier for the request that generated the trace\'s
    -- segments and subsegments.
    Trace -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | LimitExceeded is set to true when the trace has exceeded the
    -- @Trace document size@ limit. For more information about this limit and
    -- other X-Ray limits and 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,
    -- | Segment documents for the segments and subsegments that comprise the
    -- trace.
    Trace -> Maybe [Segment]
segments :: Prelude.Maybe [Segment]
  }
  deriving (Trace -> Trace -> Bool
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]
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
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. 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:
--
-- '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.
--
-- 'id', 'trace_id' - The unique identifier for the request that generated the trace\'s
-- segments and subsegments.
--
-- 'limitExceeded', 'trace_limitExceeded' - LimitExceeded is set to true when the trace has exceeded the
-- @Trace document size@ limit. For more information about this limit and
-- other X-Ray limits and quotas, see
-- <https://docs.aws.amazon.com/general/latest/gr/xray.html Amazon Web Services X-Ray endpoints and quotas>.
--
-- 'segments', 'trace_segments' - Segment documents for the segments and subsegments that comprise the
-- trace.
newTrace ::
  Trace
newTrace :: Trace
newTrace =
  Trace'
    { $sel:duration:Trace' :: Maybe Double
duration = forall a. Maybe a
Prelude.Nothing,
      $sel:id:Trace' :: Maybe Text
id = forall a. Maybe a
Prelude.Nothing,
      $sel:limitExceeded:Trace' :: Maybe Bool
limitExceeded = forall a. Maybe a
Prelude.Nothing,
      $sel:segments:Trace' :: Maybe [Segment]
segments = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' Trace (Maybe Double)
trace_duration = 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)

-- | 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 :: Lens' Trace (Maybe Text)
trace_id = 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)

-- | LimitExceeded is set to true when the trace has exceeded the
-- @Trace document size@ limit. For more information about this limit and
-- other X-Ray limits and 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 :: Lens' Trace (Maybe Bool)
trace_limitExceeded = 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)

-- | Segment documents for the segments and subsegments that comprise the
-- trace.
trace_segments :: Lens.Lens' Trace (Prelude.Maybe [Segment])
trace_segments :: Lens' Trace (Maybe [Segment])
trace_segments = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable Trace where
  hashWithSalt :: Int -> Trace -> Int
hashWithSalt Int
_salt Trace' {Maybe Bool
Maybe Double
Maybe [Segment]
Maybe Text
segments :: Maybe [Segment]
limitExceeded :: Maybe Bool
id :: Maybe Text
duration :: Maybe Double
$sel:segments:Trace' :: Trace -> Maybe [Segment]
$sel:limitExceeded:Trace' :: Trace -> Maybe Bool
$sel:id:Trace' :: Trace -> Maybe Text
$sel:duration:Trace' :: Trace -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
duration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
limitExceeded
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Segment]
segments

instance Prelude.NFData Trace where
  rnf :: Trace -> ()
rnf Trace' {Maybe Bool
Maybe Double
Maybe [Segment]
Maybe Text
segments :: Maybe [Segment]
limitExceeded :: Maybe Bool
id :: Maybe Text
duration :: Maybe Double
$sel:segments:Trace' :: Trace -> Maybe [Segment]
$sel:limitExceeded:Trace' :: Trace -> Maybe Bool
$sel:id:Trace' :: Trace -> Maybe Text
$sel:duration:Trace' :: Trace -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
duration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
limitExceeded
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Segment]
segments