diff options
author | Profpatsch <mail@profpatsch.de> | 2024-07-29T09·47+0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2024-07-30T12·41+0000 |
commit | a86dca8c784887b2eb3f2cd172e18ecad6f06acb (patch) | |
tree | 35ea309ee17749f5dd652e069ed29cbc51911c80 /users/Profpatsch/whatcd-resolver/src/AppT.hs | |
parent | 1f65a7b0d033fc8a1bc3d8315e34494035ae8128 (diff) |
feat(users/Profpatsch/whatcd-resolver): read redacted key from env r/8427
Change-Id: I5667710423aeeacfbb8dddf5b0b8750dc8f878aa Reviewed-on: https://cl.tvl.fyi/c/depot/+/12055 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch/whatcd-resolver/src/AppT.hs')
-rw-r--r-- | users/Profpatsch/whatcd-resolver/src/AppT.hs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/users/Profpatsch/whatcd-resolver/src/AppT.hs b/users/Profpatsch/whatcd-resolver/src/AppT.hs index 0c93cbaddb3a..4363e2dbb298 100644 --- a/users/Profpatsch/whatcd-resolver/src/AppT.hs +++ b/users/Profpatsch/whatcd-resolver/src/AppT.hs @@ -12,6 +12,8 @@ import Data.Pool (Pool) import Data.Text qualified as Text import Database.PostgreSQL.Simple qualified as Postgres import GHC.Stack qualified +import Json.Enc +import Json.Enc qualified as Enc import Label import OpenTelemetry.Trace qualified as Otel hiding (getTracer, inSpan, inSpan') import OpenTelemetry.Trace.Core qualified as Otel hiding (inSpan, inSpan') @@ -27,7 +29,8 @@ data Context = Context tracer :: Otel.Tracer, pgFormat :: PgFormatPool, pgConnPool :: Pool Postgres.Connection, - transmissionSessionId :: IORef (Maybe ByteString) + transmissionSessionId :: IORef (Maybe ByteString), + redactedApiKey :: ByteString } newtype AppT m a = AppT {unAppT :: ReaderT Context m a} @@ -67,6 +70,15 @@ addAttribute span key a = Otel.addAttribute span ("_." <> key) a addAttributes :: (MonadIO m) => Otel.Span -> HashMap Text Otel.Attribute -> m () addAttributes span attrs = Otel.addAttributes span $ attrs & HashMap.mapKeys ("_." <>) +-- | Create an otel attribute from a json encoder +jsonAttribute :: Enc -> Otel.Attribute +jsonAttribute e = e & Enc.encToTextPretty & Otel.toAttribute + +orThrowAppErrorNewSpan :: (MonadThrow m, MonadOtel m) => Text -> Either ErrorTree a -> m a +orThrowAppErrorNewSpan msg = \case + Left err -> appThrowTreeNewSpan msg err + Right a -> pure a + appThrowTreeNewSpan :: (MonadThrow m, MonadOtel m) => Text -> ErrorTree -> m a appThrowTreeNewSpan spanName exc = inSpan' spanName $ \span -> do let msg = prettyErrorTree exc @@ -127,7 +139,7 @@ recordException span dat = liftIO $ do HashMap.fromList [ ("exception.type", Otel.toAttribute @Text dat.type_), ("exception.message", Otel.toAttribute @Text dat.message), - ("exception.stacktrace", Otel.toAttribute @Text $ Text.unlines $ map stringToText callStack) + ("exception.stacktrace", Otel.toAttribute @Text $ Text.unlines $ Prelude.map stringToText callStack) ], .. } |