From acc818b8e0a2cc5d2bd6da749618b6a4380f051a Mon Sep 17 00:00:00 2001 From: evanlauer1 Date: Wed, 10 Jul 2024 12:49:37 -0700 Subject: [PATCH] Removed HashMap from logRecordExporterExport and updated tests --- sdk/src/OpenTelemetry/LogRecordProcessor/Simple.hs | 7 ++----- sdk/test/OpenTelemetry/LogRecordProcessorSpec.hs | 13 +++++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/sdk/src/OpenTelemetry/LogRecordProcessor/Simple.hs b/sdk/src/OpenTelemetry/LogRecordProcessor/Simple.hs index 04f71abb..1b03e8d0 100644 --- a/sdk/src/OpenTelemetry/LogRecordProcessor/Simple.hs +++ b/sdk/src/OpenTelemetry/LogRecordProcessor/Simple.hs @@ -10,7 +10,6 @@ import Control.Concurrent.Async (async, cancel) import Control.Concurrent.Chan.Unagi import Control.Exception import Control.Monad (forever) -import qualified Data.HashMap.Strict as H import qualified Data.Vector as V import OpenTelemetry.Internal.Common.Types import OpenTelemetry.Internal.Logs.Types @@ -26,7 +25,7 @@ simpleProcessor LogRecordExporter {..} = do bracketOnError (readChan outChan) (writeChan inChan) - exportSingleLogRecord + (logRecordExporterExport . V.singleton) let logRecordProcessorForceFlush = ( do @@ -60,7 +59,5 @@ simpleProcessor LogRecordExporter {..} = do case mlr of Nothing -> pure acc Just lr -> do - res <- exportSingleLogRecord lr + res <- logRecordExporterExport $ V.singleton lr forceFlushOutChan outChan (res : acc) - - exportSingleLogRecord = logRecordExporterExport . (H.singleton <$> readLogRecordInstrumentationScope <*> V.singleton) diff --git a/sdk/test/OpenTelemetry/LogRecordProcessorSpec.hs b/sdk/test/OpenTelemetry/LogRecordProcessorSpec.hs index 9f3f6b0e..2b301bdf 100644 --- a/sdk/test/OpenTelemetry/LogRecordProcessorSpec.hs +++ b/sdk/test/OpenTelemetry/LogRecordProcessorSpec.hs @@ -4,7 +4,6 @@ module OpenTelemetry.LogRecordProcessorSpec where -import qualified Data.HashMap.Strict as H import Data.IORef import qualified Data.Vector as V import qualified OpenTelemetry.Context as Context @@ -22,13 +21,12 @@ getTestExporter = do numExportsRef <- newIORef 0 shutdownRef <- newIORef False - let logRecordExporterExport logRecordsByLibrary = do + let logRecordExporterExport logRecords = do shutdown <- readIORef shutdownRef if shutdown then pure (Failure Nothing) else do - let numLogRecords = foldr (\lrs n -> n + V.length lrs) 0 logRecordsByLibrary - modifyIORef numExportsRef (+ numLogRecords) + modifyIORef numExportsRef $ (+) $ V.length logRecords pure Success @@ -52,9 +50,8 @@ getTestExporterWithoutShutdown :: IO (IORef Int, LogRecordExporter body) getTestExporterWithoutShutdown = do numExportsRef <- newIORef 0 - let logRecordExporterExport logRecordsByLibrary = do - let numLogRecords = foldr (\lrs n -> n + V.length lrs) 0 logRecordsByLibrary - modifyIORef numExportsRef (+ numLogRecords) + let logRecordExporterExport logRecords = do + modifyIORef numExportsRef $ (+) $ V.length $ logRecords pure Success @@ -110,7 +107,7 @@ spec = describe "LogRecordProcessor" $ do numExports <- readIORef numExportsRef numExports `shouldBe` 3 - exportRes <- logRecordExporterExport testExporter H.empty + exportRes <- logRecordExporterExport testExporter V.empty exportRes `shouldSatisfy` \case Success -> False Failure _ -> True