diff --git a/api/hs-opentelemetry-api.cabal b/api/hs-opentelemetry-api.cabal index 9bd00478..a340c6b0 100644 --- a/api/hs-opentelemetry-api.cabal +++ b/api/hs-opentelemetry-api.cabal @@ -40,7 +40,7 @@ library OpenTelemetry.Internal.Trace.Id OpenTelemetry.LogAttributes OpenTelemetry.Logging.Core - OpenTelemetry.LogProcessor + OpenTelemetry.LogRecordProcessor OpenTelemetry.Processor OpenTelemetry.Propagator OpenTelemetry.Resource diff --git a/api/src/OpenTelemetry/Internal/Logging/Types.hs b/api/src/OpenTelemetry/Internal/Logging/Types.hs index ec90a09c..c4709cda 100644 --- a/api/src/OpenTelemetry/Internal/Logging/Types.hs +++ b/api/src/OpenTelemetry/Internal/Logging/Types.hs @@ -2,7 +2,7 @@ {-# LANGUAGE InstanceSigs #-} module OpenTelemetry.Internal.Logging.Types ( - LogProcessor (..), + LogRecordProcessor (..), LoggerProvider (..), Logger (..), LogRecord, @@ -31,12 +31,12 @@ import OpenTelemetry.LogAttributes import OpenTelemetry.Resource (MaterializedResources) -data LogProcessor body = LogProcessor - { logProcessorOnEmit :: IORef (ImmutableLogRecord body) -> Context -> IO () +data LogRecordProcessor body = LogRecordProcessor + { logRecordProcessorOnEmit :: IORef (ImmutableLogRecord body) -> Context -> IO () -- ^ Called when a LogRecord is emitted. This method is called synchronously on the thread that emitted the LogRecord, therefore it SHOULD NOT block or throw exceptions. -- -- A LogRecordProcessor may freely modify logRecord for the duration of the OnEmit call. If logRecord is needed after OnEmit returns (i.e. for asynchronous processing) only reads are permitted. - , logProcessorShutdown :: IO (Async ShutdownResult) + , logRecordProcessorShutdown :: IO (Async ShutdownResult) -- ^ Shuts down the processor. Called when SDK is shut down. This is an opportunity for processor to do any cleanup required. -- -- Shutdown SHOULD be called only once for each LogRecordProcessor instance. After the call to Shutdown, subsequent calls to OnEmit are not allowed. SDKs SHOULD ignore these calls gracefully, if possible. @@ -47,7 +47,7 @@ data LogProcessor body = LogProcessor -- -- Shutdown SHOULD complete or abort within some timeout. Shutdown can be implemented as a blocking API or an asynchronous API which notifies the caller via a callback or an event. -- OpenTelemetry SDK authors can decide if they want to make the shutdown timeout configurable. - , logProcessorForceFlush :: IO () + , logRecordProcessorForceFlush :: IO () -- ^ This is a hint to ensure that any tasks associated with LogRecords for which the LogRecordProcessor had already received events prior to the call to ForceFlush SHOULD be completed -- as soon as possible, preferably before returning from this method. -- @@ -66,7 +66,7 @@ data LogProcessor body = LogProcessor -- | @Logger@s can be created from @LoggerProvider@s data LoggerProvider body = LoggerProvider - { loggerProviderProcessors :: Vector (LogProcessor body) + { loggerProviderProcessors :: Vector (LogRecordProcessor body) , loggerProviderResource :: MaterializedResources , loggerProviderAttributeLimits :: AttributeLimits } diff --git a/api/src/OpenTelemetry/LogProcessor.hs b/api/src/OpenTelemetry/LogRecordProcessor.hs similarity index 81% rename from api/src/OpenTelemetry/LogProcessor.hs rename to api/src/OpenTelemetry/LogRecordProcessor.hs index bf352ed5..f05346a0 100644 --- a/api/src/OpenTelemetry/LogProcessor.hs +++ b/api/src/OpenTelemetry/LogRecordProcessor.hs @@ -1,5 +1,5 @@ {- | - @LogProcessor@ is an interface which allows hooks for @LogRecord@ emit method invocations. + @LogRecordProcessor@ is an interface which allows hooks for @LogRecord@ emit method invocations. Built-in log processors are responsible for batching and conversion of spans to exportable representation and passing batches to exporters. @@ -9,8 +9,8 @@ SDK MUST allow users to implement and configure custom processors and decorate built-in processors for advanced scenarios such as tagging or filtering. -} -module OpenTelemetry.LogProcessor ( - LogProcessor (..), +module OpenTelemetry.LogRecordProcessor ( + LogRecordProcessor (..), ShutdownResult (..), ) where diff --git a/api/src/OpenTelemetry/Logging/Core.hs b/api/src/OpenTelemetry/Logging/Core.hs index 3533155f..6d418a61 100644 --- a/api/src/OpenTelemetry/Logging/Core.hs +++ b/api/src/OpenTelemetry/Logging/Core.hs @@ -91,7 +91,7 @@ emptyLoggerProviderOptions = You should generally use @getGlobalLoggerProvider@ for most applications. -} -createLoggerProvider :: [LogProcessor body] -> LoggerProviderOptions -> LoggerProvider body +createLoggerProvider :: [LogRecordProcessor body] -> LoggerProviderOptions -> LoggerProvider body createLoggerProvider ps LoggerProviderOptions {..} = LoggerProvider { loggerProviderProcessors = V.fromList ps @@ -130,7 +130,7 @@ setGlobalLoggerProvider = liftIO . writeIORef globalLoggerProvider shutdownLoggerProvider :: (MonadIO m) => LoggerProvider body -> m () shutdownLoggerProvider LoggerProvider {loggerProviderProcessors} = liftIO $ do asyncShutdownResults <- V.forM loggerProviderProcessors $ \processor -> do - logProcessorShutdown processor + logRecordProcessorShutdown processor mapM_ wait asyncShutdownResults @@ -146,7 +146,7 @@ forceFlushLoggerProvider -- ^ Result that denotes whether the flush action succeeded, failed, or timed out. forceFlushLoggerProvider LoggerProvider {loggerProviderProcessors} mtimeout = liftIO $ do jobs <- V.forM loggerProviderProcessors $ \processor -> async $ do - logProcessorForceFlush processor + logRecordProcessorForceFlush processor mresult <- timeout (fromMaybe 5_000_000 mtimeout) $ V.foldM diff --git a/api/test/OpenTelemetry/Logging/CoreSpec.hs b/api/test/OpenTelemetry/Logging/CoreSpec.hs index d0fe02d4..13552943 100644 --- a/api/test/OpenTelemetry/Logging/CoreSpec.hs +++ b/api/test/OpenTelemetry/Logging/CoreSpec.hs @@ -7,7 +7,6 @@ import qualified Data.HashMap.Strict as H import Data.IORef import qualified OpenTelemetry.Attributes as A import OpenTelemetry.Internal.Logging.Types -import OpenTelemetry.Internal.Logging.Types (LoggerProvider (loggerProviderProcessors)) import qualified OpenTelemetry.LogAttributes as LA import OpenTelemetry.Logging.Core import OpenTelemetry.Resource @@ -15,11 +14,11 @@ import OpenTelemetry.Resource.OperatingSystem import Test.Hspec -newtype TestLogProcessor body = TestLogProcessor (LogProcessor body) +newtype TestLogRecordProcessor body = TestLogRecordProcessor (LogRecordProcessor body) -instance Show (TestLogProcessor body) where - show _ = "LogProcessor {..}" +instance Show (TestLogRecordProcessor body) where + show _ = "LogRecordProcessor {..}" spec :: Spec @@ -27,7 +26,7 @@ spec = describe "Core" $ do describe "The global logger provider" $ do it "Returns a no-op LoggerProvider when not initialized" $ do LoggerProvider {..} <- getGlobalLoggerProvider - fmap TestLogProcessor loggerProviderProcessors `shouldSatisfy` null + fmap TestLogRecordProcessor loggerProviderProcessors `shouldSatisfy` null loggerProviderResource `shouldBe` emptyMaterializedResources loggerProviderAttributeLimits `shouldBe` LA.defaultAttributeLimits it "Allows a LoggerProvider to be set and returns that with subsequent calls to getGlobalLoggerProvider" $ do @@ -53,7 +52,7 @@ spec = describe "Core" $ do setGlobalLoggerProvider lp glp <- getGlobalLoggerProvider - fmap TestLogProcessor (loggerProviderProcessors glp) `shouldSatisfy` null + fmap TestLogRecordProcessor (loggerProviderProcessors glp) `shouldSatisfy` null loggerProviderResource glp `shouldBe` loggerProviderResource lp loggerProviderAttributeLimits glp `shouldBe` loggerProviderAttributeLimits lp describe "addAttribute" $ do