Skip to content

Commit

Permalink
Renamed LogProcessor to LogRecordProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlauer1 committed Jul 3, 2024
1 parent 2cf1b93 commit ca8248d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/hs-opentelemetry-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library
OpenTelemetry.Internal.Trace.Id
OpenTelemetry.LogAttributes
OpenTelemetry.Logging.Core
OpenTelemetry.LogProcessor
OpenTelemetry.LogRecordProcessor
OpenTelemetry.Processor
OpenTelemetry.Propagator
OpenTelemetry.Resource
Expand Down
12 changes: 6 additions & 6 deletions api/src/OpenTelemetry/Internal/Logging/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE InstanceSigs #-}

module OpenTelemetry.Internal.Logging.Types (
LogProcessor (..),
LogRecordProcessor (..),
LoggerProvider (..),
Logger (..),
LogRecord,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
--
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions api/src/OpenTelemetry/Logging/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions api/test/OpenTelemetry/Logging/CoreSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ 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
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
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
Expand All @@ -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
Expand Down

0 comments on commit ca8248d

Please sign in to comment.