dp wiz avatar dp wiz committed 97e3dfc

JSON objects as interface arguments

Comments (0)

Files changed (4)

lookout/lookout.cabal

     base,
     hspec,
     lookout,
-    bytestring, unordered-containers
+    bytestring, unordered-containers, aeson
+

lookout/src/System/Log/Lookout/Interfaces.hs

+{-# LANGUAGE OverloadedStrings #-}
+
 -- | Structured data interfaces. Core Sentry interfaces:
 --   <http://sentry.readthedocs.org/en/latest/developer/interfaces/index.html#provided-interfaces>
+
 module System.Log.Lookout.Interfaces
     ( exception
     ) where
 
+import Data.Aeson (object, (.=))
 import qualified Data.HashMap.Strict as HM
 
 import System.Log.Lookout.Types
 exception t v m rec =
     rec { srInterfaces = HM.insert "sentry.interfaces.Exception" info $ srInterfaces rec }
     where
-        info = HM.fromList [ ("type", t)
-                           , ("value", v)
-                           , ("module", m)
-                           ]
+        info = object [ "type" .= t
+                      , "value" .= v
+                      , "module" .= m
+                      ]

lookout/src/System/Log/Lookout/Types.hs

     , SentryLevel(..), SentryRecord(..), newRecord
     ) where
 
-import Data.Aeson (ToJSON(toJSON), object, (.=))
+import Data.Aeson (ToJSON(toJSON), Value, object, (.=))
 import qualified Data.HashMap.Strict as HM
 import qualified Data.Text as T
 
                                  , srServerName :: Maybe String
                                  , srModules    :: !Assoc
                                  , srExtra      :: !Assoc
-                                 , srInterfaces :: HM.HashMap String Assoc
+                                 , srInterfaces :: HM.HashMap String Value
                                  } deriving (Show, Eq)
 
 -- | Initialize a record with all required fields filled in.

lookout/test/Test.hs

+{-# LANGUAGE OverloadedStrings #-}
+
 import Test.Hspec
 import Control.Exception (evaluate)
 
 import qualified Data.ByteString.Lazy.Char8 as LBS
 import qualified Data.HashMap.Strict as HM
+import Data.Aeson (object, (.=))
 import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
 
 import System.Log.Lookout
         r <- make $ extra [("bru", "haha")]
         srExtra r `shouldBe` HM.fromList [("bru", "haha")]
 
-    it "registers exceptions" $ do
-        r <- make $ exception "SyntaxError" "Wattttt!" "__buitins__"
-
-        let ex = HM.fromList [ ("type", "SyntaxError")
-                             , ("value", "Wattttt!")
-                             , ("module", "__buitins__") ]
-
-        HM.lookup "sentry.interfaces.Exception" (srInterfaces r) `shouldBe` Just ex
-
     it "fills in service defaults" $ do
         v <- newEmptyMVar
         l <- initLookout
         srTags rec `shouldBe` HM.fromList [("spam", "eggs"), ("test", "shmest")]
         srExtra rec `shouldBe` HM.fromList [("sausage", "salad")]
 
+  describe "Interfaces" $ do
+    let make = record "test.logger" Debug "test record please ignore"
+
+    it "registers exceptions" $ do
+        r <- make $ exception "SyntaxError" "Wattttt!" "__buitins__"
+
+        let ex = object [ "type" .= ("SyntaxError" :: String)
+                        , "value" .= ("Wattttt!"  :: String)
+                        , "module" .= ("__buitins__"  :: String)
+                        ]
+
+        HM.lookup "sentry.interfaces.Exception" (srInterfaces r) `shouldBe` Just ex
+
+
+
 dsn = "http://public_key:secret_key@example.com/sentry/project-id"
 
 ss = SentrySettings {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.