diff --git a/api/src/OpenTelemetry/Internal/Logging/Types.hs b/api/src/OpenTelemetry/Internal/Logging/Types.hs index 6050b2dd..65f98063 100644 --- a/api/src/OpenTelemetry/Internal/Logging/Types.hs +++ b/api/src/OpenTelemetry/Internal/Logging/Types.hs @@ -21,7 +21,7 @@ import OpenTelemetry.Common (Timestamp, TraceFlags) import OpenTelemetry.Context.Types (Context) import OpenTelemetry.Internal.Common.Types (InstrumentationLibrary) import OpenTelemetry.Internal.Trace.Id (SpanId, TraceId) -import OpenTelemetry.LogAttributes (AnyValue, AttributeLimits, LogAttributes) +import OpenTelemetry.LogAttributes import OpenTelemetry.Resource (MaterializedResources) diff --git a/api/test/OpenTelemetry/Logging/CoreSpec.hs b/api/test/OpenTelemetry/Logging/CoreSpec.hs index 34393cf9..fbdff367 100644 --- a/api/test/OpenTelemetry/Logging/CoreSpec.hs +++ b/api/test/OpenTelemetry/Logging/CoreSpec.hs @@ -16,57 +16,44 @@ import Test.Hspec spec :: Spec spec = describe "Core" $ do - describe "getGlobalLoggerProvider" $ do + describe "The global logger provider" $ do it "Returns a no-op LoggerProvider when not initialized" $ do LoggerProvider {..} <- getGlobalLoggerProvider loggerProviderResource `shouldBe` emptyMaterializedResources loggerProviderAttributeLimits `shouldBe` LA.defaultAttributeLimits - describe "setGlobalLoggerProvider" $ do - it "works" $ do - lp <- - createLoggerProvider $ - LoggerProviderOptions - { loggerProviderOptionsResource = - materializeResources $ - toResource - OperatingSystem - { osType = "exampleOs" - , osDescription = Nothing - , osName = Nothing - , osVersion = Nothing + it "Allows a LoggerProvider to be set and returns that with subsequent calls to getGlobalLoggerProvider" $ do + let lp = + createLoggerProvider $ + LoggerProviderOptions + { loggerProviderOptionsResource = + materializeResources $ + toResource + OperatingSystem + { osType = "exampleOs" + , osDescription = Nothing + , osName = Nothing + , osVersion = Nothing + } + , loggerProviderOptionsAttributeLimits = + LA.AttributeLimits + { attributeCountLimit = Just 50 + , attributeLengthLimit = Just 50 } - , loggerProviderOptionsAttributeLimits = - LA.AttributeLimits - { attributeCountLimit = Just 50 - , attributeLengthLimit = Just 50 - } - } + } + setGlobalLoggerProvider lp + glp <- getGlobalLoggerProvider glp `shouldBe` lp describe "addAttribute" $ do it "works" $ do lp <- getGlobalLoggerProvider let l = makeLogger lp InstrumentationLibrary {libraryName = "exampleLibrary", libraryVersion = "", librarySchemaUrl = "", libraryAttributes = A.emptyAttributes} - lr <- - emitLogRecord - l - LogRecordArguments - { timestamp = Nothing - , observedTimestamp = Nothing - , context = Nothing - , severityText = Nothing - , severityNumber = Nothing - , body = Nothing - , attributes = - H.fromList - [ ("something", "a thing") - ] - } + lr <- emitLogRecord l $ (emptyLogRecordArguments ()) {attributes = H.fromList [("something", "a thing")]} + addAttribute lr "anotherThing" ("another thing" :: LA.AnyValue) (_, attrs) <- LA.getAttributes <$> logRecordGetAttributes lr - attrs `shouldBe` H.fromList [ ("anotherThing", "another thing") @@ -76,21 +63,8 @@ spec = describe "Core" $ do it "works" $ do lp <- getGlobalLoggerProvider let l = makeLogger lp InstrumentationLibrary {libraryName = "exampleLibrary", libraryVersion = "", librarySchemaUrl = "", libraryAttributes = A.emptyAttributes} - lr <- - emitLogRecord - l - LogRecordArguments - { timestamp = Nothing - , observedTimestamp = Nothing - , context = Nothing - , severityText = Nothing - , severityNumber = Nothing - , body = Nothing - , attributes = - H.fromList - [ ("something", "a thing") - ] - } + lr <- emitLogRecord l $ (emptyLogRecordArguments ()) {attributes = H.fromList [("something", "a thing")]} + addAttributes lr $ H.fromList [ ("anotherThing", "another thing" :: LA.AnyValue) @@ -98,7 +72,6 @@ spec = describe "Core" $ do ] (_, attrs) <- LA.getAttributes <$> logRecordGetAttributes lr - attrs `shouldBe` H.fromList [ ("anotherThing", "another thing")