Skip to content

Commit

Permalink
Added NullValue to AnyValue and removed body parameter from emptyLogR…
Browse files Browse the repository at this point in the history
…ecordArguments
  • Loading branch information
evanlauer1 committed Jul 22, 2024
1 parent 2b3cf49 commit b6a4c70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/src/OpenTelemetry/Internal/Common/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions api/src/OpenTelemetry/Internal/Logging/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
Expand All @@ -159,8 +159,9 @@ emitOTelLogRecord attrs severity body = do
}

emitLogRecord gl $
(emptyLogRecordArguments body)
emptyLogRecordArguments
{ severityNumber = Just severity
, body = toValue bodyText
, attributes = attrs
}

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

Expand Down
4 changes: 2 additions & 2 deletions api/test/OpenTelemetry/Logging/CoreSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit b6a4c70

Please sign in to comment.