Skip to content

Commit

Permalink
Refactored attribute limits to be controlled by the LoggerProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlauer1 committed Jun 11, 2024
1 parent c06b5a6 commit 27fbd05
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 5 additions & 2 deletions api/src/OpenTelemetry/Internal/Logging/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ module OpenTelemetry.Internal.Logging.Types (
severityInt,
) where

import qualified Data.HashMap.Strict as H
import Data.Int (Int64)
import Data.Text (Text)
import OpenTelemetry.Attributes (AttributeLimits)
import OpenTelemetry.Common (Timestamp, TraceFlags)
import OpenTelemetry.Context.Types
import OpenTelemetry.Internal.Common.Types (InstrumentationLibrary)
import OpenTelemetry.Internal.Trace.Id (SpanId, TraceId)
import OpenTelemetry.LogAttributes (LogAttributes)
import OpenTelemetry.LogAttributes (AnyValue, LogAttributes)
import OpenTelemetry.Resource (MaterializedResources)


-- | @Logger@s can be created from @LoggerProvider@s
data LoggerProvider = LoggerProvider
{ loggerProviderResource :: MaterializedResources
, loggerProviderAttributeLimits :: AttributeLimits
}


Expand Down Expand Up @@ -125,7 +128,7 @@ data LogRecordArguments body = LogRecordArguments
, severityText :: Maybe Text
, severityNumber :: Maybe Int
, body :: body
, attributes :: LogAttributes
, attributes :: H.HashMap Text AnyValue
}


Expand Down
5 changes: 5 additions & 0 deletions api/src/OpenTelemetry/LogAttributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ instance (ToValue a) => ToValue (H.HashMap Text a) where
toValue = HashMapValue . fmap toValue


instance ToValue AnyValue where
toValue :: AnyValue -> AnyValue
toValue = id


unsafeMergeLogAttributesIgnoringLimits :: LogAttributes -> LogAttributes -> LogAttributes
unsafeMergeLogAttributesIgnoringLimits (LogAttributes l lc ld) (LogAttributes r rc rd) = LogAttributes (l <> r) (lc + rc) (ld + rd)

Expand Down
14 changes: 12 additions & 2 deletions api/src/OpenTelemetry/Logging/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ import Control.Applicative
import Control.Monad.Trans
import Control.Monad.Trans.Maybe
import Data.Coerce
import qualified Data.HashMap.Strict as H
import Data.IORef
import Data.Maybe
import GHC.IO (unsafePerformIO)
import OpenTelemetry.Attributes (AttributeLimits)
import OpenTelemetry.Common
import OpenTelemetry.Context
import OpenTelemetry.Context.ThreadLocal
import OpenTelemetry.Internal.Common.Types
import OpenTelemetry.Internal.Logging.Types
import OpenTelemetry.Internal.Trace.Types
import OpenTelemetry.LogAttributes
import OpenTelemetry.Resource (MaterializedResources, emptyMaterializedResources)
import System.Clock

Expand All @@ -45,7 +48,10 @@ getCurrentTimestamp :: (MonadIO m) => m Timestamp
getCurrentTimestamp = liftIO $ coerce @(IO TimeSpec) @(IO Timestamp) $ getTime Realtime


data LoggerProviderOptions = LoggerProviderOptions {loggerProviderOptionsResource :: MaterializedResources}
data LoggerProviderOptions = LoggerProviderOptions
{ loggerProviderOptionsResource :: MaterializedResources
, loggerProviderOptionsAttributeLimits :: AttributeLimits
}


{- | Options for creating a @LoggerProvider@ with no resources and default limits.
Expand Down Expand Up @@ -124,5 +130,9 @@ emitLogRecord Logger {..} LogRecordArguments {..} = do
, logRecordBody = body
, logRecordResource = loggerProviderResource loggerProvider
, logRecordInstrumentationScope = loggerInstrumentationScope
, logRecordAttributes = attributes
, logRecordAttributes =
addAttributes
(loggerProviderAttributeLimits loggerProvider)
emptyAttributes
attributes
}

0 comments on commit 27fbd05

Please sign in to comment.