{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.PutTraceSegments
-- 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)
--
-- Uploads segment documents to Amazon Web Services X-Ray. The
-- <https://docs.aws.amazon.com/xray/index.html X-Ray SDK> generates
-- segment documents and sends them to the X-Ray daemon, which uploads them
-- in batches. A segment document can be a completed segment, an
-- in-progress segment, or an array of subsegments.
--
-- Segments must include the following fields. For the full segment
-- document schema, see
-- <https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html Amazon Web Services X-Ray Segment Documents>
-- in the /Amazon Web Services X-Ray Developer Guide/.
--
-- __Required segment document fields__
--
-- -   @name@ - The name of the service that handled the request.
--
-- -   @id@ - A 64-bit identifier for the segment, unique among segments in
--     the same trace, in 16 hexadecimal digits.
--
-- -   @trace_id@ - A unique identifier that connects all segments and
--     subsegments originating from a single client request.
--
-- -   @start_time@ - Time the segment or subsegment was created, in
--     floating point seconds in epoch time, accurate to milliseconds. For
--     example, @1480615200.010@ or @1.480615200010E9@.
--
-- -   @end_time@ - Time the segment or subsegment was closed. For example,
--     @1480615200.090@ or @1.480615200090E9@. Specify either an @end_time@
--     or @in_progress@.
--
-- -   @in_progress@ - Set to @true@ instead of specifying an @end_time@ to
--     record that a segment has been started, but is not complete. Send an
--     in-progress segment when your application receives a request that
--     will take a long time to serve, to trace that the request was
--     received. When the response is sent, send the complete segment to
--     overwrite the in-progress segment.
--
-- A @trace_id@ consists of three numbers separated by hyphens. For
-- example, 1-58406520-a006649127e371903a2de979. This includes:
--
-- __Trace ID Format__
--
-- -   The version number, for instance, @1@.
--
-- -   The time of the original request, in Unix epoch time, in 8
--     hexadecimal digits. For example, 10:00AM December 2nd, 2016 PST in
--     epoch time is @1480615200@ seconds, or @58406520@ in hexadecimal.
--
-- -   A 96-bit identifier for the trace, globally unique, in 24
--     hexadecimal digits.
module Amazonka.XRay.PutTraceSegments
  ( -- * Creating a Request
    PutTraceSegments (..),
    newPutTraceSegments,

    -- * Request Lenses
    putTraceSegments_traceSegmentDocuments,

    -- * Destructuring the Response
    PutTraceSegmentsResponse (..),
    newPutTraceSegmentsResponse,

    -- * Response Lenses
    putTraceSegmentsResponse_unprocessedTraceSegments,
    putTraceSegmentsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.XRay.Types

-- | /See:/ 'newPutTraceSegments' smart constructor.
data PutTraceSegments = PutTraceSegments'
  { -- | A string containing a JSON document defining one or more segments or
    -- subsegments.
    PutTraceSegments -> [Text]
traceSegmentDocuments :: [Prelude.Text]
  }
  deriving (PutTraceSegments -> PutTraceSegments -> Bool
(PutTraceSegments -> PutTraceSegments -> Bool)
-> (PutTraceSegments -> PutTraceSegments -> Bool)
-> Eq PutTraceSegments
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutTraceSegments -> PutTraceSegments -> Bool
$c/= :: PutTraceSegments -> PutTraceSegments -> Bool
== :: PutTraceSegments -> PutTraceSegments -> Bool
$c== :: PutTraceSegments -> PutTraceSegments -> Bool
Prelude.Eq, ReadPrec [PutTraceSegments]
ReadPrec PutTraceSegments
Int -> ReadS PutTraceSegments
ReadS [PutTraceSegments]
(Int -> ReadS PutTraceSegments)
-> ReadS [PutTraceSegments]
-> ReadPrec PutTraceSegments
-> ReadPrec [PutTraceSegments]
-> Read PutTraceSegments
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutTraceSegments]
$creadListPrec :: ReadPrec [PutTraceSegments]
readPrec :: ReadPrec PutTraceSegments
$creadPrec :: ReadPrec PutTraceSegments
readList :: ReadS [PutTraceSegments]
$creadList :: ReadS [PutTraceSegments]
readsPrec :: Int -> ReadS PutTraceSegments
$creadsPrec :: Int -> ReadS PutTraceSegments
Prelude.Read, Int -> PutTraceSegments -> ShowS
[PutTraceSegments] -> ShowS
PutTraceSegments -> String
(Int -> PutTraceSegments -> ShowS)
-> (PutTraceSegments -> String)
-> ([PutTraceSegments] -> ShowS)
-> Show PutTraceSegments
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutTraceSegments] -> ShowS
$cshowList :: [PutTraceSegments] -> ShowS
show :: PutTraceSegments -> String
$cshow :: PutTraceSegments -> String
showsPrec :: Int -> PutTraceSegments -> ShowS
$cshowsPrec :: Int -> PutTraceSegments -> ShowS
Prelude.Show, (forall x. PutTraceSegments -> Rep PutTraceSegments x)
-> (forall x. Rep PutTraceSegments x -> PutTraceSegments)
-> Generic PutTraceSegments
forall x. Rep PutTraceSegments x -> PutTraceSegments
forall x. PutTraceSegments -> Rep PutTraceSegments x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutTraceSegments x -> PutTraceSegments
$cfrom :: forall x. PutTraceSegments -> Rep PutTraceSegments x
Prelude.Generic)

-- |
-- Create a value of 'PutTraceSegments' 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:
--
-- 'traceSegmentDocuments', 'putTraceSegments_traceSegmentDocuments' - A string containing a JSON document defining one or more segments or
-- subsegments.
newPutTraceSegments ::
  PutTraceSegments
newPutTraceSegments :: PutTraceSegments
newPutTraceSegments =
  PutTraceSegments' :: [Text] -> PutTraceSegments
PutTraceSegments'
    { $sel:traceSegmentDocuments:PutTraceSegments' :: [Text]
traceSegmentDocuments =
        [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | A string containing a JSON document defining one or more segments or
-- subsegments.
putTraceSegments_traceSegmentDocuments :: Lens.Lens' PutTraceSegments [Prelude.Text]
putTraceSegments_traceSegmentDocuments :: ([Text] -> f [Text]) -> PutTraceSegments -> f PutTraceSegments
putTraceSegments_traceSegmentDocuments = (PutTraceSegments -> [Text])
-> (PutTraceSegments -> [Text] -> PutTraceSegments)
-> Lens PutTraceSegments PutTraceSegments [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutTraceSegments' {[Text]
traceSegmentDocuments :: [Text]
$sel:traceSegmentDocuments:PutTraceSegments' :: PutTraceSegments -> [Text]
traceSegmentDocuments} -> [Text]
traceSegmentDocuments) (\s :: PutTraceSegments
s@PutTraceSegments' {} [Text]
a -> PutTraceSegments
s {$sel:traceSegmentDocuments:PutTraceSegments' :: [Text]
traceSegmentDocuments = [Text]
a} :: PutTraceSegments) (([Text] -> f [Text]) -> PutTraceSegments -> f PutTraceSegments)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> PutTraceSegments
-> f PutTraceSegments
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutTraceSegments where
  type
    AWSResponse PutTraceSegments =
      PutTraceSegmentsResponse
  request :: PutTraceSegments -> Request PutTraceSegments
request = Service -> PutTraceSegments -> Request PutTraceSegments
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutTraceSegments
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutTraceSegments)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutTraceSegments))
-> Logger
-> Service
-> Proxy PutTraceSegments
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutTraceSegments)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [UnprocessedTraceSegment] -> Int -> PutTraceSegmentsResponse
PutTraceSegmentsResponse'
            (Maybe [UnprocessedTraceSegment]
 -> Int -> PutTraceSegmentsResponse)
-> Either String (Maybe [UnprocessedTraceSegment])
-> Either String (Int -> PutTraceSegmentsResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object
-> Text -> Either String (Maybe (Maybe [UnprocessedTraceSegment]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"UnprocessedTraceSegments"
                            Either String (Maybe (Maybe [UnprocessedTraceSegment]))
-> Maybe [UnprocessedTraceSegment]
-> Either String (Maybe [UnprocessedTraceSegment])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [UnprocessedTraceSegment]
forall a. Monoid a => a
Prelude.mempty
                        )
            Either String (Int -> PutTraceSegmentsResponse)
-> Either String Int -> Either String PutTraceSegmentsResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutTraceSegments

instance Prelude.NFData PutTraceSegments

instance Core.ToHeaders PutTraceSegments where
  toHeaders :: PutTraceSegments -> ResponseHeaders
toHeaders = ResponseHeaders -> PutTraceSegments -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON PutTraceSegments where
  toJSON :: PutTraceSegments -> Value
toJSON PutTraceSegments' {[Text]
traceSegmentDocuments :: [Text]
$sel:traceSegmentDocuments:PutTraceSegments' :: PutTraceSegments -> [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"TraceSegmentDocuments"
                  Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
traceSegmentDocuments
              )
          ]
      )

instance Core.ToPath PutTraceSegments where
  toPath :: PutTraceSegments -> ByteString
toPath = ByteString -> PutTraceSegments -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/TraceSegments"

instance Core.ToQuery PutTraceSegments where
  toQuery :: PutTraceSegments -> QueryString
toQuery = QueryString -> PutTraceSegments -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newPutTraceSegmentsResponse' smart constructor.
data PutTraceSegmentsResponse = PutTraceSegmentsResponse'
  { -- | Segments that failed processing.
    PutTraceSegmentsResponse -> Maybe [UnprocessedTraceSegment]
unprocessedTraceSegments :: Prelude.Maybe [UnprocessedTraceSegment],
    -- | The response's http status code.
    PutTraceSegmentsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutTraceSegmentsResponse -> PutTraceSegmentsResponse -> Bool
(PutTraceSegmentsResponse -> PutTraceSegmentsResponse -> Bool)
-> (PutTraceSegmentsResponse -> PutTraceSegmentsResponse -> Bool)
-> Eq PutTraceSegmentsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutTraceSegmentsResponse -> PutTraceSegmentsResponse -> Bool
$c/= :: PutTraceSegmentsResponse -> PutTraceSegmentsResponse -> Bool
== :: PutTraceSegmentsResponse -> PutTraceSegmentsResponse -> Bool
$c== :: PutTraceSegmentsResponse -> PutTraceSegmentsResponse -> Bool
Prelude.Eq, ReadPrec [PutTraceSegmentsResponse]
ReadPrec PutTraceSegmentsResponse
Int -> ReadS PutTraceSegmentsResponse
ReadS [PutTraceSegmentsResponse]
(Int -> ReadS PutTraceSegmentsResponse)
-> ReadS [PutTraceSegmentsResponse]
-> ReadPrec PutTraceSegmentsResponse
-> ReadPrec [PutTraceSegmentsResponse]
-> Read PutTraceSegmentsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutTraceSegmentsResponse]
$creadListPrec :: ReadPrec [PutTraceSegmentsResponse]
readPrec :: ReadPrec PutTraceSegmentsResponse
$creadPrec :: ReadPrec PutTraceSegmentsResponse
readList :: ReadS [PutTraceSegmentsResponse]
$creadList :: ReadS [PutTraceSegmentsResponse]
readsPrec :: Int -> ReadS PutTraceSegmentsResponse
$creadsPrec :: Int -> ReadS PutTraceSegmentsResponse
Prelude.Read, Int -> PutTraceSegmentsResponse -> ShowS
[PutTraceSegmentsResponse] -> ShowS
PutTraceSegmentsResponse -> String
(Int -> PutTraceSegmentsResponse -> ShowS)
-> (PutTraceSegmentsResponse -> String)
-> ([PutTraceSegmentsResponse] -> ShowS)
-> Show PutTraceSegmentsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutTraceSegmentsResponse] -> ShowS
$cshowList :: [PutTraceSegmentsResponse] -> ShowS
show :: PutTraceSegmentsResponse -> String
$cshow :: PutTraceSegmentsResponse -> String
showsPrec :: Int -> PutTraceSegmentsResponse -> ShowS
$cshowsPrec :: Int -> PutTraceSegmentsResponse -> ShowS
Prelude.Show, (forall x.
 PutTraceSegmentsResponse -> Rep PutTraceSegmentsResponse x)
-> (forall x.
    Rep PutTraceSegmentsResponse x -> PutTraceSegmentsResponse)
-> Generic PutTraceSegmentsResponse
forall x.
Rep PutTraceSegmentsResponse x -> PutTraceSegmentsResponse
forall x.
PutTraceSegmentsResponse -> Rep PutTraceSegmentsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutTraceSegmentsResponse x -> PutTraceSegmentsResponse
$cfrom :: forall x.
PutTraceSegmentsResponse -> Rep PutTraceSegmentsResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutTraceSegmentsResponse' 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:
--
-- 'unprocessedTraceSegments', 'putTraceSegmentsResponse_unprocessedTraceSegments' - Segments that failed processing.
--
-- 'httpStatus', 'putTraceSegmentsResponse_httpStatus' - The response's http status code.
newPutTraceSegmentsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutTraceSegmentsResponse
newPutTraceSegmentsResponse :: Int -> PutTraceSegmentsResponse
newPutTraceSegmentsResponse Int
pHttpStatus_ =
  PutTraceSegmentsResponse' :: Maybe [UnprocessedTraceSegment] -> Int -> PutTraceSegmentsResponse
PutTraceSegmentsResponse'
    { $sel:unprocessedTraceSegments:PutTraceSegmentsResponse' :: Maybe [UnprocessedTraceSegment]
unprocessedTraceSegments =
        Maybe [UnprocessedTraceSegment]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutTraceSegmentsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Segments that failed processing.
putTraceSegmentsResponse_unprocessedTraceSegments :: Lens.Lens' PutTraceSegmentsResponse (Prelude.Maybe [UnprocessedTraceSegment])
putTraceSegmentsResponse_unprocessedTraceSegments :: (Maybe [UnprocessedTraceSegment]
 -> f (Maybe [UnprocessedTraceSegment]))
-> PutTraceSegmentsResponse -> f PutTraceSegmentsResponse
putTraceSegmentsResponse_unprocessedTraceSegments = (PutTraceSegmentsResponse -> Maybe [UnprocessedTraceSegment])
-> (PutTraceSegmentsResponse
    -> Maybe [UnprocessedTraceSegment] -> PutTraceSegmentsResponse)
-> Lens
     PutTraceSegmentsResponse
     PutTraceSegmentsResponse
     (Maybe [UnprocessedTraceSegment])
     (Maybe [UnprocessedTraceSegment])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutTraceSegmentsResponse' {Maybe [UnprocessedTraceSegment]
unprocessedTraceSegments :: Maybe [UnprocessedTraceSegment]
$sel:unprocessedTraceSegments:PutTraceSegmentsResponse' :: PutTraceSegmentsResponse -> Maybe [UnprocessedTraceSegment]
unprocessedTraceSegments} -> Maybe [UnprocessedTraceSegment]
unprocessedTraceSegments) (\s :: PutTraceSegmentsResponse
s@PutTraceSegmentsResponse' {} Maybe [UnprocessedTraceSegment]
a -> PutTraceSegmentsResponse
s {$sel:unprocessedTraceSegments:PutTraceSegmentsResponse' :: Maybe [UnprocessedTraceSegment]
unprocessedTraceSegments = Maybe [UnprocessedTraceSegment]
a} :: PutTraceSegmentsResponse) ((Maybe [UnprocessedTraceSegment]
  -> f (Maybe [UnprocessedTraceSegment]))
 -> PutTraceSegmentsResponse -> f PutTraceSegmentsResponse)
-> ((Maybe [UnprocessedTraceSegment]
     -> f (Maybe [UnprocessedTraceSegment]))
    -> Maybe [UnprocessedTraceSegment]
    -> f (Maybe [UnprocessedTraceSegment]))
-> (Maybe [UnprocessedTraceSegment]
    -> f (Maybe [UnprocessedTraceSegment]))
-> PutTraceSegmentsResponse
-> f PutTraceSegmentsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [UnprocessedTraceSegment]
  [UnprocessedTraceSegment]
  [UnprocessedTraceSegment]
  [UnprocessedTraceSegment]
-> Iso
     (Maybe [UnprocessedTraceSegment])
     (Maybe [UnprocessedTraceSegment])
     (Maybe [UnprocessedTraceSegment])
     (Maybe [UnprocessedTraceSegment])
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
  [UnprocessedTraceSegment]
  [UnprocessedTraceSegment]
  [UnprocessedTraceSegment]
  [UnprocessedTraceSegment]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
putTraceSegmentsResponse_httpStatus :: Lens.Lens' PutTraceSegmentsResponse Prelude.Int
putTraceSegmentsResponse_httpStatus :: (Int -> f Int)
-> PutTraceSegmentsResponse -> f PutTraceSegmentsResponse
putTraceSegmentsResponse_httpStatus = (PutTraceSegmentsResponse -> Int)
-> (PutTraceSegmentsResponse -> Int -> PutTraceSegmentsResponse)
-> Lens PutTraceSegmentsResponse PutTraceSegmentsResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutTraceSegmentsResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutTraceSegmentsResponse' :: PutTraceSegmentsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PutTraceSegmentsResponse
s@PutTraceSegmentsResponse' {} Int
a -> PutTraceSegmentsResponse
s {$sel:httpStatus:PutTraceSegmentsResponse' :: Int
httpStatus = Int
a} :: PutTraceSegmentsResponse)

instance Prelude.NFData PutTraceSegmentsResponse