diff --git a/api/src/OpenTelemetry/Internal/Logging/Types.hs b/api/src/OpenTelemetry/Internal/Logging/Types.hs index c02c0194..0ea350d9 100644 --- a/api/src/OpenTelemetry/Internal/Logging/Types.hs +++ b/api/src/OpenTelemetry/Internal/Logging/Types.hs @@ -84,7 +84,7 @@ Creating two @Logger@s with the same identity but different @libraryAttributes@ data Logger = Logger { loggerInstrumentationScope :: InstrumentationLibrary -- ^ Details about the library that the @Logger@ instruments. - , loggerProvider :: LoggerProvider + , loggerLoggerProvider :: LoggerProvider -- ^ The @LoggerProvider@ that created this @Logger@. All configuration for the @Logger@ is contained in the @LoggerProvider@. } @@ -164,11 +164,11 @@ instance IsReadableLogRecord ReadableLogRecord where instance IsReadableLogRecord ReadWriteLogRecord where readLogRecord (ReadWriteLogRecord _ ref) = readIORef ref readLogRecordInstrumentationScope (ReadWriteLogRecord (Logger {loggerInstrumentationScope}) _) = loggerInstrumentationScope - readLogRecordResource (ReadWriteLogRecord Logger {loggerProvider = LoggerProvider {loggerProviderResource}} _) = loggerProviderResource + readLogRecordResource (ReadWriteLogRecord Logger {loggerLoggerProvider = LoggerProvider {loggerProviderResource}} _) = loggerProviderResource instance IsReadWriteLogRecord ReadWriteLogRecord where - readLogRecordAttributeLimits (ReadWriteLogRecord Logger {loggerProvider = LoggerProvider {loggerProviderAttributeLimits}} _) = loggerProviderAttributeLimits + readLogRecordAttributeLimits (ReadWriteLogRecord Logger {loggerLoggerProvider = LoggerProvider {loggerProviderAttributeLimits}} _) = loggerProviderAttributeLimits modifyLogRecord (ReadWriteLogRecord _ ref) = modifyIORef ref atomicModifyLogRecord (ReadWriteLogRecord _ ref) = atomicModifyIORef ref diff --git a/api/src/OpenTelemetry/Logging/Core.hs b/api/src/OpenTelemetry/Logging/Core.hs index d57745c0..d3356d0f 100644 --- a/api/src/OpenTelemetry/Logging/Core.hs +++ b/api/src/OpenTelemetry/Logging/Core.hs @@ -40,7 +40,7 @@ module OpenTelemetry.Logging.Core ( import Control.Applicative import Control.Concurrent.Async -import Control.Monad (void, when) +import Control.Monad import Control.Monad.Trans import Control.Monad.Trans.Maybe import Data.Coerce @@ -173,7 +173,7 @@ makeLogger -> InstrumentationLibrary -- ^ The library that the @Logger@ instruments. This uniquely identifies the @Logger@. -> Logger -makeLogger loggerProvider loggerInstrumentationScope = Logger {..} +makeLogger loggerLoggerProvider loggerInstrumentationScope = Logger {..} createImmutableLogRecord @@ -236,9 +236,12 @@ emitOTelLogRecord attrs severity body = do } -{- | Emits a LogRecord with properties specified by the passed in Logger and LogRecordArguments. +{- | Emits a @LogRecord@ with properties specified by the passed in Logger and LogRecordArguments. If observedTimestamp is not set in LogRecordArguments, it will default to the current timestamp. If context is not specified in LogRecordArguments it will default to the current context. + +The emitted @LogRecord@ will be passed to any @LogRecordProcessor@s registered on the @LoggerProvider@ +that created the @Logger@. -} emitLogRecord :: (MonadIO m) @@ -246,8 +249,15 @@ emitLogRecord -> LogRecordArguments -> m ReadWriteLogRecord emitLogRecord l args = do - ilr <- createImmutableLogRecord (loggerProviderAttributeLimits $ loggerProvider l) args - liftIO $ mkReadWriteLogRecord l ilr + let LoggerProvider {loggerProviderProcessors, loggerProviderAttributeLimits} = loggerLoggerProvider l + + ilr <- createImmutableLogRecord loggerProviderAttributeLimits args + lr <- liftIO $ mkReadWriteLogRecord l ilr + + ctxt <- getContext + mapM_ (\processor -> liftIO $ logRecordProcessorOnEmit processor lr ctxt) loggerProviderProcessors + + pure lr {- | Add an attribute to a @LogRecord@.