diff --git a/api/src/OpenTelemetry/Internal/Common/Types.hs b/api/src/OpenTelemetry/Internal/Common/Types.hs index b78dfd18..0d80f8c7 100644 --- a/api/src/OpenTelemetry/Internal/Common/Types.hs +++ b/api/src/OpenTelemetry/Internal/Common/Types.hs @@ -89,6 +89,7 @@ data AnyValue | ByteStringValue ByteString | ArrayValue [AnyValue] | HashMapValue (H.HashMap Text AnyValue) + | NullValue deriving stock (Read, Show, Eq, Ord, Data, Generic) deriving anyclass (Hashable) diff --git a/api/src/OpenTelemetry/Internal/Logging/Core.hs b/api/src/OpenTelemetry/Internal/Logging/Core.hs index c283d065..181a3818 100644 --- a/api/src/OpenTelemetry/Internal/Logging/Core.hs +++ b/api/src/OpenTelemetry/Internal/Logging/Core.hs @@ -147,7 +147,7 @@ logDroppedAttributes = emitOTelLogRecord H.empty Warn "At least 1 attribute was -- | WARNING: this function should only be used to emit logs from the hs-opentelemetry-api library. DO NOT USE this function in any other context. emitOTelLogRecord :: (MonadIO m) => H.HashMap Text LA.AnyValue -> SeverityNumber -> Text -> m ReadWriteLogRecord -emitOTelLogRecord attrs severity body = do +emitOTelLogRecord attrs severity bodyText = do glp <- getGlobalLoggerProvider let gl = makeLogger glp $ @@ -159,8 +159,9 @@ emitOTelLogRecord attrs severity body = do } emitLogRecord gl $ - (emptyLogRecordArguments body) + emptyLogRecordArguments { severityNumber = Just severity + , body = toValue bodyText , attributes = attrs } diff --git a/api/src/OpenTelemetry/Internal/Logging/Types.hs b/api/src/OpenTelemetry/Internal/Logging/Types.hs index 54893cfd..09661e3e 100644 --- a/api/src/OpenTelemetry/Internal/Logging/Types.hs +++ b/api/src/OpenTelemetry/Internal/Logging/Types.hs @@ -218,15 +218,15 @@ data LogRecordArguments = LogRecordArguments } -emptyLogRecordArguments :: (ToValue body) => body -> LogRecordArguments -emptyLogRecordArguments body = +emptyLogRecordArguments :: LogRecordArguments +emptyLogRecordArguments = LogRecordArguments { timestamp = Nothing , observedTimestamp = Nothing , context = Nothing , severityText = Nothing , severityNumber = Nothing - , body = toValue body + , body = NullValue , attributes = H.empty } diff --git a/api/test/OpenTelemetry/Logging/CoreSpec.hs b/api/test/OpenTelemetry/Logging/CoreSpec.hs index 5bf7a919..11423447 100644 --- a/api/test/OpenTelemetry/Logging/CoreSpec.hs +++ b/api/test/OpenTelemetry/Logging/CoreSpec.hs @@ -50,7 +50,7 @@ spec = describe "Core" $ do it "works" $ do lp <- getGlobalLoggerProvider let l = makeLogger lp InstrumentationLibrary {libraryName = "exampleLibrary", libraryVersion = "", librarySchemaUrl = "", libraryAttributes = A.emptyAttributes} - lr <- emitLogRecord l $ (emptyLogRecordArguments ("" :: LA.AnyValue)) {attributes = H.fromList [("something", "a thing")]} + lr <- emitLogRecord l $ emptyLogRecordArguments {attributes = H.fromList [("something", "a thing")]} addAttribute lr "anotherThing" ("another thing" :: LA.AnyValue) @@ -64,7 +64,7 @@ spec = describe "Core" $ do it "works" $ do lp <- getGlobalLoggerProvider let l = makeLogger lp InstrumentationLibrary {libraryName = "exampleLibrary", libraryVersion = "", librarySchemaUrl = "", libraryAttributes = A.emptyAttributes} - lr <- emitLogRecord l $ (emptyLogRecordArguments ("" :: LA.AnyValue)) {attributes = H.fromList [("something", "a thing")]} + lr <- emitLogRecord l $ emptyLogRecordArguments {attributes = H.fromList [("something", "a thing")]} addAttributes lr $ H.fromList