diff --git a/opentracing/OpenTracing/Log.hs b/opentracing/OpenTracing/Log.hs index 34aea2b..aae8cb9 100644 --- a/opentracing/OpenTracing/Log.hs +++ b/opentracing/OpenTracing/Log.hs @@ -4,6 +4,7 @@ Module: OpenTracing.Log Logs are structured data that occur over the lifetime of a span. -} +{-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} @@ -31,6 +32,9 @@ import Control.Exception import Control.Lens hiding ((.=)) import Data.Aeson import qualified Data.Aeson.Encoding as Encoding +#if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.Key as Key +#endif import Data.ByteString.Builder (Builder) import Data.Foldable import Data.List.NonEmpty (NonEmpty) @@ -84,8 +88,12 @@ type LogFieldsFormatter = forall t. Foldable t => t LogField -> Builder jsonAssoc :: LogFieldsFormatter jsonAssoc = Encoding.fromEncoding . Encoding.list go . toList where - go lf = Encoding.pairs $ - Encoding.pair (logFieldLabel lf) (logFieldEncoding lf) + go lf = Encoding.pairs $ Encoding.pair (key lf) (logFieldEncoding lf) +#if MIN_VERSION_aeson(2, 0, 0) + key lf = Key.fromText $ logFieldLabel lf +#else + key lf = logFieldLabel lf +#endif -- | A log formatter that encodes each `LogField` as an entry in a shared JSON object -- diff --git a/opentracing/OpenTracing/Reporting/Stdio.hs b/opentracing/OpenTracing/Reporting/Stdio.hs index 9628c2c..a86ec48 100644 --- a/opentracing/OpenTracing/Reporting/Stdio.hs +++ b/opentracing/OpenTracing/Reporting/Stdio.hs @@ -3,6 +3,7 @@ Module: OpenTracing.Reporting.Stdio Logging reporters that emit spans to stdout, stderr and System.IO `Handles`. -} +{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} module OpenTracing.Reporting.Stdio @@ -16,6 +17,9 @@ import Control.Lens (view) import Control.Monad.IO.Class import Data.Aeson (toEncoding) import Data.Aeson.Encoding +#if MIN_VERSION_aeson(2, 0, 0) +import qualified Data.Aeson.Key as Key +#endif import Data.ByteString.Lazy.Char8 (hPutStrLn) import Data.Foldable (toList) import GHC.Stack (prettyCallStack) @@ -59,10 +63,16 @@ logRecE r = pairs $ <> pair "fields" (list logFieldE . toList $ view logFields r) logFieldE :: LogField -> Encoding -logFieldE f = pairs . pair (logFieldLabel f) $ case f of +logFieldE f = pairs . pair key $ case f of Event x -> text x Message x -> text x Stack x -> string . prettyCallStack $ x ErrKind x -> text x ErrObj x -> string . show $ x LogField _ x -> string . show $ x + where +#if MIN_VERSION_aeson(2, 0, 0) + key = Key.fromText $ logFieldLabel f +#else + key = logFieldLabel f +#endif